mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 03:49:29 +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
@@ -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