blob: 354576947bf4bb7d313b0fae83148eb3e33c12ed [file] [log] [blame] [raw]
package net.glowstone.block.state;
import net.glowstone.block.GlowBlock;
import net.glowstone.block.GlowBlockState;
import net.glowstone.block.ItemTable;
import net.glowstone.block.blocktype.BlockChest;
import net.glowstone.block.entity.TEChest;
import net.glowstone.inventory.GlowDoubleChestInventory;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class GlowChest extends GlowBlockState implements Chest {
public GlowChest(GlowBlock block) {
super(block);
}
private TEChest getTileEntity() {
return (TEChest) getBlock().getTileEntity();
}
@Override
public Inventory getBlockInventory() {
return getTileEntity().getInventory();
}
@Override
public Inventory getInventory() {
GlowBlock me = getBlock();
BlockChest blockChest = (BlockChest) ItemTable.instance().getBlock(me.getType());
BlockFace attachedChest = blockChest.getAttachedChest(me);
if (attachedChest != null) {
Block nearbyBlock = me.getRelative(attachedChest);
GlowChest nearbyChest = (GlowChest) nearbyBlock.getState();
return new GlowDoubleChestInventory(this, nearbyChest);
}
return getBlockInventory();
}
@Override
public boolean update(boolean force, boolean applyPhysics) {
ItemStack[] contents = getBlockInventory().getContents();
boolean result = super.update(force, applyPhysics);
if (result) {
getTileEntity().setContents(contents);
getTileEntity().updateInRange();
}
return result;
}
}