mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Made every block be able to save the tile entities around it for future use
This commit is contained in:
parent
2fea0d3c6d
commit
37d1bc95f9
12 changed files with 102 additions and 96 deletions
|
@ -90,16 +90,6 @@ public class BlockInputter extends BlockContainerBase{
|
|||
return EnumRarity.EPIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
super.neighborsChangedCustom(world, pos);
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityInputter){
|
||||
((TileEntityInputter)tile).initVars();
|
||||
}
|
||||
}
|
||||
|
||||
public static class TheItemBlock extends ItemBlockBase{
|
||||
|
||||
private long lastSysTime;
|
||||
|
|
|
@ -30,17 +30,6 @@ public class BlockItemViewer extends BlockContainerBase{
|
|||
this.setSoundType(SoundType.STONE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
super.neighborsChangedCustom(world, pos);
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityItemViewer){
|
||||
((TileEntityItemViewer)tile).saveConnectedRelay();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta){
|
||||
return new TileEntityItemViewer();
|
||||
|
|
|
@ -112,16 +112,6 @@ public class BlockLaserRelay extends BlockContainerBase{
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
super.neighborsChangedCustom(world, pos);
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityLaserRelay){
|
||||
((TileEntityLaserRelay)tile).saveAllHandlersAround();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int i){
|
||||
switch(this.type){
|
||||
|
|
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.blocks.base;
|
|||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -156,6 +157,14 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
|
|||
|
||||
public void neighborsChangedCustom(World world, BlockPos pos){
|
||||
this.updateRedstoneState(world, pos);
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityBase){
|
||||
TileEntityBase base = (TileEntityBase)tile;
|
||||
if(base.shouldSaveHandlersAround()){
|
||||
base.saveAllHandlersAround();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,6 +42,9 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
|||
public boolean isPulseMode;
|
||||
protected int ticksElapsed;
|
||||
|
||||
protected TileEntity[] tilesAround = new TileEntity[6];
|
||||
protected boolean hasCheckedHandlersAround;
|
||||
|
||||
public TileEntityBase(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -236,8 +239,12 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
|||
if(amount <= 0){
|
||||
amount = total;
|
||||
}
|
||||
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doEnergyInteraction(this, side, amount);
|
||||
TileEntity tile = this.tilesAround[side.ordinal()];
|
||||
if(tile != null){
|
||||
WorldUtil.doEnergyInteraction(this, tile, side, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,15 +261,37 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
|||
if(amount <= 0){
|
||||
amount = total;
|
||||
}
|
||||
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doFluidInteraction(this, side, amount);
|
||||
TileEntity tile = this.tilesAround[side.ordinal()];
|
||||
if(tile != null){
|
||||
WorldUtil.doFluidInteraction(this, tile, side, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.hasCheckedHandlersAround){
|
||||
if(this.shouldSaveHandlersAround()){
|
||||
this.saveAllHandlersAround();
|
||||
}
|
||||
|
||||
this.hasCheckedHandlersAround = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAllHandlersAround(){
|
||||
for(EnumFacing side : EnumFacing.values()){
|
||||
this.tilesAround[side.ordinal()] = this.worldObj.getTileEntity(this.pos.offset(side));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldSaveHandlersAround(){
|
||||
return this instanceof ISharingEnergyProvider || this instanceof ISharingFluidHandler;
|
||||
}
|
||||
|
||||
public void setRedstonePowered(boolean powered){
|
||||
this.isRedstonePowered = powered;
|
||||
this.markDirty();
|
||||
|
|
|
@ -48,8 +48,6 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, 0, -1000);
|
||||
public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, 0, -2000);
|
||||
|
||||
private boolean hasCheckedTilesAround;
|
||||
|
||||
public TileEntityInputter(int slots, String name){
|
||||
super(slots, name);
|
||||
}
|
||||
|
@ -313,10 +311,16 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
return !this.isAdvanced || (output ? this.rightFilter : this.leftFilter).check(stack, this.slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSaveHandlersAround(){
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all of the relevant variables
|
||||
*/
|
||||
public void initVars(){
|
||||
@Override
|
||||
public void saveAllHandlersAround(){
|
||||
if(this.sideToPull != -1){
|
||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull);
|
||||
this.placeToPull = this.worldObj.getTileEntity(this.pos.offset(side));
|
||||
|
@ -399,7 +403,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
}
|
||||
|
||||
this.markDirty();
|
||||
this.initVars();
|
||||
this.saveAllHandlersAround();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -438,10 +442,6 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
|||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
if(!this.worldObj.isRemote){
|
||||
if(!this.hasCheckedTilesAround){
|
||||
this.initVars();
|
||||
this.hasCheckedTilesAround = true;
|
||||
}
|
||||
|
||||
//Is Block not powered by Redstone?
|
||||
if(!this.isRedstonePowered){
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.List;
|
|||
public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||
|
||||
public TileEntityLaserRelayItem connectedRelay;
|
||||
private boolean hasCheckedRelayOnLoad;
|
||||
|
||||
public TileEntityItemViewer(){
|
||||
super(0, "itemViewer");
|
||||
|
@ -35,11 +34,6 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
@Override
|
||||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
|
||||
if(!this.worldObj.isRemote && !this.hasCheckedRelayOnLoad){
|
||||
this.saveConnectedRelay();
|
||||
this.hasCheckedRelayOnLoad = true;
|
||||
}
|
||||
}
|
||||
|
||||
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
||||
|
@ -75,7 +69,13 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
return null;
|
||||
}
|
||||
|
||||
public void saveConnectedRelay(){
|
||||
@Override
|
||||
public boolean shouldSaveHandlersAround(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllHandlersAround(){
|
||||
TileEntityLaserRelayItem tileFound = null;
|
||||
if(this.worldObj != null){ //Why is that even possible..?
|
||||
for(int i = 0; i <= 5; i++){
|
||||
|
|
|
@ -42,8 +42,6 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
|
||||
private Set<ConnectionPair> tempConnectionStorage;
|
||||
|
||||
private boolean hasCheckedHandlersAround;
|
||||
|
||||
public TileEntityLaserRelay(String name, LaserType type){
|
||||
super(name);
|
||||
this.type = type;
|
||||
|
@ -90,14 +88,6 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
if(this.worldObj.isRemote){
|
||||
this.renderParticles();
|
||||
}
|
||||
else if(!this.hasCheckedHandlersAround){
|
||||
this.saveAllHandlersAround();
|
||||
this.hasCheckedHandlersAround = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAllHandlersAround(){
|
||||
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
|
|
@ -74,6 +74,11 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSaveHandlersAround(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllHandlersAround(){
|
||||
this.receiversAround.clear();
|
||||
|
|
|
@ -39,6 +39,11 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay implements
|
|||
super("laserRelayFluids", LaserType.FLUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSaveHandlersAround(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllHandlersAround(){
|
||||
this.receiversAround.clear();
|
||||
|
|
|
@ -43,6 +43,11 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSaveHandlersAround(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllHandlersAround(){
|
||||
this.handlersAround.clear();
|
||||
|
|
|
@ -88,55 +88,49 @@ public final class WorldUtil{
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||
public static void doEnergyInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer){
|
||||
if(maxTransfer > 0){
|
||||
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;
|
||||
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||
IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
|
||||
IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom;
|
||||
|
||||
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);
|
||||
}
|
||||
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(tileFrom, tileTo, sideTo, maxTransfer);
|
||||
}
|
||||
}
|
||||
else if(ActuallyAdditions.teslaLoaded){
|
||||
TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||
public static void doFluidInteraction(TileEntity tileFrom, TileEntity tileTo, EnumFacing sideTo, int maxTransfer){
|
||||
if(maxTransfer > 0){
|
||||
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 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{
|
||||
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);
|
||||
}
|
||||
}
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue