- 1
- 0
Block:
public class SleepingBag extends Block implements ITileEntityProvider {
public int rotationAngle;
public SleepingBag() {
super(Material.cloth);
this.setCreativeTab(CreativeTabs.tabCombat);
this.setBlockName("SleepingBag");
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F);
}
public void onBlockPlacedBy(World w, int x, int y, int z, EntityLivingBase e, ItemStack i) {
SleepingBagTileEntity tile = (SleepingBagTileEntity) w.getTileEntity(x, y, z);
tile.setOwner(player.getCommandSenderName());
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new SleepingBagTileEntity();
}
public int getRenderType() {
return -1;
}
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
}
SleepingBagTileEntity:
public class SleepingBagTileEntity extends TileEntity {
public String owner;
public SleepingBagTileEntity() {
}
public void safeRead(NBTTagCompound tag) {
this.owner = tag.getString("owner");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
this.safeWrite(tag);
}
public void safeWrite(NBTTagCompound tag) {
tag.setString("owner", this.owner);
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(super.xCoord, super.yCoord, super.zCoord, 0, nbttagcompound);
}
public AxisAlignedBB getRenderBoundingBox() {
return TileEntity.INFINITE_EXTENT_AABB;
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
this.readFromNBT(packet.func_148857_g());
}
public double getMaxRenderDistanceSquared() {
return 8192.0D;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
}