Jump to content

Possible to use NBTTagCompound in a Gui


zhscraft

Recommended Posts

not sure what to do to figure this out unless you have to put readFromNBT and write a certain way

 

 

 public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        GuiJumper.HeighLevel = par1NBTTagCompound.getInteger("HeighLevel");
        GuiJumper.isSelected = par1NBTTagCompound.getInteger("isSelected");

        GuiJumper.NORTHDIST = par1NBTTagCompound.getInteger("NORTHDIST");
        GuiJumper.SOUTHDIST = par1NBTTagCompound.getInteger("SOUTHDIST");
        GuiJumper.EASTDIST = par1NBTTagCompound.getInteger("EASTDIST");
        GuiJumper.WESTDIST = par1NBTTagCompound.getInteger("WESTDIST");
        
        //BlockJumper.Cname = par1NBTTagCompound.getString("Cname");

    }

    /**
     * Writes a tile entity to NBT.
     */
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setInteger("HeighLevel", GuiJumper.HeighLevel);
        par1NBTTagCompound.setInteger("isSelected", GuiJumper.isSelected);
        
        par1NBTTagCompound.setInteger("NORTHDIST", GuiJumper.NORTHDIST);
        par1NBTTagCompound.setInteger("SOUTHDIST", GuiJumper.SOUTHDIST);
        par1NBTTagCompound.setInteger("EASTDIST", GuiJumper.EASTDIST);
        par1NBTTagCompound.setInteger("WESTDIST", GuiJumper.WESTDIST);
        
        //par1NBTTagCompound.setString("Cname", BlockJumper.Cname);
        System.out.println("writeToNBT");
    }

 

 

Link to comment
Share on other sites

here's what I did to get access to things in my tileentity with the gui

public NAME_OF_GUI(InventoryPlayer inventoryPlayer,
                        TILEENTITY tileEntity) {
                //the container is instanciated and passed to the superclass for handling
                super(new CONTAINER(inventoryPlayer, tileEntity));
                this.ySize = 200;
                this.xSize = 234;
                VARIEABLE_NAME = tileEntity;
        }
        
        public TILEENTITY VARIEABLE_NAME ;

and then i just access the stuff in my tileentity by doing

tsc.STUFF_FROM_THE_TILEENTITY

Link to comment
Share on other sites

alright here is all the files being used

 

TileEntityJumper.class

package ZCraft.Manager.Jumper;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import ZCraft.Blocks.BlockJumper;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.WeightedRandom;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class TileEntityJumper extends TileEntity
{

    public TileEntityJumper()
    {

    }






    /**
     * Reads a tile entity from NBT.
     */
    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        GuiJumper.HeighLevel = par1NBTTagCompound.getInteger("HeighLevel");
        GuiJumper.isSelected = par1NBTTagCompound.getInteger("isSelected");

        GuiJumper.NORTHDIST = par1NBTTagCompound.getInteger("NORTHDIST");
        GuiJumper.SOUTHDIST = par1NBTTagCompound.getInteger("SOUTHDIST");
        GuiJumper.EASTDIST = par1NBTTagCompound.getInteger("EASTDIST");
        GuiJumper.WESTDIST = par1NBTTagCompound.getInteger("WESTDIST");
        
        //BlockJumper.Cname = par1NBTTagCompound.getString("Cname");

    }

    /**
     * Writes a tile entity to NBT.
     */
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setInteger("HeighLevel", GuiJumper.HeighLevel);
        par1NBTTagCompound.setInteger("isSelected", GuiJumper.isSelected);
        
        par1NBTTagCompound.setInteger("NORTHDIST", GuiJumper.NORTHDIST);
        par1NBTTagCompound.setInteger("SOUTHDIST", GuiJumper.SOUTHDIST);
        par1NBTTagCompound.setInteger("EASTDIST", GuiJumper.EASTDIST);
        par1NBTTagCompound.setInteger("WESTDIST", GuiJumper.WESTDIST);
        
        //par1NBTTagCompound.setString("Cname", BlockJumper.Cname);
        System.out.println("writeToNBT");
    }

   
}

 

GuiJumper.class

package ZCraft.Manager.Jumper;


import ZCraft.Blocks.BlockExtendChestIron;
import ZCraft.Blocks.BlockJumper;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiOptions;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiShareToLan;
import net.minecraft.client.gui.achievement.GuiAchievements;
import net.minecraft.client.gui.achievement.GuiStats;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.stats.StatList;
import net.minecraft.util.StatCollector;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiJumper extends GuiScreen
{
    /** Also counts the number of updates, not certain as to why yet. */
    private int updateCounter2 = 0;

    /** Counts the number of screen updates. */
    private int updateCounter = 0;

    /**
     * Adds the buttons (and other controls) to the screen in question.
     */
    
    public static int isSelected;
    public static String DirText;
    public static int NORTHDIST;
    public static int SOUTHDIST;
    public static int EASTDIST;
    public static int WESTDIST;
    public static int HeighLevel;
    public void initGui()
    {
        this.updateCounter2 = 0;
        this.controlList.clear();

        this.controlList.add(new GuiButton(0, 100,50,40,12, "NORTH"));
        this.controlList.add(new GuiButton(1, 100,50 + 13,40,12, "SOUTH"));
        this.controlList.add(new GuiButton(2, 100,50 + 13 + 13,40,12, "EAST"));
        this.controlList.add(new GuiButton(3, 100,50 + 13 + 13+13,40,12, "WEST"));
        this.controlList.add(new GuiButton(4, 100,50 + 59,40,12, "Height"));
        
        this.controlList.add(new GuiButton(5, 100,50 + 59 + 13,80,12, "NORTH DIST"));
        this.controlList.add(new GuiButton(6, 100,50 + 59 + 13 + 13,80,12, "SOUTH DIST"));
        this.controlList.add(new GuiButton(7, 100,50 + 59 + 13 + 13 + 13,80,12, "WEST DIST"));
        this.controlList.add(new GuiButton(8, 100,50 + 59 + 13 + 13 + 13 + 13,80,12, "EAST DIST"));
    }

    

    
    protected void actionPerformed(GuiButton par1GuiButton)
    {
        switch (par1GuiButton.id)
        {
            case 0:
            	isSelected = 0;//          	
            	DirText = "NORTH";
            	this.updateScreen();
            	break;
            case 1:
            	isSelected = 1;//
            	DirText = "SOUTH";
            	this.updateScreen();
            	break;
            case 2:
               	isSelected = 3;//
            	DirText = "EAST";
            	this.updateScreen();
            	break;
            case 3:
               	isSelected = 4;//
            	DirText = "WEST";
            	this.updateScreen();
            	break;
            case 4:
            	if(HeighLevel >= 0 && HeighLevel <= 9){
            		HeighLevel = HeighLevel + 1;
            	
            		
            	}else{
            		HeighLevel = 1;
            	}
            	break;
            case 5:
            	if(NORTHDIST >= -9 && NORTHDIST <= 0){
            		NORTHDIST = NORTHDIST - 1;
            	}else{
            		NORTHDIST = -1;
            	}
            	break;
            case 6:
            	if(SOUTHDIST >= 0 && SOUTHDIST <= 9){
            		SOUTHDIST = SOUTHDIST + 1;
            	}else{
            		SOUTHDIST = 1;
            	}
            	break;
            case 7:
            	if(WESTDIST >= -9 && WESTDIST <= 0){
            		WESTDIST = WESTDIST - 1;
            	}else{
            		WESTDIST = -1;
            	}
            	break;
            case 8:
            	if(EASTDIST >= 0 && EASTDIST <= 9){
            		EASTDIST = EASTDIST + 1;
            	}else{
            		EASTDIST =  1;
            	}
            	break;
        }
    }

    /**
     * Called from the main game loop to update the screen.
     */
    public void updateScreen()
    {
        super.updateScreen();
        ++this.updateCounter;
    }

    /**
     * Draws the screen and all the components in it.
     */
    public void drawScreen(int par1, int par2, float par3)
    {
    	
        this.drawDefaultBackground();
       
        
        //System.out.println(NBTTest);
        this.drawCenteredString(this.fontRenderer, "Last Rider " + BlockJumper.Cname, this.width / 2, 40 - 10, 16777215);
        this.drawCenteredString(this.fontRenderer, "Jumper Controls", this.width / 2, 40, 16777215);
        	this.drawString(this.fontRenderer, "Dir is " + DirText, 200, 50, 4159186);
        	this.drawString(this.fontRenderer, "Height is " + HeighLevel, 200, 60, 4159186);
        	this.drawString(this.fontRenderer, "NORTH DIST is " + NORTHDIST, 200, 80, 4159186);
        	this.drawString(this.fontRenderer, "SOUTH DIST is " + SOUTHDIST, 200, 90, 4159186);
        	this.drawString(this.fontRenderer, "WEST DIST is " + WESTDIST, 200, 110, 4159186);
        	this.drawString(this.fontRenderer, "EAST DIST is " + EASTDIST, 200, 120, 4159186);
        super.drawScreen(par1, par2, par3);
    }
}

 

BlockJumper.class

package ZCraft.Blocks;

import static net.minecraftforge.common.ForgeDirection.DOWN;

import java.util.Iterator;
import java.util.Random;

import ZCraft.ZCraft;
import ZCraft.Manager.IronChestExtended.TileEntityExtednedIronChest;
import ZCraft.Manager.Jumper.TileEntityJumper;
import ZCraft.Manager.Jumper.GuiJumper;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerEvent;

public class BlockJumper  extends BlockContainer
{
    private Random random = new Random();

    protected BlockJumper(int par1)
    {
        super(par1, Material.wood);
        this.setCreativeTab(ZCraft.ZCraftTab);
      
    }

public String getTextureFile(){
	return "/ZCraft/ZCraftSheet.png/";

}

public int getBlockTextureFromSide(int i)
    {
        return 5;
    }

public static String Cname;
    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer player, int par6, float par7, float par8, float par9)
    {
    	//Cname = player.username;
    	Object var10 = (TileEntityJumper)par1World.getBlockTileEntity(par2, par3, par4);
    	if(player.isSneaking() == true){
    		if(GuiJumper.isSelected == 0){//north
           		player.setVelocity(0, GuiJumper.HeighLevel, GuiJumper.NORTHDIST);
        		}else
        			if(GuiJumper.isSelected == 1){//south
        	       		player.setVelocity(0, GuiJumper.HeighLevel, GuiJumper.SOUTHDIST);
        	    		}else
        	    			if(GuiJumper.isSelected == 3){
                	       		player.setVelocity(GuiJumper.EASTDIST, GuiJumper.HeighLevel, 0);
                	    		}else
                	    			if(GuiJumper.isSelected == 4){//west
                        	       		player.setVelocity(GuiJumper.WESTDIST, GuiJumper.HeighLevel, 0);
                        	    		}
    		
    		return true;
    	}else{
    		player.displayGUIJumper();
    		return false;
    	}
    	
    }

@Override
public TileEntity createNewTileEntity(World var1) {
	// TODO Auto-generated method stub
	return new TileEntityJumper();
}
    
    
   
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.