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;
}
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());
}
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()));
}
}
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);
}
}
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();
}
}
}
Aggregations