Skip to content

Commit

Permalink
Flux modified tools now charge properly with the charge rate if CoFHC…
Browse files Browse the repository at this point in the history
…ore is present. WITHOUT breaking blockbreak process. This also fixes moss-repair resetting.
  • Loading branch information
bonii-xx committed Oct 24, 2014
1 parent 78167ba commit edf30d3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/api/java/cofh/core/item/IEqualityOverrideItem.java
@@ -0,0 +1,9 @@
package cofh.core.item;

import net.minecraft.item.ItemStack;

public interface IEqualityOverrideItem {

public boolean isLastHeldItemEqual(ItemStack current, ItemStack previous);

}
14 changes: 9 additions & 5 deletions src/main/java/tconstruct/library/tools/AbilityHelper.java
@@ -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;
Expand Down Expand Up @@ -406,23 +407,24 @@ public static boolean damageEnergyTool (ItemStack stack, NBTTagCompound tags, En
trueSpeed *= 6;
if (energy != -1)
{
ToolCore tool = (ToolCore) stack.getItem();
// first try charging from the hotbar
if (entity instanceof EntityPlayer)
int usage = (int)(trueSpeed * 3.3f);
// 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*50;
tags.setInteger("Energy", energy);

//stack.setItemDamage(1 + (tool.getMaxEnergyStored(stack) - energy) * (stack.getMaxDamage() - 1) / tool.getMaxEnergyStored(stack));
Expand Down Expand Up @@ -475,6 +477,8 @@ protected static void chargeEnergyFromHotbar (ItemStack stack, EntityPlayer play
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);
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/tconstruct/library/tools/ToolCore.java
@@ -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.*;
Expand Down Expand Up @@ -47,8 +48,11 @@
* @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;
Expand Down Expand Up @@ -923,5 +927,30 @@ public int getMaxEnergyStored (ItemStack container)
// 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
}

0 comments on commit edf30d3

Please sign in to comment.