mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 11:59:14 +00:00
Allow upgrading the Flux-Modifier, if the new battery is bigger
This commit is contained in:
1 parent
2510cfb2b6
commit
02de82951d
1 file changed
+71
-51
@@ -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,11 +24,9 @@ public class ModFlux extends ModBoolean
|
||||
@Override
|
||||
public boolean matches (ItemStack[] input, ItemStack tool)
|
||||
{
|
||||
// check if the regular limitations apply
|
||||
if(!canModify(tool, input))
|
||||
return false;
|
||||
NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool");
|
||||
|
||||
boolean foundBattery = false;
|
||||
ItemStack foundBattery = null;
|
||||
// try to find the battery in the input
|
||||
for(ItemStack stack : input)
|
||||
for(ItemStack battery : batteries)
|
||||
@@ -40,15 +38,32 @@ public class ModFlux extends ModBoolean
|
||||
if(!(stack.getItem() instanceof IEnergyContainerItem))
|
||||
continue;
|
||||
// we don't allow multiple batteries to be added
|
||||
if(foundBattery)
|
||||
if(foundBattery != null)
|
||||
return false;
|
||||
|
||||
// battery found, gogogo
|
||||
foundBattery = true;
|
||||
foundBattery = stack;
|
||||
}
|
||||
|
||||
// no battery found :(
|
||||
return foundBattery;
|
||||
// no battery present
|
||||
if(foundBattery == null)
|
||||
return false;
|
||||
|
||||
// check if we already have a flux modifier
|
||||
if(tags.getBoolean(key))
|
||||
{
|
||||
// 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;
|
||||
|
||||
// all requirements satisfied!
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,51 +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);
|
||||
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
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