use of net.minecraft.block.BlockChest in project SpongeCommon by SpongePowered.
the class MixinPlayerInteractionManager method processRightClickBlock.
/**
* @author Aaron1011
* @author gabizou - May 28th, 2016 - Rewritten for 1.9.4
*
* @reason Fire interact block event.
*/
@Overwrite
public EnumActionResult processRightClickBlock(EntityPlayer player, net.minecraft.world.World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (this.gameType == GameType.SPECTATOR) {
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof ILockableContainer) {
Block block = worldIn.getBlockState(pos).getBlock();
ILockableContainer ilockablecontainer = (ILockableContainer) tileentity;
if (ilockablecontainer instanceof TileEntityChest && block instanceof BlockChest) {
ilockablecontainer = ((BlockChest) block).getLockableContainer(worldIn, pos);
}
if (ilockablecontainer != null) {
// TODO - fire event
player.displayGUIChest(ilockablecontainer);
return EnumActionResult.SUCCESS;
}
} else if (tileentity instanceof IInventory) {
// TODO - fire event
player.displayGUIChest((IInventory) tileentity);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
// else { // Sponge - Remove unecessary else
// Sponge Start - Create an interact block event before something happens.
final ItemStack oldStack = stack.copy();
final BlockSnapshot currentSnapshot = ((World) worldIn).createSnapshot(pos.getX(), pos.getY(), pos.getZ());
final InteractBlockEvent.Secondary event = SpongeCommonEventFactory.callInteractBlockEventSecondary(player, oldStack, new Vector3d(pos.getX() + hitX, pos.getY() + hitY, pos.getZ() + hitZ), currentSnapshot, DirectionFacingProvider.getInstance().getKey(facing).get(), hand);
if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
SpongeCommonEventFactory.playerInteractItemChanged = true;
}
if (event.isCancelled()) {
final IBlockState state = (IBlockState) currentSnapshot.getState();
if (state.getBlock() == Blocks.COMMAND_BLOCK) {
// CommandBlock GUI opens solely on the client, we need to force it close on cancellation
this.player.connection.sendPacket(new SPacketCloseWindow(0));
} else if (state.getProperties().containsKey(BlockDoor.HALF)) {
// client to resolve this
if (state.getValue(BlockDoor.HALF) == BlockDoor.EnumDoorHalf.LOWER) {
this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.up()));
} else {
this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.down()));
}
} else if (!oldStack.isEmpty()) {
// Stopping the placement of a door or double plant causes artifacts (ghosts) on the top-side of the block. We need to remove it
final Item item = oldStack.getItem();
if (item instanceof ItemDoor || (item instanceof ItemBlock && ((ItemBlock) item).getBlock().equals(Blocks.DOUBLE_PLANT))) {
this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.up(2)));
}
}
SpongeCommonEventFactory.interactBlockEventCancelled = true;
return EnumActionResult.FAIL;
}
if (!player.isSneaking() || player.getHeldItemMainhand().isEmpty() && player.getHeldItemOffhand().isEmpty()) {
// Also, store the result instead of returning immediately
if (event.getUseBlockResult() != Tristate.FALSE) {
IBlockState iblockstate = (IBlockState) currentSnapshot.getState();
Container lastOpenContainer = player.openContainer;
EnumActionResult result = iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
// if itemstack changed, avoid restore
if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
SpongeCommonEventFactory.playerInteractItemChanged = true;
}
result = this.handleOpenEvent(lastOpenContainer, this.player, currentSnapshot, result);
if (result != EnumActionResult.PASS) {
return result;
}
} else {
// Need to send a block change to the client, because otherwise, they are not
// going to be told about the block change.
this.player.connection.sendPacket(new SPacketBlockChange(this.world, pos));
// it wasn't cancelled, but perform no further processing.
return EnumActionResult.FAIL;
}
// Sponge End
}
if (stack.isEmpty()) {
return EnumActionResult.PASS;
} else if (player.getCooldownTracker().hasCooldown(stack.getItem())) {
return EnumActionResult.PASS;
} else if (stack.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) stack.getItem()).getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
return EnumActionResult.FAIL;
}
}
// else if (this.isCreative()) { // Sponge - Rewrite this to handle an isCreative check after the result, since we have a copied stack at the top of this method.
// int j = stack.getMetadata();
// int i = stack.stackSize;
// EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, offsetX, offsetY, offsetZ);
// stack.setItemDamage(j);
// stack.stackSize = i;
// return enumactionresult;
// } else {
// return stack.onItemUse(player, worldIn, pos, hand, facing, offsetX, offsetY, offsetZ);
// }
// } // Sponge - Remove unecessary else bracket
// Sponge Start - complete the method with the micro change of resetting item damage and quantity from the copied stack.
final EnumActionResult result = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
if (this.isCreative()) {
stack.setItemDamage(oldStack.getItemDamage());
stack.setCount(oldStack.getCount());
}
if (!ItemStack.areItemStacksEqual(player.getHeldItem(hand), oldStack) || result != EnumActionResult.SUCCESS) {
player.openContainer.detectAndSendChanges();
}
return result;
// Sponge end
// } // Sponge - Remove unecessary else bracket
}
use of net.minecraft.block.BlockChest in project PneumaticCraft by MineMaarten.
the class IOHelper method getInventoryForTE.
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;
}
}
use of net.minecraft.block.BlockChest in project MC-Prefab by Brian-Wuest.
the class StructureAlternateStart method CustomBlockProcessingHandled.
@Override
protected Boolean CustomBlockProcessingHandled(StructureConfiguration configuration, BuildBlock block, World world, BlockPos originalPos, EnumFacing assumedNorth, Block foundBlock, IBlockState blockState, EntityPlayer player) {
HouseConfiguration houseConfig = (HouseConfiguration) configuration;
if ((!houseConfig.addBed && foundBlock instanceof BlockBed) || (!houseConfig.addChest && foundBlock instanceof BlockChest) || (!houseConfig.addTorches && foundBlock instanceof BlockTorch) || (!houseConfig.addCraftingTable && (foundBlock instanceof BlockWorkbench || foundBlock instanceof BlockFurnace))) {
// "handled"
return true;
}
if (foundBlock instanceof BlockFurnace) {
this.furnacePosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
} else if (foundBlock instanceof BlockTrapDoor && houseConfig.addMineShaft) {
// The trap door will still be added, but the mine shaft may not be
// built.
this.trapDoorPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
} else if (foundBlock instanceof BlockChest && this.chestPosition == null) {
this.chestPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
} else if (foundBlock instanceof BlockStandingSign) {
this.signPosition = block.getStartingPosition().getRelativePosition(originalPos, this.getClearSpace().getShape().getDirection(), configuration.houseFacing);
}
if (foundBlock.getRegistryName().getResourceDomain().equals(Blocks.STAINED_GLASS.getRegistryName().getResourceDomain()) && foundBlock.getRegistryName().getResourcePath().equals(Blocks.STAINED_GLASS.getRegistryName().getResourcePath())) {
blockState = blockState.withProperty(BlockStainedGlass.COLOR, houseConfig.glassColor);
block.setBlockState(blockState);
this.priorityOneBlocks.add(block);
return true;
} else if (foundBlock.getRegistryName().getResourceDomain().equals(Blocks.STAINED_GLASS_PANE.getRegistryName().getResourceDomain()) && foundBlock.getRegistryName().getResourcePath().equals(Blocks.STAINED_GLASS_PANE.getRegistryName().getResourcePath())) {
block.setBlockState(foundBlock.getStateFromMeta(houseConfig.glassColor.getMetadata()));
this.priorityOneBlocks.add(block);
return true;
}
return false;
}
use of net.minecraft.block.BlockChest in project Tropicraft by Tropicraft.
the class TileEntityBambooChestRenderer method renderChest.
@SuppressWarnings({ "null", "unused" })
public void renderChest(TileEntityBambooChest te, double x, double y, double z, float partialTicks, int destroyStage) {
GlStateManager.enableDepth();
GlStateManager.depthFunc(515);
GlStateManager.depthMask(true);
int i;
if (!te.hasWorld()) {
i = 0;
} else {
Block block = te.getBlockType();
i = te.getBlockMetadata();
if (block instanceof BlockChest && i == 0) {
((BlockChest) block).checkForSurroundingChests(te.getWorld(), te.getPos(), te.getWorld().getBlockState(te.getPos()));
i = te.getBlockMetadata();
}
te.checkForAdjacentChests();
}
if (te.adjacentChestZNeg == null && te.adjacentChestXNeg == null) {
ModelChest modelchest;
if (te.adjacentChestXPos == null && te.adjacentChestZPos == null) {
modelchest = chestModel;
if (destroyStage >= 0) {
this.bindTexture(DESTROY_STAGES[destroyStage]);
GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 4.0F, 1.0F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888);
} else {
TropicraftRenderUtils.bindTextureBlock("te/bamboo_chest");
}
} else {
modelchest = this.chestModelLarge;
if (destroyStage >= 0) {
this.bindTexture(DESTROY_STAGES[destroyStage]);
GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix();
GlStateManager.scale(8.0F, 4.0F, 1.0F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888);
} else {
TropicraftRenderUtils.bindTextureBlock("te/large_bamboo_chest");
}
}
GlStateManager.pushMatrix();
GlStateManager.enableRescaleNormal();
if (destroyStage < 0) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
}
GlStateManager.translate((float) x, (float) y + 1.0F, (float) z + 1.0F);
GlStateManager.scale(1.0F, -1.0F, -1.0F);
GlStateManager.translate(0.5F, 0.5F, 0.5F);
int j = 0;
if (i == 2) {
j = 180;
}
if (i == 3) {
j = 0;
}
if (i == 4) {
j = 90;
}
if (i == 5) {
j = -90;
}
if (i == 2 && te.adjacentChestXPos != null) {
GlStateManager.translate(1.0F, 0.0F, 0.0F);
}
if (i == 5 && te.adjacentChestZPos != null) {
GlStateManager.translate(0.0F, 0.0F, -1.0F);
}
GlStateManager.rotate((float) j, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(-0.5F, -0.5F, -0.5F);
float f = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks;
if (te.adjacentChestZNeg != null) {
float f1 = te.adjacentChestZNeg.prevLidAngle + (te.adjacentChestZNeg.lidAngle - te.adjacentChestZNeg.prevLidAngle) * partialTicks;
if (f1 > f) {
f = f1;
}
}
if (te.adjacentChestXNeg != null) {
float f2 = te.adjacentChestXNeg.prevLidAngle + (te.adjacentChestXNeg.lidAngle - te.adjacentChestXNeg.prevLidAngle) * partialTicks;
if (f2 > f) {
f = f2;
}
}
f = 1.0F - f;
f = 1.0F - f * f * f;
modelchest.chestLid.rotateAngleX = -(f * ((float) Math.PI / 2F));
modelchest.renderAll();
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
if (destroyStage >= 0) {
GlStateManager.matrixMode(5890);
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
}
}
}
use of net.minecraft.block.BlockChest in project Adventurers-Toolbox by the-realest-stu.
the class ExtraBlockBreakHandler method drawBlockDamageTexture.
private void drawBlockDamageTexture(Tessellator tessellatorIn, BufferBuilder bufferBuilderIn, Entity entityIn, float partialTicks) {
double d3 = entityIn.lastTickPosX + (entityIn.posX - entityIn.lastTickPosX) * (double) partialTicks;
double d4 = entityIn.lastTickPosY + (entityIn.posY - entityIn.lastTickPosY) * (double) partialTicks;
double d5 = entityIn.lastTickPosZ + (entityIn.posZ - entityIn.lastTickPosZ) * (double) partialTicks;
if (this.mc.world.getWorldTime() % 20 == 0) {
this.cleanupExtraDamagedBlocks();
}
if (!this.extraDamagedBlocks.isEmpty()) {
this.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
this.preRenderDamagedBlocks();
bufferBuilderIn.begin(7, DefaultVertexFormats.BLOCK);
bufferBuilderIn.setTranslation(-d3, -d4, -d5);
bufferBuilderIn.noColor();
for (Entry<Integer, DestroyExtraBlocksProgress> entry : this.extraDamagedBlocks.entrySet()) {
DestroyExtraBlocksProgress destroyblockprogress = entry.getValue();
BlockPos[] blockpositions = destroyblockprogress.getPositions();
for (int i = 0; i < blockpositions.length; i++) {
BlockPos blockpos = blockpositions[i];
double d6 = (double) blockpos.getX() - d3;
double d7 = (double) blockpos.getY() - d4;
double d8 = (double) blockpos.getZ() - d5;
Block block = this.mc.world.getBlockState(blockpos).getBlock();
TileEntity te = this.mc.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) {
if (d6 * d6 + d7 * d7 + d8 * d8 > 16384) {
this.extraDamagedBlocks.remove(entry.getKey());
} else {
IBlockState iblockstate = mc.world.getBlockState(blockpos);
if (iblockstate.getMaterial() != Material.AIR) {
int k1 = destroyblockprogress.getPartialBlockDamage();
TextureAtlasSprite textureatlassprite = this.destroyBlockIcons[k1];
BlockRendererDispatcher blockrendererdispatcher = this.mc.getBlockRendererDispatcher();
blockrendererdispatcher.renderBlockDamage(iblockstate, blockpos, textureatlassprite, this.mc.world);
}
}
}
}
}
tessellatorIn.draw();
bufferBuilderIn.setTranslation(0.0D, 0.0D, 0.0D);
this.postRenderDamagedBlocks();
}
}
Aggregations