Advertisement
tahg

Untitled

Oct 8th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. package buildermod.common;
  2.  
  3. import java.io.IOException;
  4.  
  5. import cpw.mods.fml.common.FMLCommonHandler;
  6. import cpw.mods.fml.relauncher.Side;
  7. import cpw.mods.fml.relauncher.SideOnly;
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.client.resources.IResourceManager;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.network.NetworkManager;
  13. import net.minecraft.network.Packet;
  14. import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
  15. import net.minecraft.server.MinecraftServer;
  16. import net.minecraft.tileentity.TileEntity;
  17. import net.minecraft.util.AxisAlignedBB;
  18. import net.minecraft.util.ResourceLocation;
  19. import net.minecraftforge.common.ForgeModContainer;
  20.  
  21. public class TileEntityProjector extends TileEntity {
  22. ItemStack picture;
  23. public ResourceLocation location;
  24.  
  25. @Override
  26. public void readFromNBT(NBTTagCompound compound) {
  27. super.readFromNBT(compound);
  28. if (compound.hasKey("item")) {
  29. picture = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("item"));
  30. setPictureLocation();
  31. }
  32. }
  33.  
  34. @Override
  35. public void writeToNBT(NBTTagCompound compound) {
  36. super.writeToNBT(compound);
  37. NBTTagCompound item = new NBTTagCompound();
  38. if (picture != null) picture.writeToNBT(item);
  39. compound.setTag("item", item);
  40. }
  41. @Override
  42. public Packet getDescriptionPacket() {
  43. NBTTagCompound compound = new NBTTagCompound();
  44. if (picture != null) picture.writeToNBT(compound);
  45. return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, compound);
  46. }
  47.  
  48. @Override
  49. public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
  50. NBTTagCompound compound = pkt.func_148857_g();
  51. if (compound.hasNoTags()) picture = null;
  52. else picture = ItemStack.loadItemStackFromNBT(compound);
  53. setPictureLocation();
  54. worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
  55. }
  56.  
  57. public void setPictureLocation() {
  58. if (picture == null) location = null;
  59. else {
  60. if (picture.hasDisplayName()) {
  61. location = new ResourceLocation("buildermod:textures/slides/" + picture.getDisplayName() + ".png");
  62. if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
  63. IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
  64. try {
  65. if (manager.getResource(location) == null) location = null;
  66. } catch (IOException e) {
  67. e.printStackTrace();
  68. }
  69. }
  70. }
  71.  
  72. }
  73. }
  74.  
  75. @Override
  76. @SideOnly(Side.CLIENT)
  77. public AxisAlignedBB getRenderBoundingBox() {
  78. return INFINITE_EXTENT_AABB;
  79. }
  80.  
  81. @Override
  82. @SideOnly(Side.CLIENT)
  83. public double getMaxRenderDistanceSquared() {
  84. return 128.0 * 128.0;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement