use of de.canitzp.metalworks.CustomEnergyStorage in project Metalworks by canitzp.
the class TileBase method writeCapabilities.
private void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
if (hasEnergyFluidInv().getRight()) {
IItemHandler inventory = this.getInventory(side);
if (inventory instanceof IItemHandlerModifiable) {
nbt.setTag("Inventory", Objects.requireNonNull(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side)));
}
}
if (hasEnergyFluidInv().getMiddle()) {
IFluidHandler tank = getTank(side);
if (tank instanceof IFluidTank) {
nbt.setTag("FluidTank", Objects.requireNonNull(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side)));
}
}
if (hasEnergyFluidInv().getLeft()) {
IEnergyStorage energy = getEnergy(side);
if (energy instanceof CustomEnergyStorage) {
NBTTagCompound energyTag = new NBTTagCompound();
energyTag.setInteger("Stored", energy.getEnergyStored());
energyTag.setInteger("Capacity", energy.getMaxEnergyStored());
energyTag.setInteger("MaxReceive", ((CustomEnergyStorage) energy).getReceiveTransfer());
energyTag.setInteger("MaxExtract", ((CustomEnergyStorage) energy).getExtractTransfer());
nbt.setTag("Energy", energyTag);
}
}
}
use of de.canitzp.metalworks.CustomEnergyStorage in project Metalworks by canitzp.
the class TileBase method readCapabilities.
private void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
if (hasEnergyFluidInv().getRight()) {
IItemHandler inventory = this.getInventory(side);
if (inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")) {
for (int i = 0; i < inventory.getSlots(); i++) {
// clear the inventory, otherwise empty stacks doesn't get overridden while syncing. Forge Bug?
((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY);
}
CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory"));
}
}
if (hasEnergyFluidInv().getMiddle()) {
IFluidHandler tank = getTank(side);
if (tank instanceof IFluidTank && nbt.hasKey("FluidTank")) {
CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank"));
}
}
if (hasEnergyFluidInv().getLeft()) {
IEnergyStorage energy = getEnergy(side);
if (energy instanceof CustomEnergyStorage && nbt.hasKey("Energy", Constants.NBT.TAG_COMPOUND)) {
NBTTagCompound energyTag = nbt.getCompoundTag("Energy");
((CustomEnergyStorage) energy).setValues(energyTag.getInteger("Stored"), energyTag.getInteger("Capacity"), energyTag.getInteger("MaxReceive"), energyTag.getInteger("MaxExtract"));
}
}
}
use of de.canitzp.metalworks.CustomEnergyStorage in project Metalworks by canitzp.
the class TileBattery method onLoad.
@Override
public void onLoad() {
Block block = world.getBlockState(this.getPos()).getBlock();
if (block instanceof BlockBattery) {
int oldEnergy = this.normal.getEnergyStored();
BlockBattery.Type batType = ((BlockBattery) block).getBatteryType();
this.normal = new CustomEnergyStorage(batType.maxEnergy, batType.maxTransfer, batType.maxTransfer, oldEnergy).setTile(this);
this.input = new SlaveEnergyStorage(this.normal).set(true, false);
this.output = new SlaveEnergyStorage(this.normal).set(false, true);
}
}
Aggregations