Java源码示例:net.minecraft.block.BlockChest
示例1
private IBlockState getChestBlock(int x, int z) {
IBlockState currentBlock;
if (x > 1) {
currentBlock = ((BlockChest) Blocks.CHEST).getStateFromMeta(4);
} else if (x < -1) {
currentBlock = ((BlockChest) Blocks.CHEST).getStateFromMeta(5);
} else if (z > 1) {
currentBlock = ((BlockChest) Blocks.CHEST).getStateFromMeta(2);
} else if (z < -1) {
currentBlock = ((BlockChest) Blocks.CHEST).getStateFromMeta(3);
} else {
currentBlock = Blocks.AIR.getDefaultState();
}
return currentBlock;
}
示例2
public BlockChestGnome()
{
super(BlockChest.Type.BASIC);
this.setCreativeTab(null);
this.setHardness(2.5F);
this.setSoundType(SoundType.WOOD);
}
示例3
private IBlockState randomChest() {
int roll = rand.nextInt(4);
switch (roll) {
case 1:
return Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.NORTH);
case 2:
return Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.SOUTH);
case 3:
return Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.EAST);
default:
return Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.WEST);
}
}
示例4
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
if (world.isRemote) {
return EnumActionResult.PASS;
}
IBlockState state = world.getBlockState(pos);
TileEntity te = world.getTileEntity(pos);
if (state.getBlock() == Blocks.CHEST && te instanceof TileEntityChest) {
TileEntityChest chest = (TileEntityChest) te;
ItemStack[] items = new ItemStack[chest.getSizeInventory()];
for (int i = 0; i < items.length; i++) {
items[i] = chest.getStackInSlot(i);
chest.setInventorySlotContents(i, ItemStack.EMPTY);
}
IBlockState newState = BlocksItemsBetterChests.betterchest.getDefaultState().withProperty(BlockBetterChest.directions, state.getValue(BlockChest.FACING));
world.setBlockState(pos, newState, 2);
TileEntityBChest newte = new TileEntityBChest();
world.setTileEntity(pos, newte);
for (int i = 0; i < items.length; i++) {
newte.getChestPart().setInventorySlotContents(i, items[i]);
}
world.notifyBlockUpdate(pos, state, newState, 1);
ItemStack heldItem = player.getHeldItem(hand);
heldItem.setCount(heldItem.getCount() - 1);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
示例5
public static IInventory getInventoryForTE(TileEntity te){
if(te instanceof IInventory) {
IInventory inv = (IInventory)te;
Block block = te.getBlockType();
if(block instanceof BlockChest) {
inv = ((BlockChest)block).func_149951_m(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
}
return inv;
} else {
return null;
}
}
示例6
/**
* aa
*
* @author xd
*/
@Overwrite
public void drawBlockDamageTexture(Tessellator tessellatorIn, BufferBuilder worldRendererIn,
Entity entityIn, float partialTicks) {
double d0 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * partialTicks;
double d1 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * partialTicks;
double d2 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * partialTicks;
if (!this.damagedBlocks.isEmpty()) {
this.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
this.preRenderDamagedBlocks();
worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
worldRendererIn.setTranslation(-d0, -d1, -d2);
worldRendererIn.noColor();
Iterator<DestroyBlockProgress> iterator = this.damagedBlocks.values().iterator();
while (iterator.hasNext()) {
DestroyBlockProgress destroyblockprogress = iterator.next();
BlockPos blockpos = destroyblockprogress.getPosition();
double d3 = blockpos.getX() - d0;
double d4 = blockpos.getY() - d1;
double d5 = blockpos.getZ() - d2;
Block block = this.world.getBlockState(blockpos).getBlock();
TileEntity te = this.world.getTileEntity(blockpos);
boolean hasBreak = block instanceof BlockChest || block instanceof BlockEnderChest
|| block instanceof BlockSign || block instanceof BlockSkull;
if (!hasBreak) {
hasBreak = te != null && te.canRenderBreaking();
}
if (!hasBreak) {
Optional<PhysicsObject> physicsObject = ValkyrienUtils
.getPhysicsObject(world, blockpos);
if (!physicsObject.isPresent() && (d3 * d3 + d4 * d4 + d5 * d5 > 1024.0D)) {
iterator.remove();
} else {
IBlockState iblockstate = this.world.getBlockState(blockpos);
if (physicsObject.isPresent()) {
physicsObject.get()
.getShipRenderer()
.applyRenderTransform(partialTicks);
worldRendererIn.setTranslation(-physicsObject.get()
.getShipRenderer().offsetPos.getX(), -physicsObject.get()
.getShipRenderer().offsetPos.getY(), -physicsObject.get()
.getShipRenderer().offsetPos.getZ());
}
if (iblockstate.getMaterial() != Material.AIR) {
int i = destroyblockprogress.getPartialBlockDamage();
TextureAtlasSprite textureatlassprite = this.destroyBlockIcons[i];
BlockRendererDispatcher blockrendererdispatcher = this.mc
.getBlockRendererDispatcher();
try {
blockrendererdispatcher
.renderBlockDamage(iblockstate, blockpos, textureatlassprite,
this.world);
} catch (Exception e) {
e.printStackTrace();
}
}
worldRendererIn.setTranslation(-d0, -d1, -d2);
// TODO: Reverse the Matrix Transforms here
if (physicsObject.isPresent()) {
tessellatorIn.draw();
worldRendererIn.begin(7, DefaultVertexFormats.BLOCK);
physicsObject.get()
.getShipRenderer()
.inverseTransform(partialTicks);
}
}
}
}
tessellatorIn.draw();
worldRendererIn.setTranslation(0.0D, 0.0D, 0.0D);
this.postRenderDamagedBlocks();
}
}
示例7
@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;
}