Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package buildermod.common;
- import java.io.IOException;
- import cpw.mods.fml.common.FMLCommonHandler;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.resources.IResourceManager;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.network.NetworkManager;
- import net.minecraft.network.Packet;
- import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
- import net.minecraft.server.MinecraftServer;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.AxisAlignedBB;
- import net.minecraft.util.ResourceLocation;
- import net.minecraftforge.common.ForgeModContainer;
- public class TileEntityProjector extends TileEntity {
- ItemStack picture;
- public ResourceLocation location;
- @Override
- public void readFromNBT(NBTTagCompound compound) {
- super.readFromNBT(compound);
- if (compound.hasKey("item")) {
- picture = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("item"));
- setPictureLocation();
- }
- }
- @Override
- public void writeToNBT(NBTTagCompound compound) {
- super.writeToNBT(compound);
- NBTTagCompound item = new NBTTagCompound();
- if (picture != null) picture.writeToNBT(item);
- compound.setTag("item", item);
- }
- @Override
- public Packet getDescriptionPacket() {
- NBTTagCompound compound = new NBTTagCompound();
- if (picture != null) picture.writeToNBT(compound);
- return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, compound);
- }
- @Override
- public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
- NBTTagCompound compound = pkt.func_148857_g();
- if (compound.hasNoTags()) picture = null;
- else picture = ItemStack.loadItemStackFromNBT(compound);
- setPictureLocation();
- worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
- }
- public void setPictureLocation() {
- if (picture == null) location = null;
- else {
- if (picture.hasDisplayName()) {
- location = new ResourceLocation("buildermod:textures/slides/" + picture.getDisplayName() + ".png");
- if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
- IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
- try {
- if (manager.getResource(location) == null) location = null;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- @Override
- @SideOnly(Side.CLIENT)
- public AxisAlignedBB getRenderBoundingBox() {
- return INFINITE_EXTENT_AABB;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public double getMaxRenderDistanceSquared() {
- return 128.0 * 128.0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement