From 97766f8ac530496a0a4e6336bd7c29b5ffcde15c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 10 Mar 2017 23:29:16 +0100 Subject: [PATCH] added a config to change the configuration items --- .../mod/blocks/BlockLaserRelay.java | 7 ++--- .../mod/blocks/base/BlockContainerBase.java | 3 ++- .../mod/config/ConfigValues.java | 27 +++++++++++++++++++ .../config/values/ConfigStringListValues.java | 1 + .../mod/event/ClientEvents.java | 6 ++--- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java index 513aafd55..3a32a8b83 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockLaserRelay.java @@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; +import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench; import de.ellpeck.actuallyadditions.mod.tile.*; @@ -141,7 +142,7 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{ if(tile instanceof TileEntityLaserRelay){ TileEntityLaserRelay relay = (TileEntityLaserRelay)tile; - if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemCompass){ + if(StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemCompassConfigurator){ if(!world.isRemote){ relay.onCompassAction(player); @@ -188,7 +189,7 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{ @SideOnly(Side.CLIENT) public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){ if(posHit != null && posHit.getBlockPos() != null && minecraft.theWorld != null && StackUtil.isValid(stack)){ - boolean compass = stack.getItem() instanceof ItemCompass; + boolean compass = stack.getItem() == ConfigValues.itemCompassConfigurator; if(compass || stack.getItem() instanceof ItemLaserWrench){ TileEntity tile = minecraft.theWorld.getTileEntity(posHit.getBlockPos()); if(tile instanceof TileEntityLaserRelay){ @@ -202,7 +203,7 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{ expl = relay.getCompassDisplayString(); } else{ - expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a Compass to modify!"; + expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a "+StringUtil.localize(ConfigValues.itemCompassConfigurator.getUnlocalizedName()+".name")+" to modify!"; } StringUtil.drawSplitString(minecraft.fontRendererObj, expl, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+15, Integer.MAX_VALUE, StringUtil.DECIMAL_COLOR_WHITE, true); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java index a8ae95d76..1e4556f5d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/base/BlockContainerBase.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.blocks.base; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; @@ -111,7 +112,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB public boolean tryToggleRedstone(World world, BlockPos pos, EntityPlayer player){ ItemStack stack = player.getHeldItemMainhand(); - if(StackUtil.isValid(stack) && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){ + if(StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemRedstoneTorchConfigurator){ TileEntity tile = world.getTileEntity(pos); if(tile instanceof TileEntityBase){ TileEntityBase base = (TileEntityBase)tile; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java index 070f7552b..a9b0df05d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/ConfigValues.java @@ -11,10 +11,18 @@ package de.ellpeck.actuallyadditions.mod.config; import de.ellpeck.actuallyadditions.mod.config.values.*; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.config.Configuration; public final class ConfigValues{ + public static Item itemRedstoneTorchConfigurator; + public static Item itemCompassConfigurator; + public static void defineConfigValues(Configuration config){ for(ConfigCrafting currConf : ConfigCrafting.values()){ @@ -37,5 +45,24 @@ public final class ConfigValues{ currConf.currentValue = config.get(currConf.category, currConf.name, currConf.defaultValue, currConf.desc).getStringList(); } + parseConfiguratorConfig(); + } + + private static void parseConfiguratorConfig(){ + itemRedstoneTorchConfigurator = null; + itemCompassConfigurator = null; + + String[] conf = ConfigStringListValues.CONFIGURE_ITEMS.getValue(); + if(conf.length == 2){ + itemRedstoneTorchConfigurator = Item.REGISTRY.getObject(new ResourceLocation(conf[0])); + itemCompassConfigurator = Item.REGISTRY.getObject(new ResourceLocation(conf[1])); + } + + if(itemRedstoneTorchConfigurator == null || itemCompassConfigurator == null){ + ModUtil.LOGGER.error("Parsing the Configuration Items config failed, reverting back to the default settings!"); + + itemRedstoneTorchConfigurator = Item.getItemFromBlock(Blocks.REDSTONE_TORCH); + itemCompassConfigurator = Items.COMPASS; + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java index 70c631340..ac4a7567f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java @@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; public enum ConfigStringListValues{ + CONFIGURE_ITEMS("Configuration Items", ConfigCategories.OTHER, new String[]{"minecraft:redstone_torch", "minecraft:compass"}, "The non-Actually Additions items that are used to configure blocks from the mod. The first one is the Redstone Torch used to configure the Redstone Mode, and the second one is the Compass used to configure Laser Relays. If another mod overrides usage of either one of these items, you can change the registry name of the used items (using blocks is not possible) here."), CRUSHER_RECIPE_EXCEPTIONS("Crusher Recipe Exceptions", ConfigCategories.OTHER, new String[]{"ingotBrick", "ingotBrickNether"}, "Ingots, Dusts and Ores that will be blacklisted from being auto-registered to be crushed by the Crusher. This list uses OreDictionary Names of the Inputs only."), CRUSHER_OUTPUT_BLACKLIST("Crusher Output Blacklist", ConfigCategories.OTHER, new String[0], "The items that aren't allowed as outputs from OreDict Crusher recipes. Use this in case a mod, for example, adds a dust variant that can't be smelted into an ingot. Use REGISTRY NAMES, and if metadata is needed, add it like so: somemod:some_item@3"), MASHED_FOOD_CRAFTING_EXCEPTIONS("Mashed Food Crafting Exceptions", ConfigCategories.ITEMS_CRAFTING, new String[]{"ActuallyAdditions:itemCoffee"}, "The ItemFood, IGrowable and IPlantable Items that can not be used to craft Mashed Food. These are the actual registered Item Names, the ones you use, for example, when using the /give Command."), diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java index 94010a7eb..caeec63ba 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.event; import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay; +import de.ellpeck.actuallyadditions.mod.config.ConfigValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.mod.inventory.gui.EnergyDisplay; @@ -20,7 +21,6 @@ import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.block.Block; -import net.minecraft.block.BlockRedstoneTorch; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; @@ -162,11 +162,11 @@ public class ClientEvents{ font.drawStringWithShadow(strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE); String expl; - if(StackUtil.isValid(stack) && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){ + if(StackUtil.isValid(stack) && stack.getItem() == ConfigValues.itemRedstoneTorchConfigurator){ expl = TextFormatting.GREEN+"Right-Click to toggle!"; } else{ - expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a Redstone Torch to toggle!"; + expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a "+StringUtil.localize(ConfigValues.itemRedstoneTorchConfigurator.getUnlocalizedName()+".name")+" to toggle!"; } font.drawStringWithShadow(expl, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE); }