2015-05-20 22:39:43 +02:00
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
2015-05-29 18:17:28 +02:00
|
|
|
import cofh.api.energy.IEnergyHandler;
|
|
|
|
import cofh.api.energy.IEnergyProvider;
|
|
|
|
import cofh.api.energy.IEnergyReceiver;
|
2015-08-10 10:37:44 +02:00
|
|
|
import ellpeck.actuallyadditions.blocks.BlockPhantom;
|
2015-06-12 19:12:06 +02:00
|
|
|
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
2015-05-20 22:39:43 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-07-07 11:51:05 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldPos;
|
2015-05-29 18:17:28 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
2015-06-12 19:12:06 +02:00
|
|
|
import net.minecraft.block.Block;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
2015-05-27 21:57:53 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTankInfo;
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
public class TileEntityPhantomface extends TileEntityInventoryBase implements IPhantomTile{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-07-07 11:51:05 +02:00
|
|
|
public WorldPos boundPosition;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-08-10 22:55:34 +02:00
|
|
|
public BlockPhantom.Type type;
|
2015-05-27 21:57:53 +02:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
public final int defaultRange = ConfigIntValues.PHANTOMFACE_RANGE.getValue();
|
|
|
|
public int range;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-07-07 16:22:37 +02:00
|
|
|
private int rangeBefore;
|
|
|
|
private WorldPos boundPosBefore;
|
|
|
|
private Block boundBlockBefore;
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
public TileEntityPhantomface(String name){
|
|
|
|
super(0, name);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
public static int upgradeRange(int defaultRange, World world, int x, int y, int z){
|
|
|
|
int newRange = defaultRange;
|
|
|
|
for(int i = 0; i < 3; i++){
|
|
|
|
Block block = world.getBlock(x, y+1+i, z);
|
|
|
|
if(block == InitBlocks.blockPhantomBooster) newRange = newRange*2;
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
return newRange;
|
|
|
|
}
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
if(!worldObj.isRemote){
|
2015-06-12 19:12:06 +02:00
|
|
|
this.range = upgradeRange(defaultRange, worldObj, xCoord, yCoord, zCoord);
|
2015-05-27 21:57:53 +02:00
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
if(!this.hasBoundPosition()){
|
2015-06-12 19:12:06 +02:00
|
|
|
this.boundPosition = null;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
2015-07-07 16:22:37 +02:00
|
|
|
|
2015-08-11 00:39:57 +02:00
|
|
|
if(this.boundPosition != this.boundPosBefore || (this.boundPosition != null && this.boundPosition.getBlock() != this.boundBlockBefore) || this.rangeBefore != this.range){
|
2015-07-07 16:22:37 +02:00
|
|
|
this.rangeBefore = this.range;
|
|
|
|
this.boundPosBefore = this.boundPosition;
|
|
|
|
this.boundBlockBefore = this.boundPosition == null ? null : this.boundPosition.getBlock();
|
|
|
|
WorldUtil.updateTileAndTilesAround(this);
|
|
|
|
}
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound compound){
|
|
|
|
super.writeToNBT(compound);
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.hasBoundPosition()){
|
2015-07-07 11:51:05 +02:00
|
|
|
compound.setInteger("XCoordOfTileStored", boundPosition.getX());
|
|
|
|
compound.setInteger("YCoordOfTileStored", boundPosition.getY());
|
|
|
|
compound.setInteger("ZCoordOfTileStored", boundPosition.getZ());
|
|
|
|
compound.setInteger("WorldOfTileStored", boundPosition.getWorld().provider.dimensionId);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
super.readFromNBT(compound);
|
2015-06-12 19:12:06 +02:00
|
|
|
int x = compound.getInteger("XCoordOfTileStored");
|
|
|
|
int y = compound.getInteger("YCoordOfTileStored");
|
|
|
|
int z = compound.getInteger("ZCoordOfTileStored");
|
2015-07-07 11:51:05 +02:00
|
|
|
World world = DimensionManager.getWorld(compound.getInteger("WorldOfTileStored"));
|
|
|
|
if(x != 0 && y != 0 && z != 0 && world != null){
|
|
|
|
this.boundPosition = new WorldPos(world, x, y, z);
|
2015-06-12 19:12:06 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-27 21:57:53 +02:00
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
|
|
|
return false;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-27 21:57:53 +02:00
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
2015-05-20 22:39:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-10 10:37:44 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasBoundPosition(){
|
|
|
|
if(this.boundPosition != null && this.boundPosition.getWorld() != null){
|
|
|
|
if(this.boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) instanceof IPhantomTile || (this.xCoord == this.boundPosition.getX() && this.yCoord == this.boundPosition.getY() && this.zCoord == this.boundPosition.getZ() && this.worldObj == this.boundPosition.getWorld())){
|
|
|
|
this.boundPosition = null;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.boundPosition.getWorld() == this.worldObj;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBoundThingInRange(){
|
|
|
|
if(this.hasBoundPosition()){
|
|
|
|
int xDif = this.boundPosition.getX()-this.xCoord;
|
|
|
|
int yDif = this.boundPosition.getY()-this.yCoord;
|
|
|
|
int zDif = this.boundPosition.getZ()-this.zCoord;
|
|
|
|
|
|
|
|
if(xDif >= -this.range && xDif <= this.range){
|
|
|
|
if(yDif >= -this.range && yDif <= this.range){
|
|
|
|
if(zDif >= -this.range && zDif <= this.range){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WorldPos getBoundPosition(){
|
|
|
|
return this.boundPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getGuiID(){
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRange(){
|
|
|
|
return this.range;
|
|
|
|
}
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
public static class TileEntityPhantomLiquiface extends TileEntityPhantomface implements IFluidHandler{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
public TileEntityPhantomLiquiface(){
|
|
|
|
super("liquiface");
|
2015-08-10 22:55:34 +02:00
|
|
|
this.type = BlockPhantom.Type.LIQUIFACE;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-05-29 18:17:28 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
|
|
|
|
if(!worldObj.isRemote){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) && this.isBoundThingInRange() && this.getHandler() != null){
|
2015-05-29 18:17:28 +02:00
|
|
|
this.pushFluid(ForgeDirection.UP);
|
|
|
|
this.pushFluid(ForgeDirection.DOWN);
|
|
|
|
this.pushFluid(ForgeDirection.NORTH);
|
|
|
|
this.pushFluid(ForgeDirection.EAST);
|
|
|
|
this.pushFluid(ForgeDirection.SOUTH);
|
|
|
|
this.pushFluid(ForgeDirection.WEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pushFluid(ForgeDirection side){
|
|
|
|
TileEntity tile = WorldUtil.getTileEntityFromSide(side, worldObj, xCoord, yCoord, zCoord);
|
2015-06-18 13:14:57 +02:00
|
|
|
if(tile != null && tile instanceof IFluidHandler && this.getTankInfo(side) != null && this.getTankInfo(side).length > 0 && ((IFluidHandler)tile).getTankInfo(side.getOpposite()) != null && ((IFluidHandler)tile).getTankInfo(side.getOpposite()).length > 0){
|
2015-05-29 18:17:28 +02:00
|
|
|
for(FluidTankInfo myInfo : this.getTankInfo(side)){
|
|
|
|
for(FluidTankInfo hisInfo : ((IFluidHandler)tile).getTankInfo(side.getOpposite())){
|
2015-05-30 17:47:57 +02:00
|
|
|
if(myInfo != null && hisInfo != null && myInfo.fluid != null && myInfo.fluid.getFluid() != null){
|
2015-05-29 18:17:28 +02:00
|
|
|
if(((IFluidHandler)tile).canFill(side.getOpposite(), myInfo.fluid.getFluid()) && this.canDrain(side, myInfo.fluid.getFluid())){
|
|
|
|
FluidStack receive = this.drain(side, Math.min(hisInfo.capacity-(hisInfo.fluid == null ? 0 : hisInfo.fluid.amount), myInfo.fluid.amount), false);
|
2015-05-30 17:47:57 +02:00
|
|
|
if(receive != null){
|
|
|
|
int actualReceive = ((IFluidHandler)tile).fill(side.getOpposite(), receive, true);
|
|
|
|
this.drain(side, new FluidStack(receive.getFluid(), actualReceive), true);
|
|
|
|
}
|
2015-05-29 18:17:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
@Override
|
2015-08-10 10:37:44 +02:00
|
|
|
public boolean isBoundThingInRange(){
|
|
|
|
return super.isBoundThingInRange() && this.boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) instanceof IFluidHandler;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
public IFluidHandler getHandler(){
|
2015-07-07 11:51:05 +02:00
|
|
|
if(this.boundPosition != null && this.boundPosition.getWorld() != null){
|
|
|
|
TileEntity tile = boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
|
2015-06-12 19:12:06 +02:00
|
|
|
if(tile instanceof IFluidHandler) return (IFluidHandler)tile;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
@Override
|
|
|
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()) return this.getHandler().fill(from, resource, doFill);
|
2015-05-27 21:57:53 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()) return this.getHandler().drain(from, resource, doDrain);
|
2015-05-27 21:57:53 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()) return this.getHandler().drain(from, maxDrain, doDrain);
|
2015-05-27 21:57:53 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(ForgeDirection from, Fluid fluid){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() && this.getHandler().canFill(from, fluid);
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(ForgeDirection from, Fluid fluid){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() && this.getHandler().canDrain(from, fluid);
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(ForgeDirection from){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()) return this.getHandler().getTankInfo(from);
|
2015-05-27 21:57:53 +02:00
|
|
|
return new FluidTankInfo[0];
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-05-29 18:17:28 +02:00
|
|
|
public static class TileEntityPhantomEnergyface extends TileEntityPhantomface implements IEnergyHandler{
|
|
|
|
|
|
|
|
public TileEntityPhantomEnergyface(){
|
|
|
|
super("energyface");
|
2015-08-10 22:55:34 +02:00
|
|
|
this.type = BlockPhantom.Type.ENERGYFACE;
|
2015-05-29 18:17:28 +02:00
|
|
|
}
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
@Override
|
2015-08-10 10:37:44 +02:00
|
|
|
public boolean isBoundThingInRange(){
|
|
|
|
return super.isBoundThingInRange() && (this.boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) instanceof IEnergyReceiver || this.boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) instanceof IEnergyProvider);
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
2015-05-29 18:17:28 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
|
|
|
|
if(!worldObj.isRemote){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange() && this.getProvider() != null){
|
2015-05-29 18:17:28 +02:00
|
|
|
this.pushEnergy(ForgeDirection.UP);
|
|
|
|
this.pushEnergy(ForgeDirection.DOWN);
|
|
|
|
this.pushEnergy(ForgeDirection.NORTH);
|
|
|
|
this.pushEnergy(ForgeDirection.EAST);
|
|
|
|
this.pushEnergy(ForgeDirection.SOUTH);
|
|
|
|
this.pushEnergy(ForgeDirection.WEST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pushEnergy(ForgeDirection side){
|
|
|
|
TileEntity tile = WorldUtil.getTileEntityFromSide(side, worldObj, xCoord, yCoord, zCoord);
|
|
|
|
if(tile != null && tile instanceof IEnergyReceiver && this.getProvider().getEnergyStored(ForgeDirection.UNKNOWN) > 0){
|
|
|
|
if(((IEnergyReceiver)tile).canConnectEnergy(side.getOpposite()) && this.canConnectEnergy(side)){
|
|
|
|
int receive = this.extractEnergy(side, Math.min(((IEnergyReceiver)tile).getMaxEnergyStored(ForgeDirection.UNKNOWN)-((IEnergyReceiver)tile).getEnergyStored(ForgeDirection.UNKNOWN), this.getEnergyStored(ForgeDirection.UNKNOWN)), true);
|
|
|
|
int actualReceive = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), receive, false);
|
|
|
|
this.extractEnergy(side, actualReceive, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnergyProvider getProvider(){
|
2015-07-07 11:51:05 +02:00
|
|
|
if(this.boundPosition != null && this.boundPosition.getWorld() != null){
|
|
|
|
TileEntity tile = boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
|
2015-06-12 19:12:06 +02:00
|
|
|
if(tile instanceof IEnergyProvider) return (IEnergyProvider)tile;
|
2015-05-29 18:17:28 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnergyReceiver getReceiver(){
|
2015-07-07 11:51:05 +02:00
|
|
|
if(this.boundPosition != null && this.boundPosition.getWorld() != null){
|
|
|
|
TileEntity tile = boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
|
2015-06-12 19:12:06 +02:00
|
|
|
if(tile instanceof IEnergyReceiver) return (IEnergyReceiver)tile;
|
2015-05-29 18:17:28 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() && this.getReceiver() != null ? this.getReceiver().receiveEnergy(from, maxReceive, simulate) : 0;
|
2015-05-29 18:17:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() && this.getProvider() != null ? this.getProvider().extractEnergy(from, maxExtract, simulate) : 0;
|
2015-05-29 18:17:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergyStored(ForgeDirection from){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
2015-05-29 18:17:28 +02:00
|
|
|
if(this.getProvider() != null) return this.getProvider().getEnergyStored(from);
|
|
|
|
if(this.getReceiver() != null) return this.getReceiver().getEnergyStored(from);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxEnergyStored(ForgeDirection from){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
2015-05-29 18:17:28 +02:00
|
|
|
if(this.getProvider() != null) return this.getProvider().getMaxEnergyStored(from);
|
|
|
|
if(this.getReceiver() != null) return this.getReceiver().getMaxEnergyStored(from);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canConnectEnergy(ForgeDirection from){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
2015-05-29 18:17:28 +02:00
|
|
|
if(this.getProvider() != null) return this.getProvider().canConnectEnergy(from);
|
|
|
|
if(this.getReceiver() != null) return this.getReceiver().canConnectEnergy(from);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
public static class TileEntityPhantomItemface extends TileEntityPhantomface{
|
|
|
|
|
|
|
|
public TileEntityPhantomItemface(){
|
|
|
|
super("phantomface");
|
2015-08-10 22:55:34 +02:00
|
|
|
this.type = BlockPhantom.Type.FACE;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public IInventory getInventory(){
|
2015-07-07 11:51:05 +02:00
|
|
|
if(this.boundPosition != null && this.boundPosition.getWorld() != null){
|
|
|
|
TileEntity tile = boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ());
|
2015-06-12 19:12:06 +02:00
|
|
|
if(tile instanceof IInventory) return (IInventory)tile;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2015-05-27 21:57:53 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
@Override
|
2015-08-10 10:37:44 +02:00
|
|
|
public boolean isBoundThingInRange(){
|
|
|
|
return super.isBoundThingInRange() && this.boundPosition.getWorld().getTileEntity(boundPosition.getX(), boundPosition.getY(), boundPosition.getZ()) instanceof IInventory;
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
public ISidedInventory getSided(){
|
|
|
|
return this.getInventory() instanceof ISidedInventory ? (ISidedInventory)this.getInventory() : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit(){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() ? this.getInventory().getInventoryStackLimit() : 0;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() && this.getInventory().isItemValidForSlot(i, stack);
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlotOnClosing(int i){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() ? this.getInventory().getStackInSlotOnClosing(i) : null;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int i, ItemStack stack){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()) this.getInventory().setInventorySlotContents(i, stack);
|
2015-05-27 21:57:53 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory(){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() ? this.getInventory().getSizeInventory() : 0;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int i){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() ? this.getInventory().getStackInSlot(i) : null;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int i, int j){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() ? this.getInventory().decrStackSize(i, j) : null;
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getInventoryName(){
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getAccessibleSlotsFromSide(int side){
|
2015-08-10 10:37:44 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
2015-05-27 21:57:53 +02:00
|
|
|
if(this.getSided() != null){
|
|
|
|
return this.getSided().getAccessibleSlotsFromSide(side);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
int[] theInt = new int[this.getSizeInventory()];
|
|
|
|
for(int i = 0; i < theInt.length; i++){
|
|
|
|
theInt[i] = i;
|
|
|
|
}
|
|
|
|
return theInt;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-27 21:57:53 +02:00
|
|
|
return new int[0];
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-05-27 21:57:53 +02:00
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canInsertItem(slot, stack, side));
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
2015-08-10 10:37:44 +02:00
|
|
|
return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canExtractItem(slot, stack, side));
|
2015-05-27 21:57:53 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|