From 161c29246289b426b2899199c2d832b7399af575 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Fri, 26 Dec 2014 11:03:28 +0100 Subject: [PATCH] Prevent the creation of useless tool parts (bow limb, xbow limb and arrowhead without respective stats for the material) --- .../tconstruct/tools/TinkerToolEvents.java | 2 + .../tconstruct/weaponry/WeaponryHandler.java | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/main/java/tconstruct/tools/TinkerToolEvents.java b/src/main/java/tconstruct/tools/TinkerToolEvents.java index 3e8a858096f..6f4924623a7 100644 --- a/src/main/java/tconstruct/tools/TinkerToolEvents.java +++ b/src/main/java/tconstruct/tools/TinkerToolEvents.java @@ -178,6 +178,7 @@ private boolean allowCrafting (int head, int handle, int accessory) @SubscribeEvent public void craftPart (PartBuilderEvent.NormalPart event) { + // bowstring if (event.pattern.getItem() == TinkerTools.woodPattern && event.pattern.getItemDamage() == 23) { ItemStack result = craftBowString(event.material); @@ -187,6 +188,7 @@ public void craftPart (PartBuilderEvent.NormalPart event) } } + // fletching if (event.pattern.getItem() == TinkerTools.woodPattern && event.pattern.getItemDamage() == 24) { ItemStack result = craftFletching(event.material); diff --git a/src/main/java/tconstruct/weaponry/WeaponryHandler.java b/src/main/java/tconstruct/weaponry/WeaponryHandler.java index 7238594c6a5..d727f105131 100644 --- a/src/main/java/tconstruct/weaponry/WeaponryHandler.java +++ b/src/main/java/tconstruct/weaponry/WeaponryHandler.java @@ -3,6 +3,10 @@ import cpw.mods.fml.common.eventhandler.Event; import cpw.mods.fml.common.gameevent.PlayerEvent; import tconstruct.armor.player.TPlayerStats; +import tconstruct.library.crafting.PatternBuilder; +import tconstruct.library.event.PartBuilderEvent; +import tconstruct.library.event.SmelteryCastEvent; +import tconstruct.library.util.IToolPart; import tconstruct.tools.TinkerTools; import tconstruct.weaponry.ammo.ArrowAmmo; import tconstruct.weaponry.ammo.BoltAmmo; @@ -283,4 +287,64 @@ private void setAmmoData(NBTTagCompound tags, int durability, float weight, floa tags.setFloat("Shoddy", shoddy); // we could actually always set this to 0 since it has zero impact on ammo tags.setInteger("Unbreaking", reinforced); } + + @SubscribeEvent + public void weaponryPartCrafted(PartBuilderEvent.NormalPart event) + { + if(event.pattern == null) + return; + + // weaponry part + if(event.pattern.getItem() == TinkerWeaponry.woodPattern) { + // crossbow or bow limb + if (event.pattern.getItemDamage() == 1 || event.pattern.getItemDamage() == 3) { + // only allow crafting if the material has bow stats + PatternBuilder.ItemKey key = PatternBuilder.instance.getItemKey(event.material); + if(key == null) + return; + + PatternBuilder.MaterialSet ms = PatternBuilder.instance.materialSets.get(key.key); + if(ms == null) + return; + + if(TConstructRegistry.getBowMaterial(ms.materialID) == null) + event.setResult(Event.Result.DENY); + } + } + // arrow stats, still in tool + if(event.pattern.getItem() == TinkerTools.woodPattern && event.pattern.getItemDamage() == 25) { + // only allow crafting if the material has bow stats + PatternBuilder.ItemKey key = PatternBuilder.instance.getItemKey(event.material); + if(key == null) + return; + + PatternBuilder.MaterialSet ms = PatternBuilder.instance.materialSets.get(key.key); + if(ms == null) + return; + + if(TConstructRegistry.getArrowMaterial(ms.materialID) == null) + event.setResult(Event.Result.DENY); + } + } + + @SubscribeEvent + public void weaponryPartCast(SmelteryCastEvent.CastingTable event) { + if (event.recipe == null || event.recipe.output == null) + return; + + if (!(event.recipe.output.getItem() instanceof IToolPart)) + return; + + // get material for the output + int mat = ((IToolPart) event.recipe.output.getItem()).getMaterialID(event.recipe.output); + + // arrowhead + if (event.recipe.output.getItem() == TinkerWeaponry.arrowhead) + if (TConstructRegistry.getArrowMaterial(mat) == null) + event.setResult(Event.Result.DENY); + // crossbow/bowlimb + if (event.recipe.output.getItem() == TinkerWeaponry.partBowLimb || event.recipe.output.getItem() == TinkerWeaponry.partCrossbowLimb) + if (TConstructRegistry.getBowMaterial(mat) == null) + event.setResult(Event.Result.DENY); + } }