Make fluid lasers actively pull fluids

Closes #564
This commit is contained in:
Ellpeck 2017-01-14 00:14:26 +01:00
parent 9c07287261
commit 3d6273ac38
2 changed files with 23 additions and 9 deletions

View file

@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergy.Mode;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -36,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
public final ConcurrentHashMap<EnumFacing, TileEntity> receiversAround = new ConcurrentHashMap<EnumFacing, TileEntity>();
public final ConcurrentHashMap<EnumFacing, TileEntity> handlersAround = new ConcurrentHashMap<EnumFacing, TileEntity>();
private final IFluidHandler[] fluidHandlers = new IFluidHandler[6];
private Mode mode = Mode.BOTH;
@ -69,6 +70,19 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
}
}
@Override
public void updateEntity(){
super.updateEntity();
if(!this.world.isRemote){
if(this.mode == Mode.INPUT_ONLY){
for(EnumFacing side : this.handlersAround.keySet()){
WorldUtil.doFluidInteraction(this.handlersAround.get(side), this, side.getOpposite(), Integer.MAX_VALUE);
}
}
}
}
@Override
public boolean shouldSaveDataOnChangeOrWorldStart(){
return true;
@ -76,16 +90,16 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
@Override
public void saveDataOnChangeOrWorldStart(){
Map<EnumFacing, TileEntity> old = new HashMap<EnumFacing, TileEntity>(this.receiversAround);
Map<EnumFacing, TileEntity> old = new HashMap<EnumFacing, TileEntity>(this.handlersAround);
boolean change = false;
this.receiversAround.clear();
this.handlersAround.clear();
for(EnumFacing side : EnumFacing.values()){
BlockPos pos = this.getPos().offset(side);
TileEntity tile = this.world.getTileEntity(pos);
if(tile != null && !(tile instanceof TileEntityLaserRelay)){
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){
this.receiversAround.put(side, tile);
this.handlersAround.put(side, tile);
TileEntity oldTile = old.get(side);
if(oldTile == null || !tile.equals(oldTile)){
@ -95,7 +109,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
}
}
if(change || old.size() != this.receiversAround.size()){
if(change || old.size() != this.handlersAround.size()){
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
if(network != null){
network.changeAmount++;
@ -137,9 +151,9 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
if(theRelay.mode != Mode.INPUT_ONLY){
boolean workedOnce = false;
for(EnumFacing facing : theRelay.receiversAround.keySet()){
for(EnumFacing facing : theRelay.handlersAround.keySet()){
if(theRelay != this || facing != from){
TileEntity tile = theRelay.receiversAround.get(facing);
TileEntity tile = theRelay.handlersAround.get(facing);
EnumFacing opp = facing.getOpposite();
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opp)){
@ -168,7 +182,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
}
for(TileEntityLaserRelayFluids theRelay : relaysThatWork){
for(Map.Entry<EnumFacing, TileEntity> receiver : theRelay.receiversAround.entrySet()){
for(Map.Entry<EnumFacing, TileEntity> receiver : theRelay.handlersAround.entrySet()){
if(receiver != null){
EnumFacing side = receiver.getKey();
EnumFacing opp = side.getOpposite();

View file

@ -1084,7 +1084,7 @@ booklet.actuallyadditions.chapter.empowerer.text.3=<n><n><n><i>Because every mod
booklet.actuallyadditions.chapter.empowerer.text.4=The <item>Display Stand<r> can also be used for other things! See the <imp>Blocks that use CF<r> section for more info about it!
booklet.actuallyadditions.chapter.fluidLaser.name=Fluid Laser Relays
booklet.actuallyadditions.chapter.fluidLaser.text.1=The <item>Fluid Laser Relays<r> work much in the same way that normal <item>Laser Relays<r> do, however the thing that makes the <item>Fluid Laser Relay<r> different from the <item>Energy Laser Relay<r>, however, is that it transfers <imp>fluids<r> from internal tanks of blocks into other blocks. <n><n><item>Fluid Laser Relays<r> can not be connected by Phantomfaces.
booklet.actuallyadditions.chapter.fluidLaser.text.1=The <item>Fluid Laser Relays<r> work much in the same way that normal <item>Laser Relays<r> do, however the thing that makes the <item>Fluid Laser Relay<r> different from the <item>Energy Laser Relay<r>, however, is that it transfers <imp>fluids<r> from internal tanks of blocks into other blocks. <n><n><item>Fluid Laser Relays<r> can not be connected by Phantomfaces. <n><n>Note that when they are toggled to <imp>Only out of adjacent Blocks<r> mode, they will <imp>actively pull<r> fluids out of containers around them.
booklet.actuallyadditions.chapter.distributorItem.name=Item Distributor
booklet.actuallyadditions.chapter.distributorItem.text.1=The <item>Item Distributor<r> is a simple way to split up items and make them go <imp>in different directions<r>. <n><n>The distributor will <imp>pull items into it from the top<r> by itself, and then split them up and <imp>put them<r> out into inventories connected to all of the <imp>other sides<r> of it. <n>It tries to do split the items <imp>equally<r>, however this works best when inputting <imp>one item at a time<r>, which its pulling feature does automatically.