Merge branch 'master' into weaponry

Conflicts:
	src/main/java/tconstruct/tools/TinkerTools.java
This commit is contained in:
Bernhard Bonigl committed 2014-10-24 13:17:48 +02:00
commit 939bd8a0ae
11 files changed
+176 -93

No files matched your search

@@ -9,7 +9,7 @@ public class StencilBuilder
public static StencilBuilder instance = new StencilBuilder();
public List<ItemStack> blanks = new LinkedList<ItemStack>(); // i wish ItemStack would support equals so i could use a Set here...
public List<ItemStack> stencils = new ArrayList<ItemStack>();
public Map<Integer, ItemStack> stencils = new TreeMap<Integer, ItemStack>();
/**
* Returns whether the given ItemStack is a blank pattern and therefore usable for stencil crafting.
@@ -28,29 +28,32 @@ public class StencilBuilder
instance.blanks.add(itemStack);
}
public static void registerStencil (Item item, int meta)
public static void registerStencil (int id, Item item, int meta)
{
instance.stencils.add(new ItemStack(item, 1, meta));
registerStencil(id, new ItemStack(item, 1, meta));
}
public static void registerStencil (ItemStack pattern)
public static void registerStencil (int id, ItemStack pattern)
{
instance.stencils.add(pattern);
if(instance.stencils.containsKey(id))
throw new IllegalArgumentException("[TCon API] Stencil ID " + id + " is already occupied by " + instance.stencils.get(id).getDisplayName());
instance.stencils.put(id, pattern);
}
public static List<ItemStack> getStencils ()
public static Collection<ItemStack> getStencils ()
{
return instance.stencils;
return instance.stencils.values();
}
/**
* Returns the index of the given stencil. If no stencil is found, returns -1.
*/
public static int getIndex (ItemStack stencil)
public static int getId(ItemStack stencil)
{
for (int i = 0; i < instance.stencils.size(); i++)
if (OreDictionary.itemMatches(stencil, getStencil(i), false))
return i;
for(Map.Entry<Integer, ItemStack> entry : instance.stencils.entrySet())
if (OreDictionary.itemMatches(stencil, entry.getValue(), false))
return entry.getKey();
return -1;
}
@@ -58,7 +61,7 @@ public class StencilBuilder
// returns the stencil with the given index
public static ItemStack getStencil (int num)
{
if (num >= instance.stencils.size())
if (!instance.stencils.containsKey(num))
return null;
return instance.stencils.get(num).copy();
@@ -1,6 +1,7 @@
package tconstruct.library.tools;
import cofh.api.energy.IEnergyContainerItem;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.Event.Result;
import java.util.*;
import net.minecraft.block.Block;
@@ -406,23 +407,24 @@ public class AbilityHelper
trueSpeed *= 6;
if (energy != -1)
{
ToolCore tool = (ToolCore) stack.getItem();
// first try charging from the hotbar
if (entity instanceof EntityPlayer)
int usage = (int)(trueSpeed * 2.8f);
// first try charging from the hotbar if we don't have CoFHs override
if (!equalityOverrideLoaded && entity instanceof EntityPlayer)
{
ToolCore tool = (ToolCore) stack.getItem();
// workaround for charging flux-capacitors making tools unusable
chargeEnergyFromHotbar(stack, (EntityPlayer) entity, tags);
energy = tool.getEnergyStored(stack);
}
if (energy < trueSpeed * 2)
if (energy < usage)
{
if (energy > 0)
tags.setInteger("Energy", 0);
return false;
}
energy -= trueSpeed * 2;
energy -= usage;
tags.setInteger("Energy", energy);
//stack.setItemDamage(1 + (tool.getMaxEnergyStored(stack) - energy) * (stack.getMaxDamage() - 1) / tool.getMaxEnergyStored(stack));
@@ -475,6 +477,8 @@ public class AbilityHelper
tags.setInteger("Energy", max - missing);
}
private static boolean equalityOverrideLoaded = Loader.isModLoaded("CoFHCore"); // Mods should be loaded far enough before this is ever initialized
public static void breakTool (ItemStack stack, NBTTagCompound tags, Entity entity)
{
tags.getCompoundTag("InfiTool").setBoolean("Broken", true);
@@ -1,6 +1,7 @@
package tconstruct.library.tools;
import cofh.api.energy.IEnergyContainerItem;
import cofh.core.item.IEqualityOverrideItem;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.*;
import java.util.*;
@@ -47,8 +48,11 @@ import tconstruct.util.config.PHConstruct;
* @see ItemModifier
*/
@Optional.Interface(modid = "CoFHLib", iface = "cofh.api.energy.IEnergyContainerItem")
public abstract class ToolCore extends Item implements IEnergyContainerItem, IModifyable
@Optional.InterfaceList({
@Optional.Interface(modid = "CoFHLib", iface = "cofh.api.energy.IEnergyContainerItem"),
@Optional.Interface(modid = "CoFHCore", iface = "cofh.core.item.IEqualityOverrideItem")
})
public abstract class ToolCore extends Item implements IEnergyContainerItem, IEqualityOverrideItem, IModifyable
{
protected Random random = new Random();
protected int damageVsEntity;
@@ -891,5 +895,30 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo
// backup
return capacity;
}
@Override
@Optional.Method(modid = "CoFHCore")
public boolean isLastHeldItemEqual(ItemStack current, ItemStack previous) {
if(!current.hasTagCompound() || !previous.hasTagCompound())
return false;
NBTTagCompound curTags = current.getTagCompound();
NBTTagCompound prevTags = previous.getTagCompound();
if(curTags == prevTags)
return true;
if(!curTags.hasKey("InfiTool") || !prevTags.hasKey("InfiTool"))
return false;
// create copies so we don't modify the original
curTags = (NBTTagCompound) curTags.copy();
prevTags = (NBTTagCompound) prevTags.copy();
curTags.removeTag("Energy");
prevTags.removeTag("Energy");
curTags.getCompoundTag("InfiTool").removeTag("Damage");
prevTags.getCompoundTag("InfiTool").removeTag("Damage");
return curTags.equals(prevTags);
}
// end of TE support section
}