Search in sources :

Example 1 with TileEntityBed

use of net.minecraft.tileentity.TileEntityBed in project ElementalSorcery by Yuzunyannn.

the class EntityBlockMove method putBlock.

public static ItemStack putBlock(World world, @Nullable EntityPlayer player, BlockPos to, ItemStack stack, @Nullable IBlockState state, @Nullable EnumFacing facing, @Nullable NBTTagCompound tileSave, boolean forcePut) {
    if (!BlockHelper.isReplaceBlock(world, to) && !forcePut)
        return stack;
    facing = facing == null ? getFacingFromState(state) : facing;
    // 放置方块
    Item item = stack.getItem();
    if (item instanceof ItemBlock) {
        ItemBlock itemBlock = (ItemBlock) item;
        IBlockState toState = itemBlock.getBlock().getStateFromMeta(stack.getItemDamage());
        if (world.isRemote) {
            world.setBlockState(to, toState);
            return ItemStack.EMPTY;
        }
        Block block = toState.getBlock();
        if (block == Blocks.PISTON || block == Blocks.STICKY_PISTON) {
            // 活塞
            if (state != null)
                toState = state.withProperty(BlockPistonBase.EXTENDED, false);
            else
                toState = toState.withProperty(BlockPistonBase.FACING, facing);
            world.setBlockState(to, toState);
        } else {
            if (state != null) {
                if (state.getBlock() == Blocks.UNLIT_REDSTONE_TORCH) {
                    // 红石火把
                    facing = state.getValue(BlockRedstoneTorch.FACING);
                    toState = toState.withProperty(BlockRedstoneTorch.FACING, facing);
                } else {
                    if (itemBlock instanceof ItemSlab)
                        toState = state;
                    else if (itemBlock.getBlock() == state.getBlock())
                        toState = state;
                }
            }
            boolean needPlace = false;
            needPlace = needPlace || block instanceof BlockDoublePlant || block instanceof ITileEntityProvider;
            if (needPlace) {
                if (player == null)
                    player = ESFakePlayer.get((WorldServer) world);
                itemBlock.placeBlockAt(stack, player, world, to, EnumFacing.UP, 0, 0, 0, toState);
            } else
                world.setBlockState(to, toState);
            loadTileSave(world, to, tileSave);
        }
        return ItemStack.EMPTY;
    } else if (stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null) != null) {
        // 液体
        IFluidHandlerItem fhi = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
        FluidStack fstack = fhi.drain(1000, true);
        if (fstack != null) {
            IBlockState fluidState = fstack.getFluid().getBlock().getDefaultState();
            world.setBlockState(to, fluidState);
        // world.notifyBlockUpdate(to, fluidState, fluidState, 0);
        }
        return fhi.getContainer();
    } else if (item == Items.BED) {
        // 床
        if (state == null)
            return stack;
        facing = state.getValue(BlockBed.FACING);
        world.setBlockState(to, state);
        world.setBlockState(to.offset(facing), state.cycleProperty(BlockBed.PART));
        TileEntityBed bed = BlockHelper.getTileEntity(world, to, TileEntityBed.class);
        if (bed != null)
            bed.setColor(EnumDyeColor.byMetadata(stack.getMetadata()));
        bed = BlockHelper.getTileEntity(world, to.offset(facing), TileEntityBed.class);
        if (bed != null)
            bed.setColor(EnumDyeColor.byMetadata(stack.getMetadata()));
        return ItemStack.EMPTY;
    } else if (item instanceof ItemDoor) {
        if (state == null)
            return stack;
        ItemDoor.placeDoor(world, to, facing.rotateY(), state.getBlock(), false);
        return ItemStack.EMPTY;
    } else if (state != null) {
        world.setBlockState(to, state);
        loadTileSave(world, to, tileSave);
        return ItemStack.EMPTY;
    }
    return stack;
}
Also used : Item(net.minecraft.item.Item) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) IBlockState(net.minecraft.block.state.IBlockState) ItemDoor(net.minecraft.item.ItemDoor) ItemSlab(net.minecraft.item.ItemSlab) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) BlockDoublePlant(net.minecraft.block.BlockDoublePlant) ItemBlock(net.minecraft.item.ItemBlock) TileEntityBed(net.minecraft.tileentity.TileEntityBed)

Example 2 with TileEntityBed

use of net.minecraft.tileentity.TileEntityBed in project CumServerPro by MCUmbrella.

the class BlockBed method getItem.

public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
    BlockPos blockpos = pos;
    if (state.getValue(PART) == EnumPartType.FOOT) {
        blockpos = pos.offset((EnumFacing) state.getValue(FACING));
    }
    TileEntity tileentity = worldIn.getTileEntity(blockpos);
    EnumDyeColor enumdyecolor = tileentity instanceof TileEntityBed ? ((TileEntityBed) tileentity).getColor() : EnumDyeColor.RED;
    return new ItemStack(Items.BED, 1, enumdyecolor.getMetadata());
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EnumDyeColor(net.minecraft.item.EnumDyeColor) TileEntityBed(net.minecraft.tileentity.TileEntityBed)

Example 3 with TileEntityBed

use of net.minecraft.tileentity.TileEntityBed in project CumServerPro by MCUmbrella.

the class BlockBed method dropBlockAsItemWithChance.

public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
    if (state.getValue(PART) == EnumPartType.HEAD) {
        TileEntity tileentity = worldIn.getTileEntity(pos);
        EnumDyeColor enumdyecolor = tileentity instanceof TileEntityBed ? ((TileEntityBed) tileentity).getColor() : EnumDyeColor.RED;
        spawnAsEntity(worldIn, pos, new ItemStack(Items.BED, 1, enumdyecolor.getMetadata()));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ItemStack(net.minecraft.item.ItemStack) EnumDyeColor(net.minecraft.item.EnumDyeColor) TileEntityBed(net.minecraft.tileentity.TileEntityBed)

Example 4 with TileEntityBed

use of net.minecraft.tileentity.TileEntityBed in project CumServerPro by MCUmbrella.

the class BlockBed method harvestBlock.

public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) {
    if (state.getValue(PART) == EnumPartType.HEAD && te instanceof TileEntityBed) {
        TileEntityBed tileentitybed = (TileEntityBed) te;
        ItemStack itemstack = tileentitybed.getItemStack();
        spawnAsEntity(worldIn, pos, itemstack);
    } else {
        super.harvestBlock(worldIn, player, pos, state, (TileEntity) null, stack);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) TileEntityBed(net.minecraft.tileentity.TileEntityBed)

Example 5 with TileEntityBed

use of net.minecraft.tileentity.TileEntityBed in project CumServerPro by MCUmbrella.

the class NetHandlerPlayClient method handleUpdateTileEntity.

public void handleUpdateTileEntity(SPacketUpdateTileEntity packetIn) {
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
    if (this.gameController.world.isBlockLoaded(packetIn.getPos())) {
        TileEntity tileentity = this.gameController.world.getTileEntity(packetIn.getPos());
        int i = packetIn.getTileEntityType();
        boolean flag = i == 2 && tileentity instanceof TileEntityCommandBlock;
        if (i == 1 && tileentity instanceof TileEntityMobSpawner || flag || i == 3 && tileentity instanceof TileEntityBeacon || i == 4 && tileentity instanceof TileEntitySkull || i == 5 && tileentity instanceof TileEntityFlowerPot || i == 6 && tileentity instanceof TileEntityBanner || i == 7 && tileentity instanceof TileEntityStructure || i == 8 && tileentity instanceof TileEntityEndGateway || i == 9 && tileentity instanceof TileEntitySign || i == 10 && tileentity instanceof TileEntityShulkerBox || i == 11 && tileentity instanceof TileEntityBed) {
            tileentity.readFromNBT(packetIn.getNbtCompound());
        } else {
            if (tileentity == null) {
                LOGGER.error("Received invalid update packet for null tile entity at {} with data: {}", packetIn.getPos(), packetIn.getNbtCompound());
                return;
            }
            tileentity.onDataPacket(netManager, packetIn);
        }
        if (flag && this.gameController.currentScreen instanceof GuiCommandBlock) {
            ((GuiCommandBlock) this.gameController.currentScreen).updateGui();
        }
    }
}
Also used : TileEntityBeacon(net.minecraft.tileentity.TileEntityBeacon) GuiCommandBlock(net.minecraft.client.gui.GuiCommandBlock) TileEntityStructure(net.minecraft.tileentity.TileEntityStructure) TileEntityCommandBlock(net.minecraft.tileentity.TileEntityCommandBlock) TileEntityShulkerBox(net.minecraft.tileentity.TileEntityShulkerBox) TileEntityBed(net.minecraft.tileentity.TileEntityBed) TileEntityEndGateway(net.minecraft.tileentity.TileEntityEndGateway) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntitySign(net.minecraft.tileentity.TileEntitySign) TileEntitySkull(net.minecraft.tileentity.TileEntitySkull) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner) TileEntityFlowerPot(net.minecraft.tileentity.TileEntityFlowerPot) TileEntityBanner(net.minecraft.tileentity.TileEntityBanner)

Aggregations

TileEntityBed (net.minecraft.tileentity.TileEntityBed)16 TileEntity (net.minecraft.tileentity.TileEntity)10 ItemStack (net.minecraft.item.ItemStack)9 EnumDyeColor (net.minecraft.item.EnumDyeColor)6 BlockPos (net.minecraft.util.math.BlockPos)5 EnumFacing (net.minecraft.util.EnumFacing)3 IBlockState (net.minecraft.block.state.IBlockState)2 GuiCommandBlock (net.minecraft.client.gui.GuiCommandBlock)2 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)2 TileEntityBanner (net.minecraft.tileentity.TileEntityBanner)2 TileEntityBeacon (net.minecraft.tileentity.TileEntityBeacon)2 TileEntityCommandBlock (net.minecraft.tileentity.TileEntityCommandBlock)2 TileEntityEndGateway (net.minecraft.tileentity.TileEntityEndGateway)2 TileEntityFlowerPot (net.minecraft.tileentity.TileEntityFlowerPot)2 TileEntityMobSpawner (net.minecraft.tileentity.TileEntityMobSpawner)2 TileEntityShulkerBox (net.minecraft.tileentity.TileEntityShulkerBox)2 TileEntitySign (net.minecraft.tileentity.TileEntitySign)2 TileEntitySkull (net.minecraft.tileentity.TileEntitySkull)2 TileEntityStructure (net.minecraft.tileentity.TileEntityStructure)2 Lists (com.google.common.collect.Lists)1