Skip to content

Commit

Permalink
Prevent the creation of useless tool parts (bow limb, xbow limb and a…
Browse files Browse the repository at this point in the history
…rrowhead without respective stats for the material)
  • Loading branch information
bonii-xx committed Dec 26, 2014
1 parent f3ba95b commit 161c292
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/tconstruct/tools/TinkerToolEvents.java
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/tconstruct/weaponry/WeaponryHandler.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 161c292

Please sign in to comment.