Remove the weird energy and fluid pulling and also make them split into all devices around

Closes #221
This commit is contained in:
Ellpeck 2016-08-31 20:16:36 +02:00
parent b3a428e50f
commit e636ab14f1
32 changed files with 396 additions and 151 deletions

View file

@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.recipe;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; 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.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals; import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals;

View file

@ -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{
}

View file

@ -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();
}

View file

@ -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();
}

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
import de.ellpeck.actuallyadditions.api.lens.ILensItem; 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.util.math.BlockPos;
import net.minecraft.world.World; 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 static final int ENERGY_USE = 1000;
public final EnergyStorage storage = new EnergyStorage(300000); public final EnergyStorage storage = new EnergyStorage(300000);

View file

@ -10,8 +10,6 @@
package de.ellpeck.actuallyadditions.mod.tile; 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.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
@ -219,12 +217,26 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
this.ticksElapsed++; this.ticksElapsed++;
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(this instanceof IEnergyReceiver || this instanceof IEnergyProvider){ if(this instanceof ISharingEnergyProvider){
WorldUtil.doEnergyInteraction(this); 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)){ if(this instanceof ISharingFluidHandler){
WorldUtil.doFluidInteraction(this); 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);
}
}
} }
} }
} }

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems; 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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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 PRODUCE = 80;
public static final int ENERGY_USE = 35; public static final int ENERGY_USE = 35;
@ -212,4 +211,19 @@ public class TileEntityCanolaPress extends TileEntityInventoryBase implements IE
return null; return null;
} }
} }
@Override
public int getFluidAmountToSplitShare(){
return this.tank.getFluidAmount();
}
@Override
public boolean doesShareFluid(){
return true;
}
@Override
public EnumFacing[] getFluidShareSides(){
return EnumFacing.values();
}
} }

View file

@ -19,7 +19,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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 static final int PRODUCE = 30;
public final EnergyStorage storage = new EnergyStorage(60000); public final EnergyStorage storage = new EnergyStorage(60000);
@ -131,4 +131,19 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
public boolean canConnectEnergy(EnumFacing from){ public boolean canConnectEnergy(EnumFacing from){
return true; return true;
} }
@Override
public int getEnergyToSplitShare(){
return this.storage.getEnergyStored();
}
@Override
public boolean doesShareEnergy(){
return true;
}
@Override
public EnumFacing[] getEnergyShareSides(){
return EnumFacing.values();
}
} }

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.InitItems; 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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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_COFFEE_BEANS = 0;
public static final int SLOT_INPUT = 1; public static final int SLOT_INPUT = 1;
@ -281,4 +280,19 @@ public class TileEntityCoffeeMachine extends TileEntityInventoryBase implements
return null; return null;
} }
} }
@Override
public int getFluidAmountToSplitShare(){
return 0;
}
@Override
public boolean doesShareFluid(){
return false;
}
@Override
public EnumFacing[] getFluidShareSides(){
return null;
}
} }

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; 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.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
@ -28,7 +27,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List; 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 RANGE = 8;
public static final int ENERGY_USE = 5; public static final int ENERGY_USE = 5;

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem; import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -20,7 +19,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; 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); public final EnergyStorage storage = new EnergyStorage(800000);
private int oldEnergy; private int oldEnergy;

View file

@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer; 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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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); public final EnergyStorage storage = new EnergyStorage(500000);
private int lastEnergy; private int lastEnergy;

View file

@ -23,7 +23,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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); public final EnergyStorage storage = new EnergyStorage(500000);
private int lastEnergy; private int lastEnergy;
@ -132,4 +132,19 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return slot == 1; return slot == 1;
} }
@Override
public int getEnergyToSplitShare(){
return this.storage.getEnergyStored();
}
@Override
public boolean doesShareEnergy(){
return true;
}
@Override
public EnumFacing[] getEnergyShareSides(){
return EnumFacing.values();
}
} }

View file

@ -21,7 +21,7 @@ import net.minecraftforge.fluids.capability.templates.FluidHandlerFluidMap;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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; private static final int PROCESS_TIME = 100;
public final FluidTank canolaTank = new FluidTank(2*Util.BUCKET){ public final FluidTank canolaTank = new FluidTank(2*Util.BUCKET){
@ -176,4 +176,19 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements net.mi
return null; return null;
} }
} }
@Override
public int getFluidAmountToSplitShare(){
return this.oilTank.getFluidAmount();
}
@Override
public boolean doesShareFluid(){
return true;
}
@Override
public EnumFacing[] getFluidShareSides(){
return EnumFacing.values();
}
} }

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.item.EntityFireworkRocket; import net.minecraft.entity.item.EntityFireworkRocket;
import net.minecraft.init.Items; import net.minecraft.init.Items;
@ -23,7 +22,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; 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 static final int USE_PER_SHOT = 300;
public final EnergyStorage storage = new EnergyStorage(20000); public final EnergyStorage storage = new EnergyStorage(20000);

View file

@ -29,7 +29,7 @@ import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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 boolean isPlacer;
public final FluidTank tank = new FluidTank(8*Util.BUCKET){ public final FluidTank tank = new FluidTank(8*Util.BUCKET){
@ -225,4 +225,19 @@ public class TileEntityFluidCollector extends TileEntityBase implements net.mine
return null; return null;
} }
} }
@Override
public int getFluidAmountToSplitShare(){
return this.tank.getFluidAmount();
}
@Override
public boolean doesShareFluid(){
return true;
}
@Override
public EnumFacing[] getFluidShareSides(){
return EnumFacing.values();
}
} }

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import net.minecraft.block.Block; 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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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_INPUT_1 = 0;
public static final int SLOT_OUTPUT_1 = 1; public static final int SLOT_OUTPUT_1 = 1;

View file

@ -17,7 +17,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; 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 static final int PRODUCE = 8;
public final EnergyStorage storage = new EnergyStorage(30000); public final EnergyStorage storage = new EnergyStorage(30000);
@ -96,4 +96,19 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyPro
public boolean needsHoldShift(){ public boolean needsHoldShift(){
return false; return false;
} }
@Override
public int getEnergyToSplitShare(){
return this.storage.getEnergyStored();
}
@Override
public boolean doesShareEnergy(){
return true;
}
@Override
public EnumFacing[] getEnergyShareSides(){
return EnumFacing.values();
}
} }

View file

@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; 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.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.misc.SoundHandler; import de.ellpeck.actuallyadditions.mod.misc.SoundHandler;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
@ -30,7 +29,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List; 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_INPUT_1 = 0;
public static final int SLOT_OUTPUT_1_1 = 1; public static final int SLOT_OUTPUT_1_1 = 1;

View file

@ -23,7 +23,7 @@ import net.minecraft.util.math.BlockPos;
import java.util.ArrayList; 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 ENERGY_PRODUCE = 40;
public static final int BLOCKS_NEEDED = 4; public static final int BLOCKS_NEEDED = 4;
@ -107,4 +107,19 @@ public class TileEntityHeatCollector extends TileEntityBase implements IEnergyPr
public boolean needsHoldShift(){ public boolean needsHoldShift(){
return false; return false;
} }
@Override
public int getEnergyToSplitShare(){
return this.storage.getEnergyStored();
}
@Override
public boolean doesShareEnergy(){
return true;
}
@Override
public EnumFacing[] getEnergyShareSides(){
return EnumFacing.values();
}
} }

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; 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.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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_INPUT = 0;
public static final int SLOT_OUTPUT = 1; public static final int SLOT_OUTPUT = 1;

View file

@ -21,13 +21,14 @@ import net.darkhax.tesla.api.ITeslaConsumer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements IEnergyReceiver{ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements ICustomEnergyReceiver{
public final ConcurrentHashMap<EnumFacing, TileEntity> receiversAround = new ConcurrentHashMap<EnumFacing, TileEntity>(); public final ConcurrentHashMap<EnumFacing, TileEntity> receiversAround = new ConcurrentHashMap<EnumFacing, TileEntity>();
@ -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 //Keeps track of all the Laser Relays and Energy Acceptors that have been checked already to make nothing run multiple times
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>(); List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
List<TileEntityLaserRelayEnergy> relaysThatWork = new ArrayList<TileEntityLaserRelayEnergy>();
int totalReceiverAmount = 0;
for(ConnectionPair pair : network.connections){ for(ConnectionPair pair : network.connections){
for(BlockPos relay : pair.positions){ for(BlockPos relay : pair.positions){
if(relay != null && !alreadyChecked.contains(relay)){ if(relay != null && !alreadyChecked.contains(relay)){
@ -99,52 +103,65 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
TileEntity relayTile = this.worldObj.getTileEntity(relay); TileEntity relayTile = this.worldObj.getTileEntity(relay);
if(relayTile instanceof TileEntityLaserRelayEnergy){ if(relayTile instanceof TileEntityLaserRelayEnergy){
TileEntityLaserRelayEnergy theRelay = (TileEntityLaserRelayEnergy)relayTile; TileEntityLaserRelayEnergy theRelay = (TileEntityLaserRelayEnergy)relayTile;
double highestLoss = Math.max(theRelay.getLossPercentage(), this.getLossPercentage()); int amount = theRelay.receiversAround.size();
int lowestCap = Math.min(theRelay.getEnergyCap(), this.getEnergyCap()); if(amount > 0){
for(Map.Entry<EnumFacing, TileEntity> receiver : theRelay.receiversAround.entrySet()){ relaysThatWork.add(theRelay);
if(receiver != null){ totalReceiverAmount += amount;
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;
}
}
//If everything that could be transmitted was transmitted if(totalReceiverAmount > 0 && !relaysThatWork.isEmpty()){
if(transmitted >= maxTransfer){ int amountPer = maxTransfer/totalReceiverAmount;
return transmitted;
} for(TileEntityLaserRelayEnergy theRelay : relaysThatWork){
double highestLoss = Math.max(theRelay.getLossPercentage(), this.getLossPercentage());
int lowestCap = Math.min(theRelay.getEnergyCap(), this.getEnergyCap());
for(Map.Entry<EnumFacing, TileEntity> 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; return transmitted;
} }
private int calcDeduction(int theoreticalReceived, double highestLoss){ 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(){ public int getEnergyCap(){

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks; import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; 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.EnumFacing;
import net.minecraft.util.math.BlockPos; 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 NOT_MULTI = 0;
public static final int HAS_LAVA = 1; public static final int HAS_LAVA = 1;

View file

@ -23,7 +23,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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 RANGE = 7;
public static final int ENERGY_PRODUCED = 300; public static final int ENERGY_PRODUCED = 300;
@ -129,4 +129,19 @@ public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyPr
public boolean needsHoldShift(){ public boolean needsHoldShift(){
return false; return false;
} }
@Override
public int getEnergyToSplitShare(){
return this.storage.getEnergyStored();
}
@Override
public boolean doesShareEnergy(){
return true;
}
@Override
public EnumFacing[] getEnergyShareSides(){
return EnumFacing.values();
}
} }

View file

@ -11,7 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; 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.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill; import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
@ -33,7 +32,7 @@ import net.minecraftforge.oredict.OreDictionary;
import java.util.List; 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 ENERGY_USE_PER_BLOCK = 1500;
public static final int DEFAULT_RANGE = 2; public static final int DEFAULT_RANGE = 2;

View file

@ -22,7 +22,7 @@ import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; 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; public static final int ENERGY_PRODUCED = 76;
private static final int BURN_TIME = 100; private static final int BURN_TIME = 100;
@ -192,4 +192,34 @@ public class TileEntityOilGenerator extends TileEntityBase implements IEnergyPro
return null; 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();
}
} }

View file

@ -23,7 +23,7 @@ import net.darkhax.tesla.api.ITeslaProducer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements IEnergyReceiver, IEnergyProvider{ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ICustomEnergyReceiver, ISharingEnergyProvider{
public TileEntityPhantomEnergyface(){ public TileEntityPhantomEnergyface(){
super("energyface"); super("energyface");
@ -132,4 +132,19 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
} }
return false; return false;
} }
@Override
public int getEnergyToSplitShare(){
return Integer.MAX_VALUE;
}
@Override
public boolean doesShareEnergy(){
return true;
}
@Override
public EnumFacing[] getEnergyShareSides(){
return EnumFacing.values();
}
} }

View file

@ -13,13 +13,10 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom; import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler{
public TileEntityPhantomLiquiface(){ public TileEntityPhantomLiquiface(){
super("liquiface"); super("liquiface");
@ -88,4 +85,19 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements
} }
return null; return null;
} }
@Override
public int getFluidAmountToSplitShare(){
return Integer.MAX_VALUE;
}
@Override
public boolean doesShareFluid(){
return true;
}
@Override
public EnumFacing[] getFluidShareSides(){
return EnumFacing.values();
}
} }

View file

@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyContainerItem; import cofh.api.energy.IEnergyContainerItem;
import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil; import de.ellpeck.actuallyadditions.mod.util.compat.TeslaUtil;
import net.darkhax.tesla.api.ITeslaConsumer; import net.darkhax.tesla.api.ITeslaConsumer;
@ -24,7 +23,7 @@ import net.minecraft.util.EnumFacing;
import java.util.UUID; 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; public static final int DEFAULT_RANGE = 32;
private final EnergyStorage storage = new EnergyStorage(30000); private final EnergyStorage storage = new EnergyStorage(30000);

View file

@ -11,14 +11,13 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class TileEntityShockSuppressor extends TileEntityBase implements IEnergyReceiver, IEnergyDisplay{ public class TileEntityShockSuppressor extends TileEntityBase implements ICustomEnergyReceiver, IEnergyDisplay{
public static final List<TileEntityShockSuppressor> SUPPRESSORS = new ArrayList<TileEntityShockSuppressor>(); public static final List<TileEntityShockSuppressor> SUPPRESSORS = new ArrayList<TileEntityShockSuppressor>();

View file

@ -91,70 +91,51 @@ public final class WorldUtil{
return null; return null;
} }
public static void doEnergyInteraction(TileEntity tile){ public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
for(EnumFacing side : EnumFacing.values()){ TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
TileEntity otherTile = tile.getWorld().getTileEntity(tile.getPos().offset(side)); if(tileTo != null){
if(otherTile != null){ if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
IEnergyReceiver handlerTo = null; IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
IEnergyProvider handlerFrom = null; IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom;
//Push RF int drain = handlerFrom.extractEnergy(sideTo, maxTransfer, true);
if(tile instanceof IEnergyProvider && otherTile instanceof IEnergyReceiver){ if(drain > 0){
handlerTo = (IEnergyReceiver)otherTile; if(handlerTo.canConnectEnergy(sideTo.getOpposite())){
handlerFrom = (IEnergyProvider)tile; int filled = handlerTo.receiveEnergy(sideTo.getOpposite(), drain, false);
} handlerFrom.extractEnergy(sideTo, filled, false);
//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);
}
} }
} }
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){ public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
for(EnumFacing side : EnumFacing.values()){ TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
TileEntity otherTile = tile.getWorld().getTileEntity(tile.getPos().offset(side)); if(tileTo != null){
if(otherTile != null){ //Push and pull with old fluid system
for(int i = 0; i < 2; i++){ if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){
//Push and pull with old fluid system net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo;
if(tile instanceof net.minecraftforge.fluids.IFluidHandler && otherTile instanceof net.minecraftforge.fluids.IFluidHandler){ net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom;
net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)(i == 0 ? tile : otherTile); FluidStack drain = handlerFrom.drain(sideTo, maxTransfer, false);
net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)(i == 0 ? otherTile : tile); if(drain != null){
FluidStack drain = handlerFrom.drain(side, Integer.MAX_VALUE, false); if(handlerTo.canFill(sideTo.getOpposite(), drain.getFluid())){
if(drain != null){ int filled = handlerTo.fill(sideTo.getOpposite(), drain.copy(), true);
if(handlerTo.canFill(side.getOpposite(), drain.getFluid())){ handlerFrom.drain(sideTo, filled, true);
int filled = handlerTo.fill(side.getOpposite(), drain.copy(), true);
handlerFrom.drain(side, filled, true);
break;
}
}
} }
//Push and pull with new fluid system }
else{ }
IFluidHandler handlerFrom = (i == 0 ? tile : otherTile).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, i == 0 ? side : side.getOpposite()); //Push and pull with new fluid system
IFluidHandler handlerTo = (i == 0 ? otherTile : tile).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, i == 0 ? side.getOpposite() : side); else{
if(handlerFrom != null && handlerTo != null){ if(tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())){
FluidStack drain = handlerFrom.drain(Integer.MAX_VALUE, false); IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
if(drain != null){ IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
int filled = handlerTo.fill(drain.copy(), true); FluidStack drain = handlerFrom.drain(maxTransfer, false);
handlerFrom.drain(filled, true); if(drain != null){
break; int filled = handlerTo.fill(drain.copy(), true);
} handlerFrom.drain(filled, true);
}
} }
} }
} }

View file

@ -47,19 +47,12 @@ public final class TeslaUtil{
} }
} }
public static void doWrappedTeslaRFInteraction(TileEntity tile, TileEntity otherTile, EnumFacing side){ public static void doWrappedTeslaRFInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing side, int maxTransfer){
ITeslaConsumer handlerTo = null; if(tileTo.hasCapability(teslaConsumer, side.getOpposite()) && tileFrom.hasCapability(teslaProducer, side)){
ITeslaProducer handlerFrom = null; ITeslaConsumer handlerTo = tileTo.getCapability(teslaConsumer, side.getOpposite());
ITeslaProducer handlerFrom = tileFrom.getCapability(teslaProducer, side);
for(int i = 0; i < 2; i++){ long drain = handlerFrom.takePower(maxTransfer, true);
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);
if(drain > 0){ if(drain > 0){
long filled = handlerTo.givePower(drain, false); long filled = handlerTo.givePower(drain, false);
handlerFrom.takePower(filled, false); handlerFrom.takePower(filled, false);