We can now restock ammo stuff. yay.

This commit is contained in:
Bernhard Bonigl committed 2014-10-26 20:38:28 +01:00
1 parent ecf5d0e990
commit 98d3cc8dc1
3 files changed
+116 -1

No files matched your search

@@ -0,0 +1,113 @@
package tconstruct.modifiers.tools;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.modifier.ItemModifier;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.ToolCore;
import tconstruct.library.weaponry.AmmoItem;
import tconstruct.library.weaponry.IAmmo;
public class ModAmmoRestock extends ItemModifier {
public ModAmmoRestock()
{
super(new ItemStack[0], 0, "");
}
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
return canModify(tool, input);
}
@Override
protected boolean canModify (ItemStack tool, ItemStack[] input)
{
if(!(tool.getItem() instanceof AmmoItem))
return false;
IAmmo ammo = (IAmmo)tool.getItem();
// full?
if(ammo.getAmmoCount(tool) >= ammo.getMaxAmmo(tool))
return false;
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
// correct material?
int headID = tags.getInteger("Head");
boolean areInputsValid = true;
for (ItemStack curInput : input)
{
if (curInput != null && headID != PatternBuilder.instance.getPartID(curInput))
{
areInputsValid = false;
break;
}
}
return areInputsValid;
}
private int calculateIncrease (ItemStack tool, int materialValue, int itemsUsed)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
float dur = tags.getInteger("BaseDurability") * ((AmmoItem)tool.getItem()).getAmmoModifier();
float increase = (5 * itemsUsed + (dur * 0.4f * materialValue/2f));
int modifiers = tags.getInteger("Modifiers");
float mods = 1.0f;
if (modifiers == 2)
mods = 0.9f;
else if (modifiers == 1)
mods = 0.8f;
else if (modifiers == 0)
mods = 0.7f;
increase *= mods;
int repair = tags.getInteger("RepairCount");
float repairCount = (100 - repair) / 100f;
if (repairCount < 0.5f)
repairCount = 0.5f;
increase *= repairCount;
increase /= ((ToolCore) tool.getItem()).getRepairCost();
return (int)increase;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
int itemsUsed = 0;
int materialValue = 0;
for (ItemStack curInput : input)
{
if (curInput != null)
{
materialValue += PatternBuilder.instance.getPartValue(curInput);
itemsUsed++;
}
}
int increase = calculateIncrease(tool, materialValue, itemsUsed);
int repair = tags.getInteger("RepairCount");
repair += itemsUsed;
tags.setInteger("RepairCount", repair);
((IAmmo)tool.getItem()).addAmmo(increase, tool);
}
@Override
public void addMatchingEffect (ItemStack tool)
{
}
public boolean validType (IModifyable input)
{
return input.getModifyType().equals("Tool") || input.getModifyType().equals("Armor");
}
}
@@ -17,7 +17,6 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.TConstruct;
import tconstruct.library.TConstructCreativeTab;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.*;
import tconstruct.library.tools.DynamicToolPart;
@@ -25,6 +24,7 @@ import tconstruct.library.tools.FletchlingLeafMaterial;
import tconstruct.library.util.IPattern;
import tconstruct.library.util.IToolPart;
import tconstruct.modifiers.tools.ModWindup;
import tconstruct.modifiers.tools.ModAmmoRestock;
import tconstruct.smeltery.TinkerSmeltery;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.items.Bowstring;
@@ -104,6 +104,7 @@ public class TinkerWeaponry {
ItemStack redstoneItem = new ItemStack(Items.redstone);
ItemStack redstoneBlock = new ItemStack(Blocks.redstone_block);
ModifyBuilder.registerModifier(new ModWindup(2, new ItemStack[] { redstoneItem, redstoneBlock }, new int[] { 1, 9 }));
ModifyBuilder.registerModifier(new ModAmmoRestock());
}
@Handler
+1
View File
@@ -11,6 +11,7 @@ TODO:
* Glassmakers Arrows :D DONE
* Check why arrow repairing doesn't work
* REGROWING PROJECTILES HAR
* Javelins need lower durability. When leftclick attacking and it has no durability, it should use up 1 ammo and get durability.
maybe give javelins slight armor piercing? or do they have that already?