mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-21 20:52:26 +00:00
Merge pull request #832 from bonii-xx/master
Proper Flux Modifiers + Blockbreak-Bug fix
This commit is contained in:
commit
0c7ab67633
3 files changed
+198
-114
No files matched your search
@@ -4,6 +4,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -344,7 +345,7 @@ public class AbilityHelper
|
||||
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode || tags == null)
|
||||
return;
|
||||
|
||||
if (ignoreCharge || !damageElectricTool(stack, tags, entity))
|
||||
if (ignoreCharge || !damageEnergyTool(stack, tags, entity))
|
||||
{
|
||||
boolean damagedTool = false;
|
||||
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
|
||||
@@ -385,64 +386,109 @@ public class AbilityHelper
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean damageElectricTool (ItemStack stack, NBTTagCompound tags, Entity entity)
|
||||
public static boolean damageEnergyTool(ItemStack stack, NBTTagCompound tags, Entity entity)
|
||||
{
|
||||
if (tags.hasKey("Energy"))
|
||||
{
|
||||
|
||||
NBTTagCompound toolTag = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int energy = -1;
|
||||
if (tags.hasKey("Energy"))
|
||||
{
|
||||
energy = tags.getInteger("Energy");
|
||||
}
|
||||
int durability = toolTag.getInteger("Damage");
|
||||
float shoddy = toolTag.getFloat("Shoddy");
|
||||
|
||||
float mineSpeed = toolTag.getInteger("MiningSpeed");
|
||||
int heads = 1;
|
||||
if (toolTag.hasKey("MiningSpeed2"))
|
||||
{
|
||||
mineSpeed += toolTag.getInteger("MiningSpeed2");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (toolTag.hasKey("MiningSpeedHandle"))
|
||||
{
|
||||
mineSpeed += toolTag.getInteger("MiningSpeedHandle");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (toolTag.hasKey("MiningSpeedExtra"))
|
||||
{
|
||||
mineSpeed += toolTag.getInteger("MiningSpeedExtra");
|
||||
heads++;
|
||||
}
|
||||
float trueSpeed = mineSpeed / (heads * 100f);
|
||||
float stonebound = toolTag.getFloat("Shoddy");
|
||||
float bonusLog = (float) Math.log(durability / 72f + 1) * 2 * stonebound;
|
||||
trueSpeed += bonusLog;
|
||||
trueSpeed *= 6;
|
||||
if (energy != -1)
|
||||
{
|
||||
if (energy < trueSpeed * 2)
|
||||
{
|
||||
if (energy > 0)
|
||||
tags.setInteger("Energy", 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
energy -= trueSpeed * 2;
|
||||
ToolCore tool = (ToolCore) stack.getItem();
|
||||
stack.setItemDamage(1 + (tool.getMaxEnergyStored(stack) - energy) * (stack.getMaxDamage() - 1) / tool.getMaxEnergyStored(stack));
|
||||
tags.setInteger("Energy", energy);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!tags.hasKey("Energy"))
|
||||
return false;
|
||||
|
||||
NBTTagCompound toolTag = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int energy = tags.getInteger("Energy");
|
||||
int durability = toolTag.getInteger("Damage");
|
||||
float shoddy = toolTag.getFloat("Shoddy");
|
||||
|
||||
float mineSpeed = toolTag.getInteger("MiningSpeed");
|
||||
int heads = 1;
|
||||
if (toolTag.hasKey("MiningSpeed2"))
|
||||
{
|
||||
mineSpeed += toolTag.getInteger("MiningSpeed2");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (toolTag.hasKey("MiningSpeedHandle"))
|
||||
{
|
||||
mineSpeed += toolTag.getInteger("MiningSpeedHandle");
|
||||
heads++;
|
||||
}
|
||||
|
||||
if (toolTag.hasKey("MiningSpeedExtra"))
|
||||
{
|
||||
mineSpeed += toolTag.getInteger("MiningSpeedExtra");
|
||||
heads++;
|
||||
}
|
||||
float trueSpeed = mineSpeed / (heads * 100f);
|
||||
float stonebound = toolTag.getFloat("Shoddy");
|
||||
float bonusLog = (float) Math.log(durability / 72f + 1) * 2 * stonebound;
|
||||
trueSpeed += bonusLog;
|
||||
trueSpeed *= 6;
|
||||
if (energy != -1)
|
||||
{
|
||||
ToolCore tool = (ToolCore) stack.getItem();
|
||||
// first try charging from the hotbar
|
||||
if(entity instanceof EntityPlayer) {
|
||||
// workaround for charging flux-capacitors making tools unusable
|
||||
chargeEnergyFromHotbar(stack, (EntityPlayer) entity, tags);
|
||||
energy = tool.getEnergyStored(stack);
|
||||
}
|
||||
|
||||
if (energy < trueSpeed * 2)
|
||||
{
|
||||
if (energy > 0)
|
||||
tags.setInteger("Energy", 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
energy -= trueSpeed * 2;
|
||||
tags.setInteger("Energy", energy);
|
||||
|
||||
|
||||
stack.setItemDamage(1 + (tool.getMaxEnergyStored(stack) - energy) * (stack.getMaxDamage() - 1) / tool.getMaxEnergyStored(stack));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static void chargeEnergyFromHotbar (ItemStack stack, EntityPlayer player, NBTTagCompound tags)
|
||||
{
|
||||
// cool kids only
|
||||
if(!(stack.getItem() instanceof ToolCore))
|
||||
return;
|
||||
|
||||
ToolCore tool = (ToolCore)stack.getItem();
|
||||
|
||||
// check if the tool can actually receive energy
|
||||
if(tool.receiveEnergy(stack, 1, true) != 1)
|
||||
// no you're not going to charge that potato battery on your tool
|
||||
return;
|
||||
|
||||
int buffer = tool.getEnergyStored(stack);
|
||||
int max = tool.getMaxEnergyStored(stack);
|
||||
int missing = max - buffer;
|
||||
|
||||
// you're full. xbox go home.
|
||||
if(missing <= 0)
|
||||
return;
|
||||
|
||||
// iterate through hotbar
|
||||
for (int iter = 0; iter < 9; ++iter)
|
||||
{
|
||||
ItemStack slot = player.inventory.mainInventory[iter];
|
||||
|
||||
// check if item is not another tool
|
||||
if(slot == null || slot.getItem() instanceof ToolCore)
|
||||
continue;
|
||||
// check if item gives energy
|
||||
if(!(slot.getItem() instanceof IEnergyContainerItem))
|
||||
continue;
|
||||
|
||||
IEnergyContainerItem fluxItem = (IEnergyContainerItem) slot.getItem();
|
||||
|
||||
// mDiyo EATS your power
|
||||
while (fluxItem.extractEnergy(slot, missing, true) > 0)
|
||||
{
|
||||
missing -= fluxItem.extractEnergy(slot, missing, false);
|
||||
}
|
||||
}
|
||||
// update energy
|
||||
tags.setInteger("Energy", max-missing);
|
||||
}
|
||||
|
||||
public static void breakTool (ItemStack stack, NBTTagCompound tags, Entity entity)
|
||||
|
||||
@@ -56,7 +56,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public abstract class ToolCore extends Item implements IEnergyContainerItem, IModifyable
|
||||
{
|
||||
// TE power constants -- TODO grab these from the items added
|
||||
// TE power constants. These are only for backup if the lookup of the real value somehow fails!
|
||||
protected int capacity = 400000;
|
||||
protected int maxReceive = 400000;
|
||||
protected int maxExtract = 80;
|
||||
@@ -781,21 +781,6 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo
|
||||
}
|
||||
|
||||
// TE support section -- from COFH core API reference section
|
||||
public void setMaxTransfer (int maxTransfer)
|
||||
{
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive (int maxReceive)
|
||||
{
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract (int maxExtract)
|
||||
{
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
/* IEnergyContainerItem */
|
||||
@Override
|
||||
@@ -805,13 +790,16 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo
|
||||
if (tags == null || !tags.hasKey("Energy"))
|
||||
return 0;
|
||||
int energy = tags.getInteger("Energy");
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
int energyReceived = tags.hasKey("EnergyReceiveRate") ? tags.getInteger("EnergyReceiveRate") : this.maxReceive; // backup value
|
||||
int maxEnergy = tags.hasKey("EnergyMax") ? tags.getInteger("EnergyMax") : this.capacity; // backup value
|
||||
|
||||
// calculate how much we can receive
|
||||
energyReceived = Math.min(maxEnergy - energy, Math.min(energyReceived, maxReceive));
|
||||
if (!simulate)
|
||||
{
|
||||
energy += energyReceived;
|
||||
tags.setInteger("Energy", energy);
|
||||
container.setItemDamage(1 + (getMaxEnergyStored(container) - energy) * (container.getMaxDamage() - 2) / getMaxEnergyStored(container));
|
||||
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
@@ -825,13 +813,15 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo
|
||||
return 0;
|
||||
}
|
||||
int energy = tags.getInteger("Energy");
|
||||
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
int energyExtracted = tags.hasKey("EnergyExtractionRate") ? tags.getInteger("EnergyExtractionRate") : this.maxExtract; // backup value
|
||||
|
||||
// calculate how much we can extract
|
||||
energyExtracted = Math.min(energy, Math.min(energyExtracted, maxExtract));
|
||||
if (!simulate)
|
||||
{
|
||||
energy -= energyExtracted;
|
||||
tags.setInteger("Energy", energy);
|
||||
container.setItemDamage(1 + (getMaxEnergyStored(container) - energy) * (container.getMaxDamage() - 1) / getMaxEnergyStored(container));
|
||||
|
||||
}
|
||||
return energyExtracted;
|
||||
}
|
||||
@@ -853,6 +843,10 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IMo
|
||||
NBTTagCompound tags = container.getTagCompound();
|
||||
if (tags == null || !tags.hasKey("Energy"))
|
||||
return 0;
|
||||
|
||||
if(tags.hasKey("EnergyMax"))
|
||||
return tags.getInteger("EnergyMax");
|
||||
// backup
|
||||
return capacity;
|
||||
}
|
||||
// end of TE support section
|
||||
|
||||
@@ -13,8 +13,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ModFlux extends ModBoolean
|
||||
{
|
||||
|
||||
public ArrayList<ItemStack> batteries = new ArrayList<ItemStack>();
|
||||
public int modifiersRequired = 1; // LALALALA totally not hidden IguanaTweaks Support LALALALA
|
||||
|
||||
public ModFlux()
|
||||
{
|
||||
@@ -24,34 +24,46 @@ public class ModFlux extends ModBoolean
|
||||
@Override
|
||||
public boolean matches (ItemStack[] input, ItemStack tool)
|
||||
{
|
||||
boolean battery = false;
|
||||
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
|
||||
|
||||
if (input[0] != null)
|
||||
{
|
||||
for (ItemStack stack : batteries)
|
||||
ItemStack foundBattery = null;
|
||||
// try to find the battery in the input
|
||||
for(ItemStack stack : input)
|
||||
for(ItemStack battery : batteries)
|
||||
{
|
||||
if (stack.getItem() == input[0].getItem() && input[0].getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
battery = true;
|
||||
}
|
||||
}
|
||||
return battery && canModify(tool, input);
|
||||
}
|
||||
if(stack == null)
|
||||
continue;
|
||||
if(stack.getItem() != battery.getItem())
|
||||
continue;
|
||||
if(!(stack.getItem() instanceof IEnergyContainerItem))
|
||||
continue;
|
||||
// we don't allow multiple batteries to be added
|
||||
if(foundBattery != null)
|
||||
return false;
|
||||
|
||||
if (input[1] != null)
|
||||
// battery found, gogogo
|
||||
foundBattery = stack;
|
||||
}
|
||||
|
||||
// no battery present
|
||||
if(foundBattery == null)
|
||||
return false;
|
||||
|
||||
// check if we already have a flux modifier
|
||||
if(tags.getBoolean(key))
|
||||
{
|
||||
|
||||
for (ItemStack stack : batteries)
|
||||
{
|
||||
if (stack.getItem() == input[1].getItem() && input[1].getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
battery = true;
|
||||
}
|
||||
return battery && canModify(tool, input);
|
||||
}
|
||||
// only allow if it's an upgrade
|
||||
// remark: we use the ToolCores function here instead of accessing the tag directly, to achieve backwards compatibility with tools without tags.
|
||||
int a = ((IEnergyContainerItem)foundBattery.getItem()).getMaxEnergyStored(foundBattery);
|
||||
int b = ((ToolCore)tool.getItem()).getMaxEnergyStored(tool);
|
||||
return ((IEnergyContainerItem)foundBattery.getItem()).getMaxEnergyStored(foundBattery) > ((ToolCore)tool.getItem()).getMaxEnergyStored(tool);
|
||||
}
|
||||
// otherwise check if we have enough modfiers
|
||||
else if(tags.getInteger("Modifiers") < modifiersRequired)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
// all requirements satisfied!
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,24 +71,56 @@ public class ModFlux extends ModBoolean
|
||||
{
|
||||
NBTTagCompound tags = tool.getTagCompound();
|
||||
|
||||
if (!tags.hasKey(key))
|
||||
{
|
||||
tags.setBoolean(key, true);
|
||||
|
||||
// update modifiers (only applies if it's not an upgrade)
|
||||
if(!tags.hasKey(key)) {
|
||||
int modifiers = tags.getCompoundTag("InfiTool").getInteger("Modifiers");
|
||||
modifiers -= 1;
|
||||
modifiers -= modifiersRequired;
|
||||
tags.getCompoundTag("InfiTool").setInteger("Modifiers", modifiers);
|
||||
int charge = 0;
|
||||
if (input[0] != null && input[0].getItem() != null && input[0].getItem() instanceof IEnergyContainerItem && input[0].hasTagCompound())
|
||||
charge = input[0].getTagCompound().getInteger("Energy");
|
||||
if (input[1] != null && input[1].getItem() != null && input[1].getItem() instanceof IEnergyContainerItem && input[1].hasTagCompound())
|
||||
charge = input[1].getTagCompound().getInteger("Energy");
|
||||
tags.setInteger("Energy", charge);
|
||||
tags.setInteger(key, 1);
|
||||
addModifierTip(tool, "\u00a7eFlux");
|
||||
ToolCore toolcore = (ToolCore) tool.getItem();
|
||||
tool.setItemDamage(1 + (toolcore.getMaxEnergyStored(tool) - charge) * (tool.getMaxDamage() - 1) / toolcore.getMaxEnergyStored(tool));
|
||||
}
|
||||
}
|
||||
|
||||
tags.getCompoundTag("InfiTool").setBoolean(key, true);
|
||||
|
||||
|
||||
// find the battery in the input
|
||||
ItemStack inputBattery = null;
|
||||
for(ItemStack stack : input)
|
||||
for(ItemStack battery : batteries)
|
||||
{
|
||||
if(stack == null)
|
||||
continue;
|
||||
if(stack.getItem() != battery.getItem())
|
||||
continue;
|
||||
if(!(stack.getItem() instanceof IEnergyContainerItem))
|
||||
continue;
|
||||
|
||||
// we're guaranteed to only find one battery because more are prevented above
|
||||
inputBattery = stack;
|
||||
}
|
||||
|
||||
// get the energy interface
|
||||
IEnergyContainerItem energyContainer = (IEnergyContainerItem)inputBattery.getItem();
|
||||
|
||||
// set the charge values
|
||||
int charge = energyContainer.getEnergyStored(inputBattery);
|
||||
// add already present charge in the tool
|
||||
if(tags.hasKey("Energy"))
|
||||
charge += tags.getInteger("Energy");
|
||||
int maxCharge = energyContainer.getMaxEnergyStored(inputBattery);
|
||||
// simulate transferring maximum amount of POWER to obtain the maximum receive-limit of the battery ;_;
|
||||
int maxExtract = energyContainer.extractEnergy(inputBattery, Integer.MAX_VALUE, true);
|
||||
int maxReceive = energyContainer.receiveEnergy(inputBattery, Integer.MAX_VALUE, true);
|
||||
|
||||
// make sure we don't overcharge
|
||||
charge = Math.min(charge, maxCharge);
|
||||
|
||||
tags.setInteger("Energy", charge);
|
||||
tags.setInteger("EnergyMax", maxCharge);
|
||||
tags.setInteger("EnergyExtractionRate", maxExtract);
|
||||
tags.setInteger("EnergyReceiveRate", maxReceive);
|
||||
|
||||
tags.setInteger(key, 1);
|
||||
ToolCore toolcore = (ToolCore) tool.getItem();
|
||||
tool.setItemDamage(1 + (toolcore.getMaxEnergyStored(tool) - charge) * (tool.getMaxDamage() - 1) / toolcore.getMaxEnergyStored(tool));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user