mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 19:59:55 +00:00
Flux modifier now uses the properties of the battery that was added. (Max-Energy and transfer rates)
This commit is contained in:
1 parent
cf0d0cc0dd
commit
820b13e106
2 files changed
+69
-33
No files matched your search
@@ -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;
|
||||
@@ -805,7 +805,11 @@ 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 = 0;
|
||||
if(tags.hasKey("EnergyReceiveRate"))
|
||||
energyReceived = tags.getInteger("EnergyReceiveRate");
|
||||
else
|
||||
energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
if (!simulate)
|
||||
{
|
||||
energy += energyReceived;
|
||||
@@ -825,7 +829,11 @@ 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 = 0;
|
||||
if(tags.hasKey("EnergyExtractionRate"))
|
||||
energyExtracted = tags.getInteger("EnergyExtractionRate");
|
||||
else
|
||||
energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); // backup value
|
||||
if (!simulate)
|
||||
{
|
||||
energy -= energyExtracted;
|
||||
@@ -853,6 +861,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
|
||||
|
||||
@@ -24,34 +24,31 @@ public class ModFlux extends ModBoolean
|
||||
@Override
|
||||
public boolean matches (ItemStack[] input, ItemStack tool)
|
||||
{
|
||||
boolean battery = false;
|
||||
// check if the regular limitations apply
|
||||
if(!canModify(tool, input))
|
||||
return false;
|
||||
|
||||
if (input[0] != null)
|
||||
{
|
||||
for (ItemStack stack : batteries)
|
||||
boolean foundBattery = false;
|
||||
// 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;
|
||||
}
|
||||
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)
|
||||
return false;
|
||||
|
||||
// battery found, gogogo
|
||||
foundBattery = true;
|
||||
}
|
||||
return battery && canModify(tool, input);
|
||||
}
|
||||
|
||||
if (input[1] != null)
|
||||
{
|
||||
|
||||
for (ItemStack stack : batteries)
|
||||
{
|
||||
if (stack.getItem() == input[1].getItem() && input[1].getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
battery = true;
|
||||
}
|
||||
return battery && canModify(tool, input);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// no battery found :(
|
||||
return foundBattery;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,17 +63,44 @@ public class ModFlux extends ModBoolean
|
||||
int modifiers = tags.getCompoundTag("InfiTool").getInteger("Modifiers");
|
||||
modifiers -= 1;
|
||||
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");
|
||||
|
||||
|
||||
// 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);
|
||||
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);
|
||||
tags.setInteger("Energy", charge);
|
||||
tags.setInteger("EnergyMax", maxCharge);
|
||||
tags.setInteger("EnergyExtractionRate", maxExtract);
|
||||
tags.setInteger("EnergyReceiveRate", maxReceive);
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user