Skip to content

Commit

Permalink
Implemented drawbridge blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
fuj1n committed Sep 28, 2019
1 parent bf3a7fb commit 74f8160
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 14 deletions.
13 changes: 7 additions & 6 deletions src/main/java/slimeknights/tmechworks/TMechworks.java
Expand Up @@ -5,8 +5,6 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.*;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand All @@ -15,18 +13,22 @@
import slimeknights.mantle.util.ModelJsonGenerator;
import slimeknights.tmechworks.client.ClientProxy;
import slimeknights.tmechworks.common.CommonProxy;
import slimeknights.tmechworks.common.MechworksConfig;
import slimeknights.tmechworks.common.config.BlacklistConfig;
import slimeknights.tmechworks.common.config.MechworksConfig;
import slimeknights.tmechworks.common.MechworksContent;
import slimeknights.tmechworks.common.network.PacketHandler;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;

@Mod(TMechworks.modId)
public class TMechworks {
public static final String modId = "tmechworks";
public static final String modName = "Tinkers' Mechworks";

public static final Path CONFIG_ROOT = Paths.get("config", "Tinkers Mechworks");

public static final Logger log = LogManager.getLogger(modId);

public static TMechworks instance;
Expand All @@ -49,10 +51,9 @@ public TMechworks() {
}

private void preInit(final FMLCommonSetupEvent event) {
File configPath = new File("config");
if(!configPath.exists())
configPath.mkdirs();
CONFIG_ROOT.toFile().mkdirs();
MechworksConfig.load();
BlacklistConfig.ping();

proxy.preInit();

Expand Down
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
Expand All @@ -14,6 +15,7 @@
import net.minecraftforge.fml.network.PacketDistributor;
import slimeknights.tmechworks.client.gui.components.ArrowWidget;
import slimeknights.tmechworks.common.blocks.tileentity.DrawbridgeTileEntity;
import slimeknights.tmechworks.common.config.BlacklistConfig;
import slimeknights.tmechworks.common.inventory.DrawbridgeContainer;
import slimeknights.tmechworks.common.network.PacketHandler;
import slimeknights.tmechworks.common.network.packet.ServerReopenUiPacket;
Expand Down Expand Up @@ -127,6 +129,11 @@ public List<String> getTooltipFromItem(ItemStack stack) {
list.add(TextFormatting.GRAY + I18n.format(Util.prefix("gui.blocknum"), hoveredSlot.getSlotIndex() + 1));
}

if(stack.getItem() instanceof BlockItem && BlacklistConfig.DRAWBRIDGE.isBlacklisted(((BlockItem)stack.getItem()).getBlock().getRegistryName())) {
list.add("");
list.add(I18n.format(Util.prefix("gui.blacklisted")));
}

return list;
}

Expand Down
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.client.gui.ScreenManager;
import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.*;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -31,15 +30,14 @@
import slimeknights.tmechworks.common.blocks.MetalBlock;
import slimeknights.tmechworks.common.blocks.tileentity.DrawbridgeTileEntity;
import slimeknights.tmechworks.common.blocks.tileentity.FirestarterTileEntity;
import slimeknights.tmechworks.common.config.MechworksConfig;
import slimeknights.tmechworks.common.inventory.DisguiseContainer;
import slimeknights.tmechworks.common.inventory.DrawbridgeContainer;
import slimeknights.tmechworks.common.items.MachineUpgradeItem;
import slimeknights.tmechworks.common.items.MechworksBlockItem;
import slimeknights.tmechworks.common.items.MechworksBookItem;
import slimeknights.tmechworks.common.worldgen.MechworksWorld;

import java.util.function.Supplier;

public class MechworksContent implements IRegisterUtil {
private Logger log = LogManager.getLogger(TMechworks.modId + ".content");

Expand Down
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import slimeknights.tmechworks.common.MechworksConfig;
import slimeknights.tmechworks.common.blocks.tileentity.DrawbridgeTileEntity;
import slimeknights.tmechworks.common.items.MechworksBlockItem;

Expand Down
Expand Up @@ -25,7 +25,8 @@
import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.event.ForgeEventFactory;
import slimeknights.tmechworks.common.MechworksConfig;
import slimeknights.tmechworks.common.config.BlacklistConfig;
import slimeknights.tmechworks.common.config.MechworksConfig;
import slimeknights.tmechworks.common.MechworksContent;
import slimeknights.tmechworks.common.blocks.DrawbridgeBlock;
import slimeknights.tmechworks.common.blocks.RedstoneMachineBlock;
Expand Down Expand Up @@ -67,7 +68,7 @@ public DrawbridgeTileEntity() {
super(MechworksContent.TileEntities.drawbridge, new TranslationTextComponent(Util.prefix("inventory.drawbridge")), UPGRADES_SIZE + 1);

upgrades = new FragmentedInventory(this, 0, UPGRADES_SIZE).overrideStackLimit(1).setValidItemsPredicate(stack -> stack.getItem() instanceof MachineUpgradeItem);
slots = new FragmentedInventory(this, UPGRADES_SIZE, 1).setValidItemsPredicate(stack -> stack.getItem() instanceof BlockItem).overrideStackLimit(64);
slots = new FragmentedInventory(this, UPGRADES_SIZE, 1).setValidItemsPredicate(stack -> stack.getItem() instanceof BlockItem && !BlacklistConfig.DRAWBRIDGE.isBlacklisted(((BlockItem)stack.getItem()).getBlock().getRegistryName())).overrideStackLimit(64);
}

@Override
Expand Down Expand Up @@ -199,6 +200,9 @@ public boolean placeBlock(BlockPos pos, ItemStack stack) {
return false;
if (stack.isEmpty() || !(stack.getItem() instanceof BlockItem))
return false;
if(BlacklistConfig.DRAWBRIDGE.isBlacklisted(((BlockItem)stack.getItem()).getBlock().getRegistryName()))
return false;


FakePlayer player = getFakePlayer(pos);

Expand Down
@@ -0,0 +1,55 @@
package slimeknights.tmechworks.common.config;

import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import slimeknights.tmechworks.TMechworks;

import javax.annotation.Nullable;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;

public class BlacklistConfig {
public static final Path BLACKLIST_ROOT = Paths.get(TMechworks.CONFIG_ROOT.toString(), "Blacklist");
public static final BlacklistConfig DRAWBRIDGE = new BlacklistConfig("Drawbridge");

private final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();

public final ForgeConfigSpec.ConfigValue<List<? extends String>> blacklist;

private final ForgeConfigSpec spec;

private BlacklistConfig(String of) {
this(of, Collections.emptyList());
}

private BlacklistConfig(String of, List<? extends String> defaultValues) {
blacklist = builder
.comment()
.comment("Any blocks in this list will not be allowed in the " + of + "\nA list of fully qualified block registry names, for example, \"minecraft:iron_block\"")
.defineList("blacklist", defaultValues, obj -> ResourceLocation.isResouceNameValid(obj.toString()));

spec = builder.build();

BLACKLIST_ROOT.toFile().mkdirs();

CommentedFileConfig config = CommentedFileConfig.builder(Paths.get(BLACKLIST_ROOT.toString(), of + ".toml")).build();
config.load();
spec.setConfig(config);
}

public boolean isBlacklisted(@Nullable ResourceLocation resource) {
if(resource == null)
return false;

List<? extends String> list = blacklist.get();

return list.stream().anyMatch(resource.toString()::equals);
}

public static void ping() {
}
}
Expand Up @@ -9,7 +9,7 @@
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import slimeknights.tmechworks.common.MechworksConfig;
import slimeknights.tmechworks.common.config.MechworksConfig;
import slimeknights.tmechworks.common.MechworksContent;

import java.util.List;
Expand Down
7 changes: 6 additions & 1 deletion src/resources/assets/tmechworks/lang/en_us.json
Expand Up @@ -63,5 +63,10 @@

// GUI
"tmechworks:gui.upgrades": "Upgrades",
"tmechworks:gui.blocknum": "Block #%d"
"tmechworks:gui.blocknum": "Block #%d",
"tmechworks:gui.blacklisted": "§4BLACKLISTED",

// Integrations
"config.waila.plugin_tmechworks": "Tinkers' Mechworks",
"config.waila.plugin_tmechworks.redstone_machine": "Redstone Machines"
}

0 comments on commit 74f8160

Please sign in to comment.