diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java index da2630cd8..734976717 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java @@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.recipe; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; -import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ICustomEnergyReceiver.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ICustomEnergyReceiver.java new file mode 100644 index 000000000..1d1f48e80 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ICustomEnergyReceiver.java @@ -0,0 +1,17 @@ +/* + * This file ("IDontWannaUseRFReceiver.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.tile; + +import cofh.api.energy.IEnergyReceiver; + +public interface ICustomEnergyReceiver extends IEnergyReceiver{ + +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ISharingEnergyProvider.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ISharingEnergyProvider.java new file mode 100644 index 000000000..0b47e91ea --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ISharingEnergyProvider.java @@ -0,0 +1,24 @@ +/* + * This file ("IEnergyProviderBetter.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.tile; + +import cofh.api.energy.IEnergyProvider; +import net.minecraft.util.EnumFacing; + +public interface ISharingEnergyProvider extends IEnergyProvider{ + + int getEnergyToSplitShare(); + + boolean doesShareEnergy(); + + EnumFacing[] getEnergyShareSides(); + +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ISharingFluidHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ISharingFluidHandler.java new file mode 100644 index 000000000..d9958190c --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/ISharingFluidHandler.java @@ -0,0 +1,24 @@ +/* + * This file ("ISharingFluidHandler.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.tile; + +import net.minecraft.util.EnumFacing; +import net.minecraftforge.fluids.IFluidHandler; + +public interface ISharingFluidHandler extends IFluidHandler{ + + int getFluidAmountToSplitShare(); + + boolean doesShareFluid(); + + EnumFacing[] getFluidShareSides(); + +} 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 1794ba3fa..686bb3e4f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; import de.ellpeck.actuallyadditions.api.lens.ILensItem; @@ -28,7 +27,7 @@ import net.minecraft.util.SoundCategory; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements IEnergyReceiver, IEnergyDisplay, IAtomicReconstructor{ +public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements ICustomEnergyReceiver, IEnergyDisplay, IAtomicReconstructor{ public static final int ENERGY_USE = 1000; public final EnergyStorage storage = new EnergyStorage(300000); 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 8b24000fb..b188d65c6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java @@ -10,8 +10,6 @@ package de.ellpeck.actuallyadditions.mod.tile; -import cofh.api.energy.IEnergyProvider; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; @@ -219,12 +217,26 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{ this.ticksElapsed++; if(!this.worldObj.isRemote){ - if(this instanceof IEnergyReceiver || this instanceof IEnergyProvider){ - WorldUtil.doEnergyInteraction(this); + if(this instanceof ISharingEnergyProvider){ + ISharingEnergyProvider provider = (ISharingEnergyProvider)this; + if(provider.doesShareEnergy()){ + EnumFacing[] sides = provider.getEnergyShareSides(); + int amount = provider.getEnergyToSplitShare()/sides.length; + for(EnumFacing side : sides){ + WorldUtil.doEnergyInteraction(this, side, amount); + } + } } - if(this instanceof net.minecraftforge.fluids.IFluidHandler || this.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)){ - WorldUtil.doFluidInteraction(this); + if(this instanceof ISharingFluidHandler){ + ISharingFluidHandler handler = (ISharingFluidHandler)this; + if(handler.doesShareFluid()){ + EnumFacing[] sides = handler.getFluidShareSides(); + int amount = handler.getFluidAmountToSplitShare()/sides.length; + for(EnumFacing side : sides){ + WorldUtil.doFluidInteraction(this, side, amount); + } + } } } } 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 e87cb1b6c..02f94a1cd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems; @@ -25,7 +24,7 @@ import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityCanolaPress extends TileEntityInventoryBase implements IEnergyReceiver, net.minecraftforge.fluids.IFluidHandler{ +public class TileEntityCanolaPress extends TileEntityInventoryBase implements ICustomEnergyReceiver, ISharingFluidHandler{ public static final int PRODUCE = 80; public static final int ENERGY_USE = 35; @@ -212,4 +211,19 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE return null; } } + + @Override + public int getFluidAmountToSplitShare(){ + return this.tank.getFluidAmount(); + } + + @Override + public boolean doesShareFluid(){ + return true; + } + + @Override + public EnumFacing[] getFluidShareSides(){ + return EnumFacing.values(); + } } 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 8a721f8eb..95a17f341 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java @@ -19,7 +19,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityCoalGenerator extends TileEntityInventoryBase implements IEnergyProvider{ +public class TileEntityCoalGenerator extends TileEntityInventoryBase implements ISharingEnergyProvider{ public static final int PRODUCE = 30; public final EnergyStorage storage = new EnergyStorage(60000); @@ -131,4 +131,19 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements public boolean canConnectEnergy(EnumFacing from){ return true; } + + @Override + public int getEnergyToSplitShare(){ + return this.storage.getEnergyStored(); + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } } 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 e5fcdf991..df8adbd88 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoffeeMachine.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.items.InitItems; @@ -31,7 +30,7 @@ import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, IEnergyReceiver, net.minecraftforge.fluids.IFluidHandler{ +public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements IButtonReactor, ICustomEnergyReceiver, ISharingFluidHandler{ public static final int SLOT_COFFEE_BEANS = 0; public static final int SLOT_INPUT = 1; @@ -281,4 +280,19 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements return null; } } + + @Override + public int getFluidAmountToSplitShare(){ + return 0; + } + + @Override + public boolean doesShareFluid(){ + return false; + } + + @Override + public EnumFacing[] getFluidShareSides(){ + return null; + } } 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 38f3c0697..e730a8d9b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDirectionalBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDirectionalBreaker.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; @@ -28,7 +27,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; -public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implements IEnergyReceiver{ +public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implements ICustomEnergyReceiver{ public static final int RANGE = 8; public static final int ENERGY_USE = 5; 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 893860d79..c69723c08 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem; import net.minecraft.block.Block; import net.minecraft.item.Item; @@ -20,7 +19,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; -public class TileEntityDisplayStand extends TileEntityInventoryBase implements IEnergyDisplay, IEnergyReceiver{ +public class TileEntityDisplayStand extends TileEntityInventoryBase implements IEnergyDisplay, ICustomEnergyReceiver{ public final EnergyStorage storage = new EnergyStorage(800000); private int oldEnergy; 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 cb431e6b9..8f5d982a9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnergizer.java @@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; import cofh.api.energy.IEnergyContainerItem; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import net.darkhax.tesla.api.ITeslaConsumer; @@ -23,7 +22,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityEnergizer extends TileEntityInventoryBase implements IEnergyReceiver{ +public class TileEntityEnergizer extends TileEntityInventoryBase implements ICustomEnergyReceiver{ public final EnergyStorage storage = new EnergyStorage(500000); private int lastEnergy; 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 84cbb8d12..7d077e4c9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEnervator.java @@ -23,7 +23,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityEnervator extends TileEntityInventoryBase implements IEnergyProvider{ +public class TileEntityEnervator extends TileEntityInventoryBase implements ISharingEnergyProvider{ public final EnergyStorage storage = new EnergyStorage(500000); private int lastEnergy; @@ -132,4 +132,19 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ return slot == 1; } + + @Override + public int getEnergyToSplitShare(){ + return this.storage.getEnergyStored(); + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java index 490690db6..023a6817a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFermentingBarrel.java @@ -21,7 +21,7 @@ import net.minecraftforge.fluids.capability.templates.FluidHandlerFluidMap; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityFermentingBarrel extends TileEntityBase implements net.minecraftforge.fluids.IFluidHandler{ +public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler{ private static final int PROCESS_TIME = 100; public final FluidTank canolaTank = new FluidTank(2*Util.BUCKET){ @@ -176,4 +176,19 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements net.mi return null; } } + + @Override + public int getFluidAmountToSplitShare(){ + return this.oilTank.getFluidAmount(); + } + + @Override + public boolean doesShareFluid(){ + return true; + } + + @Override + public EnumFacing[] getFluidShareSides(){ + return EnumFacing.values(); + } } 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 35ae240da..7e06e4f0d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFireworkBox.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.util.Util; import net.minecraft.entity.item.EntityFireworkRocket; import net.minecraft.init.Items; @@ -23,7 +22,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; -public class TileEntityFireworkBox extends TileEntityBase implements IEnergyReceiver, IEnergyDisplay{ +public class TileEntityFireworkBox extends TileEntityBase implements ICustomEnergyReceiver, IEnergyDisplay{ public static final int USE_PER_SHOT = 300; public final EnergyStorage storage = new EnergyStorage(20000); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java index 9596b5fac..e56b10e14 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java @@ -29,7 +29,7 @@ import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityFluidCollector extends TileEntityBase implements net.minecraftforge.fluids.IFluidHandler{ +public class TileEntityFluidCollector extends TileEntityBase implements ISharingFluidHandler{ public boolean isPlacer; public final FluidTank tank = new FluidTank(8*Util.BUCKET){ @@ -225,4 +225,19 @@ public class TileEntityFluidCollector extends TileEntityBase implements net.mine return null; } } + + @Override + public int getFluidAmountToSplitShare(){ + return this.tank.getFluidAmount(); + } + + @Override + public boolean doesShareFluid(){ + return true; + } + + @Override + public EnumFacing[] getFluidShareSides(){ + return EnumFacing.values(); + } } 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 90c71f9f6..705fcb703 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceDouble.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import net.minecraft.block.Block; @@ -24,7 +23,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements IEnergyReceiver, IButtonReactor{ +public class TileEntityFurnaceDouble extends TileEntityInventoryBase implements ICustomEnergyReceiver, IButtonReactor{ public static final int SLOT_INPUT_1 = 0; public static final int SLOT_OUTPUT_1 = 1; 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 43d3ed199..a9ed71f15 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFurnaceSolar.java @@ -17,7 +17,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyProvider, IEnergyDisplay{ +public class TileEntityFurnaceSolar extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay{ public static final int PRODUCE = 8; public final EnergyStorage storage = new EnergyStorage(30000); @@ -96,4 +96,19 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyPro public boolean needsHoldShift(){ return false; } + + @Override + public int getEnergyToSplitShare(){ + return this.storage.getEnergyStored(); + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } } 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 d6dfed01b..128facca7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java @@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.misc.SoundHandler; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; @@ -30,7 +29,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; -public class TileEntityGrinder extends TileEntityInventoryBase implements IEnergyReceiver, IButtonReactor{ +public class TileEntityGrinder extends TileEntityInventoryBase implements ICustomEnergyReceiver, IButtonReactor{ public static final int SLOT_INPUT_1 = 0; public static final int SLOT_OUTPUT_1_1 = 1; 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 1f6736d9d..56fd823ab 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java @@ -23,7 +23,7 @@ import net.minecraft.util.math.BlockPos; import java.util.ArrayList; -public class TileEntityHeatCollector extends TileEntityBase implements IEnergyProvider, IEnergyDisplay{ +public class TileEntityHeatCollector extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay{ public static final int ENERGY_PRODUCE = 40; public static final int BLOCKS_NEEDED = 4; @@ -107,4 +107,19 @@ public class TileEntityHeatCollector extends TileEntityBase implements IEnergyPr public boolean needsHoldShift(){ return false; } + + @Override + public int getEnergyToSplitShare(){ + return this.storage.getEnergyStored(); + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } } 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 496af3794..0a2e6b6dd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemRepairer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemRepairer.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -20,7 +19,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityItemRepairer extends TileEntityInventoryBase implements IEnergyReceiver{ +public class TileEntityItemRepairer extends TileEntityInventoryBase implements ICustomEnergyReceiver{ public static final int SLOT_INPUT = 0; public static final int SLOT_OUTPUT = 1; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java index 718abc0d1..abfbc68ca 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java @@ -21,13 +21,14 @@ import net.darkhax.tesla.api.ITeslaConsumer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements IEnergyReceiver{ +public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements ICustomEnergyReceiver{ public final ConcurrentHashMap receiversAround = new ConcurrentHashMap(); @@ -92,6 +93,9 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements //Keeps track of all the Laser Relays and Energy Acceptors that have been checked already to make nothing run multiple times List alreadyChecked = new ArrayList(); + List relaysThatWork = new ArrayList(); + int totalReceiverAmount = 0; + for(ConnectionPair pair : network.connections){ for(BlockPos relay : pair.positions){ if(relay != null && !alreadyChecked.contains(relay)){ @@ -99,52 +103,65 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements TileEntity relayTile = this.worldObj.getTileEntity(relay); if(relayTile instanceof TileEntityLaserRelayEnergy){ TileEntityLaserRelayEnergy theRelay = (TileEntityLaserRelayEnergy)relayTile; - double highestLoss = Math.max(theRelay.getLossPercentage(), this.getLossPercentage()); - int lowestCap = Math.min(theRelay.getEnergyCap(), this.getEnergyCap()); - for(Map.Entry receiver : theRelay.receiversAround.entrySet()){ - if(receiver != null){ - EnumFacing side = receiver.getKey(); - EnumFacing opp = side.getOpposite(); - TileEntity tile = receiver.getValue(); - if(!alreadyChecked.contains(tile.getPos())){ - alreadyChecked.add(tile.getPos()); - if(theRelay != this || side != from){ - if(tile instanceof IEnergyReceiver){ - IEnergyReceiver iReceiver = (IEnergyReceiver)tile; - if(iReceiver.canConnectEnergy(opp)){ - int theoreticalReceived = iReceiver.receiveEnergy(opp, Math.min(maxTransfer, lowestCap)-transmitted, true); - int deduct = this.calcDeduction(theoreticalReceived, highestLoss); - transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate); - transmitted += deduct; - } - } - else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){ - ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp); - if(cap != null){ - int theoreticalReceived = (int)cap.givePower(Math.min(maxTransfer, lowestCap)-transmitted, true); - int deduct = this.calcDeduction(theoreticalReceived, highestLoss); - transmitted += cap.givePower(theoreticalReceived-deduct, simulate); - transmitted += deduct; - } - } + int amount = theRelay.receiversAround.size(); + if(amount > 0){ + relaysThatWork.add(theRelay); + totalReceiverAmount += amount; + } + } + } + } + } - //If everything that could be transmitted was transmitted - if(transmitted >= maxTransfer){ - return transmitted; - } + if(totalReceiverAmount > 0 && !relaysThatWork.isEmpty()){ + int amountPer = maxTransfer/totalReceiverAmount; + + for(TileEntityLaserRelayEnergy theRelay : relaysThatWork){ + double highestLoss = Math.max(theRelay.getLossPercentage(), this.getLossPercentage()); + int lowestCap = Math.min(theRelay.getEnergyCap(), this.getEnergyCap()); + for(Map.Entry receiver : theRelay.receiversAround.entrySet()){ + if(receiver != null){ + EnumFacing side = receiver.getKey(); + EnumFacing opp = side.getOpposite(); + TileEntity tile = receiver.getValue(); + if(!alreadyChecked.contains(tile.getPos())){ + alreadyChecked.add(tile.getPos()); + if(theRelay != this || side != from){ + if(tile instanceof IEnergyReceiver){ + IEnergyReceiver iReceiver = (IEnergyReceiver)tile; + if(iReceiver.canConnectEnergy(opp)){ + int theoreticalReceived = iReceiver.receiveEnergy(opp, Math.min(amountPer, lowestCap), true); + int deduct = this.calcDeduction(theoreticalReceived, highestLoss); + transmitted += iReceiver.receiveEnergy(opp, theoreticalReceived-deduct, simulate); + transmitted += deduct; } } + else if(ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, opp)){ + ITeslaConsumer cap = tile.getCapability(TeslaUtil.teslaConsumer, opp); + if(cap != null){ + int theoreticalReceived = (int)cap.givePower(Math.min(amountPer, lowestCap), true); + int deduct = this.calcDeduction(theoreticalReceived, highestLoss); + transmitted += cap.givePower(theoreticalReceived-deduct, simulate); + transmitted += deduct; + } + } + + //If everything that could be transmitted was transmitted + if(transmitted >= maxTransfer){ + return transmitted; + } } } } } } } + return transmitted; } private int calcDeduction(int theoreticalReceived, double highestLoss){ - return ConfigBoolValues.LASER_RELAY_LOSS.isEnabled() ? (int)(theoreticalReceived*(highestLoss/100)) : 0; + return ConfigBoolValues.LASER_RELAY_LOSS.isEnabled() ? MathHelper.ceiling_double_int(theoreticalReceived*(highestLoss/100)) : 0; } public int getEnergyCap(){ 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 c6453563d..8100c444b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLavaFactoryController.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; @@ -22,7 +21,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -public class TileEntityLavaFactoryController extends TileEntityBase implements IEnergyReceiver, IEnergyDisplay{ +public class TileEntityLavaFactoryController extends TileEntityBase implements ICustomEnergyReceiver, IEnergyDisplay{ public static final int NOT_MULTI = 0; public static final int HAS_LAVA = 1; 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 483dd18d0..3b1e145d7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -23,7 +23,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyProvider, IEnergyDisplay{ +public class TileEntityLeafGenerator extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay{ public static final int RANGE = 7; public static final int ENERGY_PRODUCED = 300; @@ -129,4 +129,19 @@ public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyPr public boolean needsHoldShift(){ return false; } + + @Override + public int getEnergyToSplitShare(){ + return this.storage.getEnergyStored(); + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } } 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 a4e202d4d..19240e483 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java @@ -11,7 +11,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.items.ItemDrill; @@ -33,7 +32,7 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.List; -public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyReceiver, IButtonReactor, IEnergyDisplay{ +public class TileEntityMiner extends TileEntityInventoryBase implements ICustomEnergyReceiver, IButtonReactor, IEnergyDisplay{ public static final int ENERGY_USE_PER_BLOCK = 1500; public static final int DEFAULT_RANGE = 2; 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 b5f040978..d7a1f828c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -22,7 +22,7 @@ import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class TileEntityOilGenerator extends TileEntityBase implements IEnergyProvider, net.minecraftforge.fluids.IFluidHandler{ +public class TileEntityOilGenerator extends TileEntityBase implements ISharingEnergyProvider, ISharingFluidHandler{ public static final int ENERGY_PRODUCED = 76; private static final int BURN_TIME = 100; @@ -192,4 +192,34 @@ public class TileEntityOilGenerator extends TileEntityBase implements IEnergyPro return null; } } + + @Override + public int getFluidAmountToSplitShare(){ + return 0; + } + + @Override + public boolean doesShareFluid(){ + return false; + } + + @Override + public EnumFacing[] getFluidShareSides(){ + return null; + } + + @Override + public int getEnergyToSplitShare(){ + return this.storage.getEnergyStored(); + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java index 4c819a54d..b1922c3f4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java @@ -23,7 +23,7 @@ import net.darkhax.tesla.api.ITeslaProducer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; -public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements IEnergyReceiver, IEnergyProvider{ +public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ICustomEnergyReceiver, ISharingEnergyProvider{ public TileEntityPhantomEnergyface(){ super("energyface"); @@ -132,4 +132,19 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement } return false; } + + @Override + public int getEnergyToSplitShare(){ + return Integer.MAX_VALUE; + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java index 3c5ddc8e6..4d52cbbba 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java @@ -13,13 +13,10 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; +import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; -public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{ +public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler{ public TileEntityPhantomLiquiface(){ super("liquiface"); @@ -88,4 +85,19 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements } return null; } + + @Override + public int getFluidAmountToSplitShare(){ + return Integer.MAX_VALUE; + } + + @Override + public boolean doesShareFluid(){ + return true; + } + + @Override + public EnumFacing[] getFluidShareSides(){ + return EnumFacing.values(); + } } 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 5eff581d0..2130a4883 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java @@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; import cofh.api.energy.IEnergyContainerItem; -import cofh.api.energy.IEnergyReceiver; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import net.darkhax.tesla.api.ITeslaConsumer; @@ -24,7 +23,7 @@ import net.minecraft.util.EnumFacing; import java.util.UUID; -public class TileEntityPlayerInterface extends TileEntityInventoryBase implements IEnergyReceiver, IEnergyDisplay{ +public class TileEntityPlayerInterface extends TileEntityInventoryBase implements ICustomEnergyReceiver, IEnergyDisplay{ public static final int DEFAULT_RANGE = 32; private final EnergyStorage storage = new EnergyStorage(30000); 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 37d95aaf2..93b3e076e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java @@ -11,14 +11,13 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; -import cofh.api.energy.IEnergyReceiver; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import java.util.ArrayList; import java.util.List; -public class TileEntityShockSuppressor extends TileEntityBase implements IEnergyReceiver, IEnergyDisplay{ +public class TileEntityShockSuppressor extends TileEntityBase implements ICustomEnergyReceiver, IEnergyDisplay{ public static final List SUPPRESSORS = new ArrayList(); 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 3e9898083..22cd16e18 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -91,70 +91,51 @@ public final class WorldUtil{ return null; } - public static void doEnergyInteraction(TileEntity tile){ - for(EnumFacing side : EnumFacing.values()){ - TileEntity otherTile = tile.getWorld().getTileEntity(tile.getPos().offset(side)); - if(otherTile != null){ - IEnergyReceiver handlerTo = null; - IEnergyProvider handlerFrom = null; + public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){ + TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo)); + if(tileTo != null){ + if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){ + IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo; + IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom; - //Push RF - if(tile instanceof IEnergyProvider && otherTile instanceof IEnergyReceiver){ - handlerTo = (IEnergyReceiver)otherTile; - handlerFrom = (IEnergyProvider)tile; - } - //Pull RF - else if(tile instanceof IEnergyReceiver && otherTile instanceof IEnergyProvider){ - handlerTo = (IEnergyReceiver)tile; - handlerFrom = (IEnergyProvider)otherTile; - } - - if(handlerFrom != null && handlerTo != null){ - int drain = handlerFrom.extractEnergy(side, Integer.MAX_VALUE, true); - if(drain > 0){ - if(handlerTo.canConnectEnergy(side.getOpposite())){ - int filled = handlerTo.receiveEnergy(side.getOpposite(), drain, false); - handlerFrom.extractEnergy(side, filled, false); - } + int drain = handlerFrom.extractEnergy(sideTo, maxTransfer, true); + if(drain > 0){ + if(handlerTo.canConnectEnergy(sideTo.getOpposite())){ + int filled = handlerTo.receiveEnergy(sideTo.getOpposite(), drain, false); + handlerFrom.extractEnergy(sideTo, filled, false); } } - else if(ActuallyAdditions.teslaLoaded){ - TeslaUtil.doWrappedTeslaRFInteraction(tile, otherTile, side); - } + } + else if(ActuallyAdditions.teslaLoaded){ + TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer); } } } - public static void doFluidInteraction(TileEntity tile){ - for(EnumFacing side : EnumFacing.values()){ - TileEntity otherTile = tile.getWorld().getTileEntity(tile.getPos().offset(side)); - if(otherTile != null){ - for(int i = 0; i < 2; i++){ - //Push and pull with old fluid system - if(tile instanceof net.minecraftforge.fluids.IFluidHandler && otherTile instanceof net.minecraftforge.fluids.IFluidHandler){ - net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)(i == 0 ? tile : otherTile); - net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)(i == 0 ? otherTile : tile); - FluidStack drain = handlerFrom.drain(side, Integer.MAX_VALUE, false); - if(drain != null){ - if(handlerTo.canFill(side.getOpposite(), drain.getFluid())){ - int filled = handlerTo.fill(side.getOpposite(), drain.copy(), true); - handlerFrom.drain(side, filled, true); - break; - } - } + public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){ + TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo)); + if(tileTo != null){ + //Push and pull with old fluid system + if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){ + net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo; + net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom; + FluidStack drain = handlerFrom.drain(sideTo, maxTransfer, false); + if(drain != null){ + if(handlerTo.canFill(sideTo.getOpposite(), drain.getFluid())){ + int filled = handlerTo.fill(sideTo.getOpposite(), drain.copy(), true); + handlerFrom.drain(sideTo, filled, true); } - //Push and pull with new fluid system - else{ - IFluidHandler handlerFrom = (i == 0 ? tile : otherTile).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, i == 0 ? side : side.getOpposite()); - IFluidHandler handlerTo = (i == 0 ? otherTile : tile).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, i == 0 ? side.getOpposite() : side); - if(handlerFrom != null && handlerTo != null){ - FluidStack drain = handlerFrom.drain(Integer.MAX_VALUE, false); - if(drain != null){ - int filled = handlerTo.fill(drain.copy(), true); - handlerFrom.drain(filled, true); - break; - } - } + } + } + //Push and pull with new fluid system + else{ + if(tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())){ + IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo); + IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite()); + FluidStack drain = handlerFrom.drain(maxTransfer, false); + if(drain != null){ + int filled = handlerTo.fill(drain.copy(), true); + handlerFrom.drain(filled, true); } } } 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 14e07db21..977fb8253 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,19 +47,12 @@ public final class TeslaUtil{ } } - public static void doWrappedTeslaRFInteraction(TileEntity tile, TileEntity otherTile, EnumFacing side){ - ITeslaConsumer handlerTo = null; - ITeslaProducer handlerFrom = null; + public static void 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); - for(int i = 0; i < 2; i++){ - if(handlerFrom == null && handlerTo == null){ - handlerFrom = (i == 0 ? tile : otherTile).getCapability(teslaProducer, i == 0 ? side : side.getOpposite()); - handlerTo = (i == 0 ? otherTile : tile).getCapability(teslaConsumer, i == 0 ? side.getOpposite() : side); - } - } - - if(handlerFrom != null && handlerTo != null){ - long drain = handlerFrom.takePower(Long.MAX_VALUE, true); + long drain = handlerFrom.takePower(maxTransfer, true); if(drain > 0){ long filled = handlerTo.givePower(drain, false); handlerFrom.takePower(filled, false);