diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java index f21054007..9a5bce385 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java @@ -10,7 +10,8 @@ package de.ellpeck.actuallyadditions.mod.tile; -import cofh.api.energy.EnergyStorage; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.energy.EnergyStorage; public class CustomEnergyStorage extends EnergyStorage{ @@ -28,21 +29,33 @@ public class CustomEnergyStorage extends EnergyStorage{ public int extractEnergyInternal(int maxExtract, boolean simulate){ int before = this.maxExtract; - this.setMaxExtract(Integer.MAX_VALUE); + this.maxExtract = Integer.MAX_VALUE; int toReturn = this.extractEnergy(maxExtract, simulate); - this.setMaxExtract(before); + this.maxExtract = before; return toReturn; } public int receiveEnergyInternal(int maxReceive, boolean simulate){ int before = this.maxReceive; - this.setMaxReceive(Integer.MAX_VALUE); + this.maxReceive = Integer.MAX_VALUE; int toReturn = this.receiveEnergy(maxReceive, simulate); - this.setMaxReceive(before); + this.maxReceive = before; return toReturn; } + + public void readFromNBT(NBTTagCompound compound){ + this.energy = compound.getInteger("Energy"); + } + + public void writeToNBT(NBTTagCompound compound){ + compound.setInteger("Energy", this.energy); + } + + public void setEnergyStored(int energy){ + this.energy = energy; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java index 5a438a958..824f07992 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -26,6 +26,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.energy.IEnergyStorage; public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements ICustomEnergyReceiver, IEnergyDisplay, IAtomicReconstructor{ @@ -215,4 +216,9 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple public void activateOnPulse(){ this.doWork(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java index 6437e93ef..979bb1ac2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java @@ -32,6 +32,8 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fml.common.network.NetworkRegistry; @@ -320,6 +322,12 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{ return (T)tank; } } + else if(capability == CapabilityEnergy.ENERGY){ + IEnergyStorage storage = this.getEnergyStorage(facing); + if(storage != null){ + return (T)storage; + } + } else if(ActuallyAdditions.teslaLoaded){ T cap = TeslaUtil.wrapTeslaToRF(this, capability, facing); if(cap != null){ @@ -333,6 +341,10 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{ return null; } + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return null; + } + public boolean isRedstoneToggle(){ return false; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java index 4260e2a2b..d1a7f5aa9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java @@ -21,6 +21,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraftforge.common.IPlantable; +import net.minecraftforge.energy.IEnergyStorage; import java.util.ArrayList; import java.util.List; @@ -176,4 +177,9 @@ public class TileEntityBioReactor extends TileEntityInventoryBase implements ISh public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java index a63190eb2..42a74ecda 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java @@ -19,6 +19,7 @@ import de.ellpeck.actuallyadditions.mod.util.Util; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; @@ -169,4 +170,9 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IC public EnumFacing[] getFluidShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java index 2fc3b9ab8..34dbccec4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java @@ -16,6 +16,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -143,4 +144,9 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java index 6865ce07c..4cb2cffc7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java @@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.capability.IFluidHandler; import net.minecraftforge.fluids.capability.IFluidTankProperties; @@ -231,4 +232,9 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements public EnumFacing[] getFluidShareSides(){ return null; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDirectionalBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDirectionalBreaker.java index f6768903c..6aadbf3ca 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDirectionalBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDirectionalBreaker.java @@ -18,6 +18,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -152,4 +153,9 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem public void activateOnPulse(){ this.doWork(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java index 6c87ef594..51d1b97e1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java @@ -19,6 +19,7 @@ import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; public class TileEntityDisplayStand extends TileEntityInventoryBase implements IEnergyDisplay, ICustomEnergyReceiver{ @@ -137,4 +138,9 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I public int getInventoryStackLimit(){ return 1; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java index aa5b261ee..3aba6a2ab 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java @@ -20,6 +20,7 @@ import net.darkhax.tesla.api.ITeslaHolder; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -128,4 +129,9 @@ public class TileEntityEnergizer extends TileEntityInventoryBase implements ICus public boolean canConnectEnergy(EnumFacing from){ return true; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java index b00094c23..36b2a225d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java @@ -20,6 +20,7 @@ import net.darkhax.tesla.api.ITeslaProducer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -144,4 +145,9 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements ISha public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java index 63c7c25d5..c38a39578 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java @@ -28,6 +28,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.IPlantable; +import net.minecraftforge.energy.IEnergyStorage; import java.util.ArrayList; import java.util.List; @@ -235,4 +236,9 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements ICustom public boolean canConnectEnergy(EnumFacing from){ return true; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java index 5cdbee53a..0534a9b8f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java @@ -20,6 +20,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import net.minecraftforge.energy.IEnergyStorage; public class TileEntityFireworkBox extends TileEntityBase implements ICustomEnergyReceiver, IEnergyDisplay{ @@ -170,4 +171,9 @@ public class TileEntityFireworkBox extends TileEntityBase implements ICustomEner public boolean needsHoldShift(){ return false; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java index 2c7ece2d0..a5ed72fee 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java @@ -22,6 +22,7 @@ import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -225,4 +226,9 @@ public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements this.markDirty(); } } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java index d94754f1e..2960d9951 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java @@ -15,6 +15,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.energy.IEnergyStorage; public class TileEntityFurnaceSolar extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay{ @@ -121,4 +122,9 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements ISharingEn public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java index 7517c2235..e47b6fdbd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java @@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.SoundCategory; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -257,4 +258,9 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto this.markDirty(); } } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java index 69be6260d..c4d09a656 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java @@ -18,6 +18,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.energy.IEnergyStorage; import java.util.ArrayList; @@ -120,4 +121,10 @@ public class TileEntityHeatCollector extends TileEntityBase implements ISharingE public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } + } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemRepairer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemRepairer.java index 300968478..3e4020651 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemRepairer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemRepairer.java @@ -17,6 +17,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -160,4 +161,9 @@ public class TileEntityItemRepairer extends TileEntityInventoryBase implements I public boolean canConnectEnergy(EnumFacing from){ return true; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java index 0c9925c8e..24e80ce10 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java @@ -20,6 +20,7 @@ import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.energy.IEnergyStorage; public class TileEntityLavaFactoryController extends TileEntityBase implements ICustomEnergyReceiver, IEnergyDisplay{ @@ -127,4 +128,9 @@ public class TileEntityLavaFactoryController extends TileEntityBase implements I public boolean needsHoldShift(){ return false; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java index 1e8ed2b71..9ca65f59e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -16,6 +16,7 @@ import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.energy.IEnergyStorage; import java.util.ArrayList; import java.util.Collections; @@ -138,4 +139,9 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java index 57e096108..feb2efc25 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java @@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.oredict.OreDictionary; @@ -233,4 +234,9 @@ public class TileEntityMiner extends TileEntityInventoryBase implements ICustomE public boolean needsHoldShift(){ return false; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java index b257d06b0..c13f8ee39 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.api.recipe.OilGenRecipe; import de.ellpeck.actuallyadditions.mod.util.Util; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTank; @@ -198,4 +199,9 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn public EnumFacing[] getEnergyShareSides(){ return EnumFacing.values(); } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java index 473e84b50..052b94649 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java @@ -21,6 +21,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import java.util.UUID; @@ -239,4 +240,9 @@ public class TileEntityPlayerInterface extends TileEntityInventoryBase implement public boolean needsHoldShift(){ return false; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java index 5d5e5af05..92e2e80d9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; +import net.minecraftforge.energy.IEnergyStorage; import java.util.ArrayList; import java.util.List; @@ -105,4 +106,9 @@ public class TileEntityShockSuppressor extends TileEntityBase implements ICustom public boolean needsHoldShift(){ return false; } + + @Override + public IEnergyStorage getEnergyStorage(EnumFacing facing){ + return this.storage; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index 78bad2603..ae96da466 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -43,6 +43,8 @@ import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayerFactory; +import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; @@ -84,11 +86,28 @@ public final class WorldUtil{ if(handlerTo.canConnectEnergy(sideTo.getOpposite())){ int filled = handlerTo.receiveEnergy(sideTo.getOpposite(), drain, false); handlerFrom.extractEnergy(sideTo, filled, false); + return; } } } - else if(ActuallyAdditions.teslaLoaded){ - TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer); + + if(ActuallyAdditions.teslaLoaded){ + if(TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer)){ + return; + } + } + + if(tileFrom.hasCapability(CapabilityEnergy.ENERGY, sideTo) && tileTo.hasCapability(CapabilityEnergy.ENERGY, sideTo.getOpposite())){ + IEnergyStorage handlerFrom = tileFrom.getCapability(CapabilityEnergy.ENERGY, sideTo); + IEnergyStorage handlerTo = tileTo.getCapability(CapabilityEnergy.ENERGY, sideTo.getOpposite()); + + if(handlerFrom != null && handlerTo != null){ + int drain = handlerFrom.extractEnergy(maxTransfer, true); + if(drain > 0){ + int filled = handlerTo.receiveEnergy(drain, false); + handlerFrom.extractEnergy(filled, false); + } + } } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/TeslaUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/TeslaUtil.java index 977fb8253..f2a2df574 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/TeslaUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/compat/TeslaUtil.java @@ -47,17 +47,21 @@ public final class TeslaUtil{ } } - public static void doWrappedTeslaRFInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing side, int maxTransfer){ + public static boolean doWrappedTeslaRFInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing side, int maxTransfer){ if(tileTo.hasCapability(teslaConsumer, side.getOpposite()) && tileFrom.hasCapability(teslaProducer, side)){ ITeslaConsumer handlerTo = tileTo.getCapability(teslaConsumer, side.getOpposite()); ITeslaProducer handlerFrom = tileFrom.getCapability(teslaProducer, side); - long drain = handlerFrom.takePower(maxTransfer, true); - if(drain > 0){ - long filled = handlerTo.givePower(drain, false); - handlerFrom.takePower(filled, false); + if(handlerTo != null && handlerFrom != null){ + long drain = handlerFrom.takePower(maxTransfer, true); + if(drain > 0){ + long filled = handlerTo.givePower(drain, false); + handlerFrom.takePower(filled, false); + return true; + } } } + return false; } private static TileTeslaWrapper getHandler(TileEntityBase tile, EnumFacing facing){