From 499fa1a00f2e5d664f9ca107ea5030d5022fe0bd Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Wed, 30 Jul 2014 22:48:43 +0200 Subject: [PATCH] Started Tweaks module: Remove Flint Drop and add Flint recipe --- .../IguanaTweaksTConstruct.java | 2 + .../reference/Reference.java | 3 ++ .../tweaks/IguanaTweaks.java | 47 +++++++++++++++++++ .../tweaks/handler/FlintHandler.java | 37 +++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java create mode 100644 src/main/java/iguanaman/iguanatweakstconstruct/tweaks/handler/FlintHandler.java diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java b/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java index bcafdf2..88e50a3 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/IguanaTweaksTConstruct.java @@ -18,6 +18,7 @@ import iguanaman.iguanatweakstconstruct.proxy.CommonProxy; import iguanaman.iguanatweakstconstruct.reference.Config; import iguanaman.iguanatweakstconstruct.reference.Reference; import iguanaman.iguanatweakstconstruct.replacing.IguanaToolPartReplacing; +import iguanaman.iguanatweakstconstruct.tweaks.IguanaTweaks; import iguanaman.iguanatweakstconstruct.util.HarvestLevels; import iguanaman.iguanatweakstconstruct.util.Log; import mantle.pulsar.config.ForgeCFG; @@ -87,6 +88,7 @@ public class IguanaTweaksTConstruct { pulsar.registerPulse(new IguanaHarvestLevelTweaks()); pulsar.registerPulse(new IguanaToolLeveling()); pulsar.registerPulse(new IguanaToolPartReplacing()); + pulsar.registerPulse(new IguanaTweaks()); pulsar.preInit(event); } diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/reference/Reference.java b/src/main/java/iguanaman/iguanatweakstconstruct/reference/Reference.java index a10e85d..fffb51f 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/reference/Reference.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/reference/Reference.java @@ -14,6 +14,9 @@ public class Reference { public static final String PULSE_LEVELING = "ToolLeveling"; public static final String PULSE_HARVESTTWEAKS = "HarvestLevelTweaks"; public static final String PULSE_REPLACING = "ToolPartReplacing"; + public static final String PULSE_MOBHEADS = "MobHeads"; + public static final String PULSE_TWEAKS = "IguanaTweaks"; + public static final String PULSE_ITEMS = "IguanaItems"; public static final String PROXY_CLIENT_CLASS = "iguanaman.iguanatweakstconstruct.proxy.ClientProxy"; public static final String PROXY_SERVER_CLASS = "iguanaman.iguanatweakstconstruct.proxy.ServerProxy"; diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java new file mode 100644 index 0000000..0890d38 --- /dev/null +++ b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java @@ -0,0 +1,47 @@ +package iguanaman.iguanatweakstconstruct.tweaks; + +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.registry.GameRegistry; +import iguanaman.iguanatweakstconstruct.reference.Config; +import iguanaman.iguanatweakstconstruct.reference.Reference; +import iguanaman.iguanatweakstconstruct.tweaks.handler.FlintHandler; +import iguanaman.iguanatweakstconstruct.util.Log; +import mantle.pulsar.pulse.Handler; +import mantle.pulsar.pulse.Pulse; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; + +/** + * Various Tweaks for Tinkers Construct and Vanilla Minecraft. See Config. + */ + +@Pulse(id = Reference.PULSE_TWEAKS, description = "Various Tweaks for vanilla Minecraft and Tinker's Construct. See Config.") +public class IguanaTweaks { + + @Handler + public void postInit(FMLPostInitializationEvent event) + { + FlintTweaks(); + } + + private void FlintTweaks() + { + if(Config.removeFlintDrop) { + Log.info("Removing Flint drops from Gravel"); + MinecraftForge.EVENT_BUS.register(new FlintHandler()); + } + + if(Config.addFlintRecipe) { + Log.info("Adding shapeless Flint recipe from " + Config.recipeGravelPerFlint + " Gravel"); + // create recipe + ItemStack[] recipe = new ItemStack[Config.recipeGravelPerFlint]; + for(int i = 0; i < Config.recipeGravelPerFlint; i++) + recipe[i] = new ItemStack(Blocks.gravel); + + // add recipe + GameRegistry.addShapelessRecipe(new ItemStack(Items.flint), recipe); + } + } +} diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/handler/FlintHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/handler/FlintHandler.java new file mode 100644 index 0000000..169e6cc --- /dev/null +++ b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/handler/FlintHandler.java @@ -0,0 +1,37 @@ +package iguanaman.iguanatweakstconstruct.tweaks.handler; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import iguanaman.iguanatweakstconstruct.reference.Config; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.event.world.BlockEvent; + +import java.util.ListIterator; + +public class FlintHandler { + + @SubscribeEvent + public void onBlockHarvested(BlockEvent.HarvestDropsEvent event) + { + // remove flint drop + if(event.block != null && event.block == Blocks.gravel) + { + ListIterator iter = event.drops.listIterator(); + boolean hasGravel = false; + while(iter.hasNext()) + { + Item item = iter.next().getItem(); + if(item == Items.flint) + iter.remove(); + else if(item == Item.getItemFromBlock(Blocks.gravel)) + hasGravel = true; + } + + // ensure that gravel drops + if(!hasGravel) + event.drops.add(new ItemStack(Blocks.gravel)); + } + } +}