Some bounding block inventory management
This commit is contained in:
parent
68f3d28119
commit
1c674f4317
7 changed files with 323 additions and 32 deletions
common/mekanism
resources/assets/mekanism/render
|
@ -11,8 +11,13 @@ import mekanism.api.Object3D;
|
|||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import mekanism.api.energy.IStrictEnergyStorage;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAdvancedBoundingBlock extends IBoundingBlock, ISidedInventory, IEnergySink, IStrictEnergyAcceptor, IPowerReceptor, IEnergyTile, IElectrical, IElectricalStorage, IConnector, IStrictEnergyStorage, IEnergyHandler
|
||||
{
|
||||
public int[] getBoundSlots(Object3D location, int slotID);
|
||||
|
||||
public boolean canBoundInsert(Object3D location, int i, ItemStack itemstack);
|
||||
|
||||
public boolean canBoundExtract(Object3D location, int i, ItemStack itemstack, int j);
|
||||
}
|
||||
|
|
|
@ -26,246 +26,446 @@ public class TileEntityAdvancedBoundingBlock extends TileEntityBoundingBlock imp
|
|||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().decrStackSize(i, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().getStackInSlotOnClosing(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getInv().setInventorySlotContents(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInvName()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().getInvName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvNameLocalized()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().isInvNameLocalized();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().isUseableByPlayer(entityplayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getInv().openChest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getInv().closeChest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return getInv().isItemValidForSlot(i, itemstack);
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().canBoundInsert(Object3D.get(this), i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int slotID)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().getBoundSlots(Object3D.get(this), slotID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return getInv().canInsertItem(i, itemstack, j);
|
||||
return isItemValidForSlot(i, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return getInv().canExtractItem(i, itemstack, j);
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().canBoundExtract(Object3D.get(this), i, itemstack, j);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().acceptsEnergyFrom(emitter, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().receiveEnergy(from, maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().extractEnergy(from, maxExtract, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInterface(ForgeDirection from)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().canInterface(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getMaxEnergyStored(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergy()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getEnergy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(double energy)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getInv().setEnergy(energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxEnergy()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getMaxEnergy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().canConnect(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergyStored(float energy)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getInv().setEnergyStored(energy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().receiveElectricity(from, receive, doReceive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().provideElectricity(from, request, doProvide);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRequest(ForgeDirection direction)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getRequest(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProvide(ForgeDirection direction)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getProvide(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVoltage()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getVoltage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().getPowerReceiver(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
getInv().doWork(workProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInv().getWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double transferEnergyToAcceptor(double amount)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
return getInv().transferEnergyToAcceptor(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveEnergy(ForgeDirection side)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return getInv().canReceiveEnergy(side);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().demandedEnergyUnits();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
return getInv().injectEnergyUnits(directionFrom, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
if(getInv() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return getInv().getMaxSafeInput();
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ public class TileEntityBoundingBlock extends TileEntity implements ITileNetwork
|
|||
data.add(mainX);
|
||||
data.add(mainY);
|
||||
data.add(mainZ);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,10 @@ import mekanism.common.miner.ThreadMinerSearch;
|
|||
import mekanism.common.miner.ThreadMinerSearch.State;
|
||||
import mekanism.common.network.PacketTileEntity;
|
||||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MinerUtils;
|
||||
import mekanism.common.util.TransporterUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -103,6 +105,23 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
{
|
||||
ChargeUtils.discharge(27, this);
|
||||
|
||||
if(doEject && getTopEject(false, null) != null && getEjectInv() != null)
|
||||
{
|
||||
if(getEjectInv() instanceof IInventory)
|
||||
{
|
||||
ItemStack remains = InventoryUtils.putStackInInventory((IInventory)getEjectInv(), getTopEject(false, null), ForgeDirection.getOrientation(facing).getOpposite().ordinal(), false);
|
||||
|
||||
getTopEject(true, remains);
|
||||
}
|
||||
else if(getEjectInv() instanceof TileEntityLogisticalTransporter)
|
||||
{
|
||||
if(TransporterUtils.insert(getEjectTile(), (TileEntityLogisticalTransporter)getEjectInv(), getTopEject(false, null), null))
|
||||
{
|
||||
getTopEject(true, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(running && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_USAGE) && searcher.state == State.FINISHED && oresToMine.size() > 0)
|
||||
{
|
||||
if(delay > 0)
|
||||
|
@ -238,26 +257,29 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
public boolean shouldOutput()
|
||||
public ItemStack getTopEject(boolean remove, ItemStack reject)
|
||||
{
|
||||
for(int i = 0; i < 27; i++)
|
||||
for(int i = 27-1; i >= 0; i--)
|
||||
{
|
||||
ItemStack stack = inventory[i];
|
||||
|
||||
if(stack == null)
|
||||
if(stack != null)
|
||||
{
|
||||
continue;
|
||||
if(replaceStack != null && replaceStack.isItemEqual(stack))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(remove)
|
||||
{
|
||||
inventory[i] = reject;
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
if(replaceStack != null && stack.isItemEqual(replaceStack))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canInsert(List<ItemStack> stacks)
|
||||
|
@ -306,9 +328,11 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
return null;
|
||||
}
|
||||
|
||||
public IInventory getEjectInv()
|
||||
public TileEntity getEjectInv()
|
||||
{
|
||||
return null;
|
||||
ForgeDirection side = ForgeDirection.getOrientation(facing).getOpposite();
|
||||
|
||||
return (TileEntity)new Object3D(xCoord+(side.offsetX*2), yCoord+1, zCoord+(side.offsetZ*2), worldObj.provider.dimensionId).getTileEntity(worldObj);
|
||||
}
|
||||
|
||||
public void add(List<ItemStack> stacks)
|
||||
|
@ -893,15 +917,22 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public TileEntity getEjectTile()
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(facing).getOpposite();
|
||||
return new Object3D(xCoord+side.offsetX, yCoord+1, zCoord+side.offsetZ, worldObj.provider.dimensionId).getTileEntity(worldObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getBoundSlots(Object3D location, int slotID)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(facing).getOpposite();
|
||||
|
||||
Object3D obj = new Object3D(xCoord+side.offsetX, yCoord+1, zCoord+side.offsetZ, worldObj.provider.dimensionId);
|
||||
Object3D eject = new Object3D(xCoord+side.offsetX, yCoord+1, zCoord+side.offsetZ, worldObj.provider.dimensionId);
|
||||
Object3D pull = new Object3D(xCoord, yCoord+1, zCoord);
|
||||
|
||||
if(location.equals(obj))
|
||||
if(location.equals(eject) || location.equals(pull))
|
||||
{
|
||||
int[] ret = new int[27];
|
||||
|
||||
|
@ -915,4 +946,52 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBoundInsert(Object3D location, int i, ItemStack itemstack)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(facing).getOpposite();
|
||||
|
||||
Object3D eject = new Object3D(xCoord+side.offsetX, yCoord+1, zCoord+side.offsetZ, worldObj.provider.dimensionId);
|
||||
Object3D pull = new Object3D(xCoord, yCoord+1, zCoord);
|
||||
|
||||
if(location.equals(eject))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if(location.equals(pull))
|
||||
{
|
||||
if(itemstack != null && replaceStack != null && itemstack.isItemEqual(replaceStack))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBoundExtract(Object3D location, int i, ItemStack itemstack, int j)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(facing).getOpposite();
|
||||
|
||||
Object3D eject = new Object3D(xCoord+side.offsetX, yCoord+1, zCoord+side.offsetZ, worldObj.provider.dimensionId);
|
||||
Object3D pull = new Object3D(xCoord, yCoord+1, zCoord);
|
||||
|
||||
if(location.equals(eject))
|
||||
{
|
||||
if(itemstack != null && replaceStack != null && itemstack.isItemEqual(replaceStack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(location.equals(pull))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,21 +112,27 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt
|
|||
|
||||
if(stack.getItemDamage() == GeneratorType.ADVANCED_SOLAR_GENERATOR.meta)
|
||||
{
|
||||
if(!Block.blocksList[world.getBlockId(x, y, z)].isBlockReplaceable(world, x, y, z) && world.getBlockId(x, y, z) != 0)
|
||||
place = false;
|
||||
|
||||
if(world.getBlockId(x, y, z) != 0)
|
||||
{
|
||||
if(Block.blocksList[world.getBlockId(x, y, z)].isBlockReplaceable(world, x, y, z))
|
||||
place = true;
|
||||
}
|
||||
|
||||
for(int xPos=-1;xPos<=1;xPos++)
|
||||
if(Block.blocksList[world.getBlockId(x, y, z)] == null)
|
||||
place = false;
|
||||
|
||||
if(place == true)
|
||||
{
|
||||
for(int zPos=-1;zPos<=1;zPos++)
|
||||
if(!Block.blocksList[world.getBlockId(x, y, z)].isBlockReplaceable(world, x, y, z) && world.getBlockId(x, y, z) != 0)
|
||||
place = false;
|
||||
|
||||
if(world.getBlockId(x, y, z) != 0)
|
||||
{
|
||||
if(Block.blocksList[world.getBlockId(x, y, z)].isBlockReplaceable(world, x, y, z))
|
||||
place = true;
|
||||
}
|
||||
|
||||
for(int xPos=-1;xPos<=1;xPos++)
|
||||
{
|
||||
if(world.getBlockId(x+xPos, y+2, z+zPos) != 0 || y+2 > 255)
|
||||
place = false;
|
||||
for(int zPos=-1;zPos<=1;zPos++)
|
||||
{
|
||||
if(world.getBlockId(x+xPos, y+2, z+zPos) != 0 || y+2 > 255)
|
||||
place = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before ![]() (image error) Size: 17 KiB After ![]() (image error) Size: 33 KiB ![]() ![]() |
Binary file not shown.
Before ![]() (image error) Size: 17 KiB After ![]() (image error) Size: 33 KiB ![]() ![]() |
Loading…
Add table
Reference in a new issue