2015-10-10 02:58:07 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityPhantomItemface.java") is part of the Actually Additions mod for Minecraft.
|
2015-10-10 02:58:07 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-10-10 02:58:07 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-10-10 02:58:07 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-10-10 02:58:07 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom;
|
2015-10-10 02:58:07 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-01-08 08:10:55 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-05-05 13:43:57 +02:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
2015-10-10 02:58:07 +02:00
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2015-10-10 02:58:07 +02:00
|
|
|
public class TileEntityPhantomItemface extends TileEntityPhantomface{
|
|
|
|
|
|
|
|
public TileEntityPhantomItemface(){
|
|
|
|
super("phantomface");
|
|
|
|
this.type = BlockPhantom.Type.FACE;
|
|
|
|
}
|
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
@Nonnull
|
2015-10-10 02:58:07 +02:00
|
|
|
@Override
|
2016-05-19 20:05:12 +02:00
|
|
|
public int[] getSlotsForFace(@Nonnull EnumFacing side){
|
2015-10-10 02:58:07 +02:00
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
if(this.getSided() != null){
|
2016-01-08 08:10:55 +01:00
|
|
|
return this.getSided().getSlotsForFace(side);
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
int[] theInt = new int[this.getSizeInventory()];
|
|
|
|
for(int i = 0; i < theInt.length; i++){
|
|
|
|
theInt[i] = i;
|
|
|
|
}
|
|
|
|
return theInt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new int[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit(){
|
|
|
|
return this.isBoundThingInRange() ? this.getInventory().getInventoryStackLimit() : 0;
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
public void clear(){
|
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
this.getInventory().clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-10 02:58:07 +02:00
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int i, ItemStack stack){
|
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
this.getInventory().setInventorySlotContents(i, stack);
|
|
|
|
}
|
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory(){
|
|
|
|
return this.isBoundThingInRange() ? this.getInventory().getSizeInventory() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int i){
|
|
|
|
return this.isBoundThingInRange() ? this.getInventory().getStackInSlot(i) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int i, int j){
|
|
|
|
return this.isBoundThingInRange() ? this.getInventory().decrStackSize(i, j) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-02-01 17:49:55 +01:00
|
|
|
public ItemStack removeStackFromSlot(int index){
|
|
|
|
if(this.isBoundThingInRange()){
|
|
|
|
return this.getInventory().removeStackFromSlot(index);
|
|
|
|
}
|
|
|
|
return null;
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|
|
|
|
|
2015-10-12 23:27:36 +02:00
|
|
|
public ISidedInventory getSided(){
|
|
|
|
return this.getInventory() instanceof ISidedInventory ? (ISidedInventory)this.getInventory() : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IInventory getInventory(){
|
2015-12-23 01:43:49 +01:00
|
|
|
if(this.boundPosition != null){
|
2016-05-02 17:46:53 +02:00
|
|
|
TileEntity tile = this.worldObj.getTileEntity(this.boundPosition);
|
2015-10-12 23:27:36 +02:00
|
|
|
if(tile instanceof IInventory){
|
|
|
|
return (IInventory)tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2016-05-19 20:05:12 +02:00
|
|
|
public boolean isItemValidForSlot(int i, @Nonnull ItemStack stack){
|
2016-02-01 20:32:49 +01:00
|
|
|
return this.isBoundThingInRange() && this.getInventory().isItemValidForSlot(i, stack);
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
public boolean isBoundThingInRange(){
|
2016-05-05 13:43:57 +02:00
|
|
|
return super.isBoundThingInRange() && this.getInventory() != null;
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-19 20:05:12 +02:00
|
|
|
public boolean canInsertItem(int slot, @Nonnull ItemStack stack, @Nonnull EnumFacing side){
|
2016-02-01 17:49:55 +01:00
|
|
|
return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canInsertItem(slot, stack, side));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-19 20:05:12 +02:00
|
|
|
public boolean canExtractItem(int slot, @Nonnull ItemStack stack, @Nonnull EnumFacing side){
|
2016-02-01 17:49:55 +01:00
|
|
|
return this.isBoundThingInRange() && (this.getSided() == null || this.getSided().canExtractItem(slot, stack, side));
|
|
|
|
}
|
2016-05-05 13:43:57 +02:00
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
@Nonnull
|
2016-05-05 13:43:57 +02:00
|
|
|
@Override
|
2016-05-19 20:05:12 +02:00
|
|
|
public <T> T getCapability(@Nonnull Capability<T> capability, @Nonnull EnumFacing facing){
|
2016-05-05 13:43:57 +02:00
|
|
|
return this.isBoundThingInRange() ? this.worldObj.getTileEntity(this.boundPosition).getCapability(capability, facing) : super.getCapability(capability, facing);
|
|
|
|
}
|
2015-10-10 02:58:07 +02:00
|
|
|
}
|