Search in sources :

Example 1 with BlockChest

use of net.minecraft.block.BlockChest in project SecurityCraft by Geforce132.

the class TileEntityKeypadChestRenderer method renderTileEntityAt.

public void renderTileEntityAt(TileEntityChest p_147502_1_, double p_147502_2_, double p_147502_4_, double p_147502_6_, float p_147502_8_) {
    int i;
    if (!p_147502_1_.hasWorldObj())
        i = 0;
    else {
        Block block = p_147502_1_.getBlockType();
        i = p_147502_1_.getBlockMetadata();
        if (block instanceof BlockChest && i == 0) {
            try {
                ((BlockChest) block).initMetadata(p_147502_1_.getWorld(), p_147502_1_.xCoord, p_147502_1_.yCoord, p_147502_1_.zCoord);
            } catch (ClassCastException e) {
                FMLLog.severe("Attempted to render a chest at %d,  %d, %d that was not a chest", p_147502_1_.xCoord, p_147502_1_.yCoord, p_147502_1_.zCoord);
            }
            i = p_147502_1_.getBlockMetadata();
        }
        p_147502_1_.checkForAdjacentChests();
    }
    if (p_147502_1_.adjacentChestZNeg == null && p_147502_1_.adjacentChestXNeg == null) {
        ModelChest modelchest;
        if (p_147502_1_.adjacentChestXPos == null && p_147502_1_.adjacentChestZPos == null) {
            modelchest = field_147510_h;
            if (field_147509_j)
                bindTexture(christmasNormal);
            else if (p_147502_1_.lidAngle >= 0.9)
                bindTexture(normalSingleActive);
            else
                bindTexture(normalSingleUnactive);
        } else {
            modelchest = field_147511_i;
            if (field_147509_j)
                bindTexture(christmasDouble);
            else if (p_147502_1_.lidAngle >= 0.9)
                bindTexture(normalDoubleActive);
            else
                bindTexture(normalDoubleUnactive);
        }
        GL11.glPushMatrix();
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glTranslatef((float) p_147502_2_, (float) p_147502_4_ + 1.0F, (float) p_147502_6_ + 1.0F);
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        short short1 = 0;
        if (i == 2)
            short1 = 180;
        if (i == 3)
            short1 = 0;
        if (i == 4)
            short1 = 90;
        if (i == 5)
            short1 = -90;
        if (i == 2 && p_147502_1_.adjacentChestXPos != null)
            GL11.glTranslatef(1.0F, 0.0F, 0.0F);
        if (i == 5 && p_147502_1_.adjacentChestZPos != null)
            GL11.glTranslatef(0.0F, 0.0F, -1.0F);
        GL11.glRotatef(short1, 0.0F, 1.0F, 0.0F);
        GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
        float f1 = p_147502_1_.prevLidAngle + (p_147502_1_.lidAngle - p_147502_1_.prevLidAngle) * p_147502_8_;
        float f2;
        if (p_147502_1_.adjacentChestZNeg != null) {
            f2 = p_147502_1_.adjacentChestZNeg.prevLidAngle + (p_147502_1_.adjacentChestZNeg.lidAngle - p_147502_1_.adjacentChestZNeg.prevLidAngle) * p_147502_8_;
            if (f2 > f1)
                f1 = f2;
        }
        if (p_147502_1_.adjacentChestXNeg != null) {
            f2 = p_147502_1_.adjacentChestXNeg.prevLidAngle + (p_147502_1_.adjacentChestXNeg.lidAngle - p_147502_1_.adjacentChestXNeg.prevLidAngle) * p_147502_8_;
            if (f2 > f1)
                f1 = f2;
        }
        f1 = 1.0F - f1;
        f1 = 1.0F - f1 * f1 * f1;
        modelchest.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F);
        modelchest.renderAll();
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glPopMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    }
}
Also used : ModelChest(net.minecraft.client.model.ModelChest) BlockChest(net.minecraft.block.BlockChest) Block(net.minecraft.block.Block)

Example 2 with BlockChest

use of net.minecraft.block.BlockChest in project Bookshelf by Darkhax-Minecraft.

the class TileEntityBasicChest method isChestAt.

/**
     * Checks if there is a chest at the target position.
     *
     * @param posIn The position to check.
     * @return Whether or not there is a chest at the position, and it's type is equal to this
     *         type.
     */
private boolean isChestAt(BlockPos posIn) {
    if (this.getWorld() == null) {
        return false;
    } else {
        final Block block = this.getWorld().getBlockState(posIn).getBlock();
        final TileEntity te = this.getWorld().getTileEntity(posIn);
        return block instanceof BlockChest && ((BlockChest) block).chestType == this.getChestType() && te instanceof TileEntityBasicChest && ((TileEntityBasicChest) te).type == this.type;
    }
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockChest(net.minecraft.block.BlockChest) Block(net.minecraft.block.Block)

Example 3 with BlockChest

use of net.minecraft.block.BlockChest in project SecurityCraft by Geforce132.

the class TileEntityKeypadChestRenderer method renderTileEntityAt.

public void renderTileEntityAt(TileEntityChest p_147502_1_, double p_147502_2_, double p_147502_4_, double p_147502_6_, float p_147502_8_) {
    int i;
    if (!p_147502_1_.hasWorldObj()) {
        i = 0;
    } else {
        Block block = p_147502_1_.getBlockType();
        i = p_147502_1_.getBlockMetadata();
        if (block instanceof BlockChest && i == 0) {
            try {
                ((BlockChest) block).func_149954_e(p_147502_1_.getWorldObj(), p_147502_1_.xCoord, p_147502_1_.yCoord, p_147502_1_.zCoord);
            } catch (ClassCastException e) {
                FMLLog.severe("Attempted to render a chest at %d,  %d, %d that was not a chest", p_147502_1_.xCoord, p_147502_1_.yCoord, p_147502_1_.zCoord);
            }
            i = p_147502_1_.getBlockMetadata();
        }
        p_147502_1_.checkForAdjacentChests();
    }
    if (p_147502_1_.adjacentChestZNeg == null && p_147502_1_.adjacentChestXNeg == null) {
        ModelChest modelchest;
        if (p_147502_1_.adjacentChestXPos == null && p_147502_1_.adjacentChestZPos == null) {
            modelchest = this.field_147510_h;
            if (p_147502_1_.func_145980_j() == 1) {
                this.bindTexture(trappedNormal);
            } else if (this.field_147509_j) {
                this.bindTexture(christmasNormal);
            } else {
                if (p_147502_1_.lidAngle >= 0.9) {
                    this.bindTexture(normalSingleActive);
                } else {
                    this.bindTexture(normalSingleUnactive);
                }
            }
        } else {
            modelchest = this.field_147511_i;
            if (p_147502_1_.func_145980_j() == 1) {
                this.bindTexture(trappedDouble);
            } else if (this.field_147509_j) {
                this.bindTexture(christmasDouble);
            } else {
                if (p_147502_1_.lidAngle >= 0.9) {
                    this.bindTexture(normalDoubleActive);
                } else {
                    this.bindTexture(normalDoubleUnactive);
                }
            }
        }
        GL11.glPushMatrix();
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glTranslatef((float) p_147502_2_, (float) p_147502_4_ + 1.0F, (float) p_147502_6_ + 1.0F);
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        short short1 = 0;
        if (i == 2) {
            short1 = 180;
        }
        if (i == 3) {
            short1 = 0;
        }
        if (i == 4) {
            short1 = 90;
        }
        if (i == 5) {
            short1 = -90;
        }
        if (i == 2 && p_147502_1_.adjacentChestXPos != null) {
            GL11.glTranslatef(1.0F, 0.0F, 0.0F);
        }
        if (i == 5 && p_147502_1_.adjacentChestZPos != null) {
            GL11.glTranslatef(0.0F, 0.0F, -1.0F);
        }
        GL11.glRotatef((float) short1, 0.0F, 1.0F, 0.0F);
        GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
        float f1 = p_147502_1_.prevLidAngle + (p_147502_1_.lidAngle - p_147502_1_.prevLidAngle) * p_147502_8_;
        float f2;
        if (p_147502_1_.adjacentChestZNeg != null) {
            f2 = p_147502_1_.adjacentChestZNeg.prevLidAngle + (p_147502_1_.adjacentChestZNeg.lidAngle - p_147502_1_.adjacentChestZNeg.prevLidAngle) * p_147502_8_;
            if (f2 > f1) {
                f1 = f2;
            }
        }
        if (p_147502_1_.adjacentChestXNeg != null) {
            f2 = p_147502_1_.adjacentChestXNeg.prevLidAngle + (p_147502_1_.adjacentChestXNeg.lidAngle - p_147502_1_.adjacentChestXNeg.prevLidAngle) * p_147502_8_;
            if (f2 > f1) {
                f1 = f2;
            }
        }
        f1 = 1.0F - f1;
        f1 = 1.0F - f1 * f1 * f1;
        modelchest.chestLid.rotateAngleX = -(f1 * (float) Math.PI / 2.0F);
        modelchest.renderAll();
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glPopMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    }
}
Also used : ModelChest(net.minecraft.client.model.ModelChest) BlockChest(net.minecraft.block.BlockChest) Block(net.minecraft.block.Block)

Example 4 with BlockChest

use of net.minecraft.block.BlockChest in project Charset by CharsetMC.

the class CustomCarryHandlerChest method onPlace.

@Override
public void onPlace(World world, BlockPos pos) {
    super.onPlace(world, pos);
    for (EnumFacing facing1 : EnumFacing.HORIZONTALS) {
        if (world.getBlockState(pos.offset(facing1)).getBlock() instanceof BlockChest) {
            // FIXME: Double chests need this (#137)
            IBlockState state = owner.getState();
            List<ItemStack> drops = state.getBlock().getDrops(world, pos, state, 0);
            owner.getState().getBlock().onBlockPlacedBy(world, pos, owner.getState(), (EntityLivingBase) owner.getCarrier(), drops.size() > 0 ? drops.get(0) : ItemStack.EMPTY);
            break;
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockChest(net.minecraft.block.BlockChest) EnumFacing(net.minecraft.util.EnumFacing) ItemStack(net.minecraft.item.ItemStack)

Example 5 with BlockChest

use of net.minecraft.block.BlockChest in project SpongeForge by SpongePowered.

the class MixinPlayerInteractionManager method processRightClickBlock.

/**
 * @author gabizou - May 5th, 2016
 * @reason Rewrite the firing of interact block events with forge hooks
 * Note: This is a dirty merge of Aaron's SpongeCommon writeup of the interaction events and
 * Forge's additions. There's some overlay between the two events, specifically that there
 * is a SpongeEvent thrown before the ForgeEvent, and yet both are checked in various
 * if statements.
 */
@Overwrite
public EnumActionResult processRightClickBlock(EntityPlayer player, 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) {
                player.displayGUIChest(ilockablecontainer);
                return EnumActionResult.SUCCESS;
            }
        } else if (tileentity instanceof IInventory) {
            player.displayGUIChest((IInventory) tileentity);
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.PASS;
    }
    // Store reference of current player's itemstack in case it changes
    ItemStack oldStack = stack.copy();
    InteractBlockEvent.Secondary event;
    BlockSnapshot currentSnapshot = ((org.spongepowered.api.world.World) worldIn).createSnapshot(pos.getX(), pos.getY(), pos.getZ());
    event = SpongeCommonEventFactory.callInteractBlockEventSecondary(player, oldStack, VecHelper.toVector3d(pos.add(hitX, hitY, hitZ)), currentSnapshot, DirectionFacingProvider.getInstance().getKey(facing).get(), hand);
    if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
        SpongeCommonEventFactory.playerInteractItemChanged = true;
    }
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (event.isCancelled()) {
        final IBlockState state = worldIn.getBlockState(pos);
        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 (!stack.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
            if (stack.getItem() instanceof ItemDoor || (stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock().equals(Blocks.DOUBLE_PLANT))) {
                this.player.connection.sendPacket(new SPacketBlockChange(worldIn, pos.up(2)));
            }
        }
        // since we don't want to undo that
        if (tileEntity != null && this.player.openContainer instanceof ContainerPlayer) {
            this.player.closeScreen();
        }
        SpongeCommonEventFactory.interactBlockEventCancelled = true;
        return EnumActionResult.FAIL;
    }
    net.minecraft.item.Item item = stack.isEmpty() ? null : stack.getItem();
    EnumActionResult ret = item == null ? EnumActionResult.PASS : item.onItemUseFirst(player, worldIn, pos, facing, hitX, hitY, hitZ, hand);
    if (ret != EnumActionResult.PASS) {
        return ret;
    }
    boolean bypass = true;
    final ItemStack[] itemStacks = { player.getHeldItemMainhand(), player.getHeldItemOffhand() };
    for (ItemStack s : itemStacks) {
        bypass = bypass && (s.isEmpty() || s.getItem().doesSneakBypassUse(s, worldIn, pos, player));
    }
    EnumActionResult result = EnumActionResult.PASS;
    if (!player.isSneaking() || bypass || event.getUseBlockResult() == Tristate.TRUE) {
        // also, store the result instead of returning immediately
        if (event.getUseBlockResult() != Tristate.FALSE) {
            IBlockState iblockstate = worldIn.getBlockState(pos);
            Container lastOpenContainer = player.openContainer;
            result = iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
            // if itemstack changed, avoid restore
            if (!ItemStack.areItemStacksEqual(oldStack, this.player.getHeldItem(hand))) {
                SpongeCommonEventFactory.playerInteractItemChanged = true;
            }
            result = this.handleOpenEvent(lastOpenContainer, this.player, currentSnapshot, result);
        } else {
            this.player.connection.sendPacket(new SPacketBlockChange(this.world, pos));
            result = TristateUtil.toActionResult(event.getUseItemResult());
        }
    }
    // This handles the event not cancelled and block not activated
    if (result != EnumActionResult.SUCCESS && tileEntity != null && hand == EnumHand.MAIN_HAND) {
        this.player.closeScreen();
    }
    // store result instead of returning
    if (stack.isEmpty()) {
        result = EnumActionResult.PASS;
    } else if (player.getCooldownTracker().hasCooldown(stack.getItem())) {
        result = EnumActionResult.PASS;
    } else if (stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).getBlock() instanceof BlockCommandBlock && !player.canUseCommand(2, "")) {
        result = EnumActionResult.FAIL;
    } else {
        if ((result != EnumActionResult.SUCCESS && event.getUseItemResult() != Tristate.FALSE || result == EnumActionResult.SUCCESS && event.getUseItemResult() == Tristate.TRUE)) {
            int meta = stack.getMetadata();
            int size = stack.getCount();
            result = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
            // nest isCreative check instead of calling the method twice.
            if (this.isCreative()) {
                stack.setItemDamage(meta);
                stack.setCount(size);
            }
        }
    }
    if (!ItemStack.areItemStacksEqual(player.getHeldItem(hand), oldStack) || result != EnumActionResult.SUCCESS) {
        player.openContainer.detectAndSendChanges();
    }
    return result;
// Sponge end
}
Also used : ItemDoor(net.minecraft.item.ItemDoor) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) World(net.minecraft.world.World) TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) EnumActionResult(net.minecraft.util.EnumActionResult) ILockableContainer(net.minecraft.world.ILockableContainer) Container(net.minecraft.inventory.Container) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) SPacketCloseWindow(net.minecraft.network.play.server.SPacketCloseWindow) IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) IBlockState(net.minecraft.block.state.IBlockState) BlockChest(net.minecraft.block.BlockChest) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) ItemBlock(net.minecraft.item.ItemBlock) SPacketBlockChange(net.minecraft.network.play.server.SPacketBlockChange) ContainerPlayer(net.minecraft.inventory.ContainerPlayer) Block(net.minecraft.block.Block) BlockCommandBlock(net.minecraft.block.BlockCommandBlock) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

BlockChest (net.minecraft.block.BlockChest)18 Block (net.minecraft.block.Block)15 ModelChest (net.minecraft.client.model.ModelChest)7 IBlockState (net.minecraft.block.state.IBlockState)6 TileEntity (net.minecraft.tileentity.TileEntity)6 IInventory (net.minecraft.inventory.IInventory)4 ItemStack (net.minecraft.item.ItemStack)3 TileEntityChest (net.minecraft.tileentity.TileEntityChest)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockBed (net.minecraft.block.BlockBed)2 BlockCommandBlock (net.minecraft.block.BlockCommandBlock)2 BlockEnderChest (net.minecraft.block.BlockEnderChest)2 BlockSign (net.minecraft.block.BlockSign)2 BlockSkull (net.minecraft.block.BlockSkull)2 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 Container (net.minecraft.inventory.Container)2 ItemBlock (net.minecraft.item.ItemBlock)2 ItemDoor (net.minecraft.item.ItemDoor)2 SPacketBlockChange (net.minecraft.network.play.server.SPacketBlockChange)2