Java源码示例:net.minecraft.block.BlockJukebox
示例1
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
CraftWorld world = (CraftWorld) this.getWorld();
Material record = this.getPlaying();
if (record == Material.AIR) {
world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()),
Blocks.JUKEBOX.getDefaultState()
.withProperty(BlockJukebox.HAS_RECORD, false), 3);
} else {
world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()),
Blocks.JUKEBOX.getDefaultState()
.withProperty(BlockJukebox.HAS_RECORD, true), 3);
}
world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record.getId());
}
return result;
}
示例2
@Override
public boolean eject() {
requirePlaced();
TileEntity tileEntity = this.getTileEntityFromWorld();
if (!(tileEntity instanceof TileEntityJukebox)) return false;
TileEntityJukebox jukebox = (TileEntityJukebox) tileEntity;
boolean result = !jukebox.getRecord().isEmpty();
CraftWorld world = (CraftWorld) this.getWorld();
((BlockJukebox) Blocks.JUKEBOX).dropRecord(world.getHandle(), new BlockPos(getX(), getY(), getZ()), null);
return result;
}
示例3
public boolean eject() {
boolean result = isPlaying();
((BlockJukebox) Blocks.jukebox).func_149925_e(world.getHandle(), getX(), getY(), getZ());
return result;
}
示例4
@Override
public ResponseMessage onMessage(TileRequest message, MessageContext ctx)
{
World world = DimensionManager.getWorld(message.dim);
if (world == null) return null;
TileEntity te = world.getTileEntity(message.pos);
if (te == null) return null;
if (Helper.banned.contains(te.getClass().getCanonicalName())) return null;
if (te instanceof ILockableContainer && !ctx.getServerHandler().player.canOpen(((ILockableContainer) te).getLockCode())) return null;
if (te instanceof TileEntityEnderChest)
{
return new PlainInventory(message.pos, ctx.getServerHandler().player.getInventoryEnderChest());
}
else if (te instanceof BlockJukebox.TileEntityJukebox)
{
InventoryBasic ib = new InventoryBasic("minecraft:jukebox", false, 1);
ib.setInventorySlotContents(0, ((BlockJukebox.TileEntityJukebox) te).getRecord());
return new PlainInventory(message.pos, ib).setName(Blocks.JUKEBOX.getUnlocalizedName());
}
else if (te instanceof TileEntityChest)
{
Block b = world.getBlockState(message.pos).getBlock();
if (b instanceof BlockChest)
{
IInventory i = ((BlockChest) b).getLockableContainer(world, message.pos);
if (i != null) return new PlainInventory(message.pos, i);
return null;
}
return new PlainInventory(message.pos, ((TileEntityChest) te));
}
else if (te instanceof IInventory)
{
return new PlainInventory(message.pos, (IInventory) te);
}
else if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null))
{
IItemHandler iih = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
if (iih == null)
{
HoloInventory.getLogger().warn("Error: Block at {} (Class: {} Te: {} Block: {}) returned null after indicating the capability is available.", message.pos, te.getClass().getName(), te, te.getBlockType());
return null;
}
if (te instanceof INamedItemHandler) {
INamedItemHandler namedHandler = (INamedItemHandler) te;
return new PlainInventory(message.pos, namedHandler.getItemHandlerName(), iih);
}
return new PlainInventory(message.pos, te.getBlockType().getUnlocalizedName(), iih);
}
return null;
}
示例5
public static boolean accept(TileEntity te)
{
return te != null && (te instanceof IInventory || te instanceof BlockJukebox.TileEntityJukebox || te instanceof TileEntityEnderChest || te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null));
}