Search in sources :

Example 26 with BlockChest

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
}
Also used : IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) IBlockState(net.minecraft.block.state.IBlockState) ItemDoor(net.minecraft.item.ItemDoor) BlockChest(net.minecraft.block.BlockChest) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) BlockStructure(net.minecraft.block.BlockStructure) World(org.spongepowered.api.world.World) ItemBlock(net.minecraft.item.ItemBlock) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange) TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) Item(net.minecraft.item.Item) ILockableContainer(net.minecraft.world.ILockableContainer) IMixinContainer(org.spongepowered.common.interfaces.IMixinContainer) Container(net.minecraft.inventory.Container) EnumActionResult(net.minecraft.util.EnumActionResult) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) Vector3d(com.flowpowered.math.vector.Vector3d) Block(net.minecraft.block.Block) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) ItemBlock(net.minecraft.item.ItemBlock) SPacketCloseWindow(net.minecraft.network.play.server.SPacketCloseWindow) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 27 with BlockChest

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;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) BlockChest(net.minecraft.block.BlockChest) Block(net.minecraft.block.Block)

Example 28 with BlockChest

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;
}
Also used : BlockFurnace(net.minecraft.block.BlockFurnace) BlockChest(net.minecraft.block.BlockChest) BlockWorkbench(net.minecraft.block.BlockWorkbench) BlockTrapDoor(net.minecraft.block.BlockTrapDoor) BlockStandingSign(net.minecraft.block.BlockStandingSign) BlockBed(net.minecraft.block.BlockBed) HouseConfiguration(com.wuest.prefab.Config.Structures.HouseConfiguration) BlockTorch(net.minecraft.block.BlockTorch)

Example 29 with BlockChest

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);
        }
    }
}
Also used : ModelChest(net.minecraft.client.model.ModelChest) BlockChest(net.minecraft.block.BlockChest) Block(net.minecraft.block.Block)

Example 30 with BlockChest

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();
    }
}
Also used : BlockSkull(net.minecraft.block.BlockSkull) IBlockState(net.minecraft.block.state.IBlockState) BlockChest(net.minecraft.block.BlockChest) BlockEnderChest(net.minecraft.block.BlockEnderChest) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) TileEntity(net.minecraft.tileentity.TileEntity) BlockSign(net.minecraft.block.BlockSign) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Aggregations

BlockChest (net.minecraft.block.BlockChest)45 Block (net.minecraft.block.Block)42 TileEntity (net.minecraft.tileentity.TileEntity)20 IInventory (net.minecraft.inventory.IInventory)18 IBlockState (net.minecraft.block.state.IBlockState)16 TileEntityChest (net.minecraft.tileentity.TileEntityChest)14 ModelChest (net.minecraft.client.model.ModelChest)13 Entity (net.minecraft.entity.Entity)9 BlockPos (net.minecraft.util.math.BlockPos)9 BlockEnderChest (net.minecraft.block.BlockEnderChest)8 BlockSign (net.minecraft.block.BlockSign)8 BlockSkull (net.minecraft.block.BlockSkull)8 ILockableContainer (net.minecraft.world.ILockableContainer)7 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)6 BlockPos (net.minecraft.util.BlockPos)6 BlockCommandBlock (net.minecraft.block.BlockCommandBlock)4 ItemBlock (net.minecraft.item.ItemBlock)4 EnumActionResult (net.minecraft.util.EnumActionResult)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)4 List (java.util.List)3