Search in sources :

Example 16 with BlockChest

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

the class TileEntityKeypadChestRenderer method render.

@Override
public void render(TileEntityKeypadChest te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    int j;
    if (!te.hasWorld())
        j = 0;
    else {
        Block block = te.getBlockType();
        j = te.getBlockMetadata();
        if (block instanceof BlockChest && j == 0) {
            ((BlockChest) block).checkForSurroundingChests(te.getWorld(), te.getPos(), te.getWorld().getBlockState(te.getPos()));
            j = te.getBlockMetadata();
        }
        te.checkForAdjacentChests();
    }
    if (te.adjacentChestZNeg == null && te.adjacentChestXNeg == null) {
        ModelChest modelchest;
        if (te.adjacentChestXPos == null && te.adjacentChestZPos == null) {
            modelchest = field_147510_h;
            if (destroyStage >= 0) {
                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 if (field_147509_j)
                bindTexture(christmasNormal);
            else if (te.lidAngle >= 0.9)
                bindTexture(normalSingleActive);
            else
                bindTexture(normalSingleUnactive);
        } else {
            modelchest = field_147511_i;
            if (destroyStage >= 0) {
                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 if (field_147509_j)
                bindTexture(christmasDouble);
            else if (te.lidAngle >= 0.9)
                bindTexture(normalDoubleActive);
            else
                bindTexture(normalDoubleUnactive);
        }
        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);
        short short1 = 0;
        if (j == 2)
            short1 = 180;
        if (j == 3)
            short1 = 0;
        if (j == 4)
            short1 = 90;
        if (j == 5)
            short1 = -90;
        if (j == 2 && te.adjacentChestXPos != null)
            GlStateManager.translate(1.0F, 0.0F, 0.0F);
        if (j == 5 && te.adjacentChestZPos != null)
            GlStateManager.translate(0.0F, 0.0F, -1.0F);
        GlStateManager.rotate(short1, 0.0F, 1.0F, 0.0F);
        GlStateManager.translate(-0.5F, -0.5F, -0.5F);
        float f1 = te.prevLidAngle + (te.lidAngle - te.prevLidAngle) * partialTicks;
        float f2;
        if (te.adjacentChestZNeg != null) {
            f2 = te.adjacentChestZNeg.prevLidAngle + (te.adjacentChestZNeg.lidAngle - te.adjacentChestZNeg.prevLidAngle) * partialTicks;
            if (f2 > f1)
                f1 = f2;
        }
        if (te.adjacentChestXNeg != null) {
            f2 = te.adjacentChestXNeg.prevLidAngle + (te.adjacentChestXNeg.lidAngle - te.adjacentChestXNeg.prevLidAngle) * partialTicks;
            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();
        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 17 with BlockChest

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

the class TileEntityKeypadChestRenderer method func_180538_a.

public void func_180538_a(TileEntityChest p_180538_1_, double p_180538_2_, double p_180538_4_, double p_180538_6_, float p_180538_8_, int p_180538_9_) {
    int j;
    if (!p_180538_1_.hasWorldObj())
        j = 0;
    else {
        Block block = p_180538_1_.getBlockType();
        j = p_180538_1_.getBlockMetadata();
        if (block instanceof BlockChest && j == 0) {
            ((BlockChest) block).checkForSurroundingChests(p_180538_1_.getWorld(), p_180538_1_.getPos(), p_180538_1_.getWorld().getBlockState(p_180538_1_.getPos()));
            j = p_180538_1_.getBlockMetadata();
        }
        p_180538_1_.checkForAdjacentChests();
    }
    if (p_180538_1_.adjacentChestZNeg == null && p_180538_1_.adjacentChestXNeg == null) {
        ModelChest modelchest;
        if (p_180538_1_.adjacentChestXPos == null && p_180538_1_.adjacentChestZPos == null) {
            modelchest = field_147510_h;
            if (p_180538_9_ >= 0) {
                bindTexture(DESTROY_STAGES[p_180538_9_]);
                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 if (field_147509_j)
                bindTexture(christmasNormal);
            else if (p_180538_1_.lidAngle >= 0.9)
                bindTexture(normalSingleActive);
            else
                bindTexture(normalSingleUnactive);
        } else {
            modelchest = field_147511_i;
            if (p_180538_9_ >= 0) {
                bindTexture(DESTROY_STAGES[p_180538_9_]);
                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 if (field_147509_j)
                bindTexture(christmasDouble);
            else if (p_180538_1_.lidAngle >= 0.9)
                bindTexture(normalDoubleActive);
            else
                bindTexture(normalDoubleUnactive);
        }
        GlStateManager.pushMatrix();
        GlStateManager.enableRescaleNormal();
        if (p_180538_9_ < 0)
            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.translate((float) p_180538_2_, (float) p_180538_4_ + 1.0F, (float) p_180538_6_ + 1.0F);
        GlStateManager.scale(1.0F, -1.0F, -1.0F);
        GlStateManager.translate(0.5F, 0.5F, 0.5F);
        short short1 = 0;
        if (j == 2)
            short1 = 180;
        if (j == 3)
            short1 = 0;
        if (j == 4)
            short1 = 90;
        if (j == 5)
            short1 = -90;
        if (j == 2 && p_180538_1_.adjacentChestXPos != null)
            GlStateManager.translate(1.0F, 0.0F, 0.0F);
        if (j == 5 && p_180538_1_.adjacentChestZPos != null)
            GlStateManager.translate(0.0F, 0.0F, -1.0F);
        GlStateManager.rotate(short1, 0.0F, 1.0F, 0.0F);
        GlStateManager.translate(-0.5F, -0.5F, -0.5F);
        float f1 = p_180538_1_.prevLidAngle + (p_180538_1_.lidAngle - p_180538_1_.prevLidAngle) * p_180538_8_;
        float f2;
        if (p_180538_1_.adjacentChestZNeg != null) {
            f2 = p_180538_1_.adjacentChestZNeg.prevLidAngle + (p_180538_1_.adjacentChestZNeg.lidAngle - p_180538_1_.adjacentChestZNeg.prevLidAngle) * p_180538_8_;
            if (f2 > f1)
                f1 = f2;
        }
        if (p_180538_1_.adjacentChestXNeg != null) {
            f2 = p_180538_1_.adjacentChestXNeg.prevLidAngle + (p_180538_1_.adjacentChestXNeg.lidAngle - p_180538_1_.adjacentChestXNeg.prevLidAngle) * p_180538_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();
        GlStateManager.disableRescaleNormal();
        GlStateManager.popMatrix();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        if (p_180538_9_ >= 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 18 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 19 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 20 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)

Aggregations

BlockChest (net.minecraft.block.BlockChest)26 Block (net.minecraft.block.Block)23 TileEntity (net.minecraft.tileentity.TileEntity)10 ModelChest (net.minecraft.client.model.ModelChest)9 IInventory (net.minecraft.inventory.IInventory)9 IBlockState (net.minecraft.block.state.IBlockState)8 TileEntityChest (net.minecraft.tileentity.TileEntityChest)7 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStack (net.minecraft.item.ItemStack)3 ILockableContainer (net.minecraft.world.ILockableContainer)3 List (java.util.List)2 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 Entity (net.minecraft.entity.Entity)2 Container (net.minecraft.inventory.Container)2