Jump to content

Recommended Posts

Posted

I want to use the NBT I have made in one class, in another, how would I do this and here is my code

 

NBT

 

  Reveal hidden contents

 

 

GUI

 

 

  Reveal hidden contents

 

Posted
  On 11/2/2014 at 11:49 AM, diesieben07 said:

Grmbl, you still have

UniquePin

and

balance

as fields in your Item class. This does not work! You have to use the ItemStack every time you want to access those values. You cannot store them in the Item class.

 

For accessing those values from your Gui: Use the ItemStack, just like you do in your Item class already. For writing values to it from a Gui you will need packets though, as a Gui is client-only and you cannot change things in the world/in inventories/etc. from the client.

 

So like this?

itemStack.stackTagCompound = new NBTTagCompound();
	    	 itemStack.stackTagCompound.setString("owner", player.getDisplayName());
	    	 itemStack.stackTagCompound.setInteger("pin", 1000 + (int)(Math.random()*9999));

Posted
  On 11/2/2014 at 12:28 PM, diesieben07 said:

That would overwrite any previous data, yes. I suggest you only create a new NBTTagCompound if stackTagCompound is null, to avoid overwriting any previous data like e.g. Enchantments.

Also you should not store the display name. It potentially includes stuff like color codes and stuff. Use the UUID for the player, as Mojang will soon allow username changes.

 

So, how would I get the pin into my gui class, I used this but it gave me a null pointer

if(enteredPin.equals(itemstack.stackTagCompound.getString("pin")))

Posted

Either

enteredPin

,

itemstack

or

stackTagCompound

null. Put a breakpoint on that line so you can see which was is null.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
  On 11/2/2014 at 12:38 PM, larsgerrits said:

Either

enteredPin

,

itemstack

or

stackTagCompound

null. Put a breakpoint on that line so you can see which was is null.

 

Here is the whole class. I think that the itemstack might be null

package com.bugzoo.FinancialMod;

import java.io.IOException;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;



public class ATMPinGUI extends GuiContainer{
public final int xSizeBackground1 = 232;
public final int ySizeBackground1 = 240;

private String enteredPin = "";
private String underScore = "";
private int tick = 0;

public ItemStack itemstack;


public final int guiX = (this.width - xSizeBackground1) / 2;
public final int guiY = (this.height - xSizeBackground1) / 2;

public ResourceLocation background1 = new ResourceLocation("financialmod", "textures/gui/ATM.png");


public ATMPinGUI(InventoryPlayer player, TileEntityATM atm){
	super(new ContainerATM(player, atm));
}


public void initGui(){
	buttonList.clear();
	buttonList.add(new ATMButton(1, guiLeft + 181, guiTop + 149, 24, 15, "1")); // 1
    	buttonList.add(new ATMButton(2, guiLeft + 213, guiTop + 149, 24, 15, "2")); // 2
    	buttonList.add(new ATMButton(3, guiLeft + 245, guiTop + 149, 24, 15, "3")); // 3
    	buttonList.add(new ATMRedButton(4, guiLeft + 281, guiTop + 149, 24, 15, "")); // Cancel
    	buttonList.add(new ATMButton(5, guiLeft + 181, guiTop + 173, 24, 15, "4")); // 4
    	buttonList.add(new ATMButton(6, guiLeft + 213, guiTop + 173, 24, 15, "5")); // 5
    	buttonList.add(new ATMButton(7, guiLeft + 245, guiTop + 173, 24, 15, "6")); // 6
    	buttonList.add(new ATMYellowButton(8, guiLeft + 281, guiTop + 173, 24, 15, "")); // Clear
    	buttonList.add(new ATMButton(9, guiLeft + 181, guiTop + 197, 24, 15, "7")); // 7
    	buttonList.add(new ATMButton(10, guiLeft + 213, guiTop + 197, 24, 15, "8")); // 8
    	buttonList.add(new ATMButton(11, guiLeft + 245, guiTop + 197, 24, 15, "9")); // 9
    	buttonList.add(new ATMConfirmButton(12, guiLeft + 281, guiTop + 197, 24, 15, "")); // Confirm
    	buttonList.add(new ATMButton(13, guiLeft + 213, guiTop + 221, 24, 15, "0")); // 0

    	buttonList.add(new ATMLeftButton(14, guiLeft + 130, guiTop + 33, 24, 15, "")); //Top-Left
    	buttonList.add(new ATMLeftButton(15, guiLeft + 130, guiTop + 60, 24, 15, "")); //Mid-Upper Left
    	buttonList.add(new ATMLeftButton(16, guiLeft + 130, guiTop + 87, 24, 15, "")); //Mid-Lower Left
    	buttonList.add(new ATMLeftButton(17, guiLeft + 130, guiTop + 114, 24, 15, "")); //Bottom Left
    	
    	buttonList.add(new ATMRightButton(18, guiLeft + 325, guiTop + 33, 24, 15, "")); //Top-Right
    	buttonList.add(new ATMRightButton(19, guiLeft + 325, guiTop + 60, 24, 15, "")); //Mid-Upper Right
    	buttonList.add(new ATMRightButton(20, guiLeft + 325, guiTop + 87, 24, 15, "")); //Mid-Lower Right
    	buttonList.add(new ATMRightButton(21, guiLeft + 325, guiTop + 114, 24, 15, "")); //Bottom Right

}

public void actionPerformed(GuiButton guibutton){
	if(guibutton.id==1){
		enteredPin = enteredPin + "1";
		System.out.println(enteredPin);
	}
	if(guibutton.id==2){
		enteredPin = enteredPin + "2";
		System.out.println(enteredPin);
	}
	if(guibutton.id==3){
		enteredPin = enteredPin + "3";
		System.out.println(enteredPin);
	}
	if(guibutton.id==4){
		this.enteredPin = "";
	}
	if(guibutton.id==5){
		enteredPin = enteredPin + "4";
		System.out.println(enteredPin);
	}
	if(guibutton.id==6){
		enteredPin = enteredPin + "5";
		System.out.println(enteredPin);
	}
	if(guibutton.id==7){
		enteredPin = enteredPin + "6";
		System.out.println(enteredPin);
	}
	if(guibutton.id=={


		/*String URL = "https://www.google.co.uk/search?q=atm+screen&client=firefox-a&hs=KRv&rls=org.mozilla:en-GB:official&channel=np&tbm=isch&imgil=4qxgegDeEWCSaM%253A%253BMH8IbcHAhg9-3M%253Bhttps%25253A%25252F%25252Fsufiazamir.wordpress.com%25252Ftag%25252Fatm-screens%25252F&source=iu&pf=m&fir=4qxgegDeEWCSaM%253A%252CMH8IbcHAhg9-3M%252C_&usg=__0fIcaFRq-6p0shy1i8dW3VNWoa4%3D&biw=1536&bih=755&ved=0CC4Qyjc&ei=MRlWVPz-FOat7AaP04HwCw#facrc=_&imgdii=_&imgrc=Hxd6rXd8p_O0NM%253A%3B4r3sPIEVxepLfM%3Bhttp%253A%252F%252Fzesty.ca%252Flj%252Flusaka-atm-3.jpg%3Bhttp%253A%252F%252Fzestyping.livejournal.com%252F251102.html%3B400%3B300";
		try {
			java.awt.Desktop.getDesktop().browse(java.net.URI.create(URL));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
	}
	if(guibutton.id==9){
		enteredPin = enteredPin + "7";
		System.out.println(enteredPin);
	}
	if(guibutton.id==10){
		enteredPin = enteredPin + "8";
		System.out.println(enteredPin);
	}
	if(guibutton.id==11){
		enteredPin = enteredPin + "9";
		System.out.println(enteredPin);
	}
	if(guibutton.id==12){
		if(enteredPin.equals(itemstack.stackTagCompound.getString("pin"))){

		}
	}
}


public boolean doesGuiPauseGame(){
	return false;
}

public void drawScreen(int i, int j, float f){



	//Background Texture
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(background1);
        int k1 = (this.width - this.xSizeBackground1) / 2;
        int l1 = (this.height - this.ySizeBackground1) / 2;
        this.drawTexturedModalRect(k1, l1, 0, 0, this.xSizeBackground1, this.ySizeBackground1);
        
        String underScore = "";
    	if (tick < 60) {
    		tick++;
    	} else if (tick >= 60) {
    		tick = 0;
    	}
    	
    	if (tick < 30) {
    		underScore = "_";
    	}
    	
    	if (enteredPin.length() == 1) {
		drawString(fontRendererObj, "*" + underScore, width - 295, 90, 0xff00);
	} else if (enteredPin.length() == 2) {
		drawString(fontRendererObj, "**" + underScore, width - 295, 90, 0xff00);
	} else if (enteredPin.length() == 3) {
		drawString(fontRendererObj, "***" + underScore, width - 295, 90, 0xff00);
	} else if (enteredPin.length() >= 4) {
		drawString(fontRendererObj, "****" + underScore, width - 295, 90, 0xff00);
	}
        
        this.drawCenteredString(fontRendererObj, "Welcome!", width/2, 45, 0xff00);
        this.drawString(fontRendererObj, "Please Enter Your Pin", width - 295, 60, 0xff00);
        if(enteredPin.length() == 0){
        this.drawString(fontRendererObj, underScore, width - 295, 90, 0xff00);
        }
        super.drawScreen(i, j, f); 
}


@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
		int p_146976_2_, int p_146976_3_) {


}
}

Posted
  On 11/2/2014 at 12:52 PM, larsgerrits said:

Yeah, you don't set the

itemstack

variable anywhere, so how would you expect it to not be null?

 

Ok, so what should I set the itemstack equal to?

ItemStack itemstack = null;
itemstack.stackTagCompound = new NBTTagCompound();
		if(enteredPin.equals(itemstack.stackTagCompound.getString("pin"))){
			System.out.println("The Right Pin!");
		}

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi! I've been running a server on Minecraft using the Prodigium Reforged pack on curse forge using the site exaroton. It was working fine until randomly encountering this error every time anyone tries to connect to the server, I've already reloaded backups and deleted json files  Here is the crash report https://mclo.gs/EwKw51q. Thanks for the help in advance
    • nevermind i figured out the issue  
    • I was trying to host a server with the 1.21.1 cobbleverse forge mod, but when I tried starting it, it kept giving me this error. Crash report here: https://pastebin.com/AsE1X5QY   Thanks
    • This mod lets you choose an element power, Earth, Wind, Fire, or Water. Also two secret element powers Light and Darkness. Each power gives good a bad things, Earth lets you dig through anything but ores and bedrock, Wind lets you jump high in the air every three seconds, Fir lets you throw fire balls and you are immune to any flame/lava but you can't go into water or else you take damage, Water you swim and break blocks under water quicker and you can get rid of water like a sponge but you take more damage when in fire/lava, Light makes you faster at day but slower at night you are able to throw light spears that do four hearts and can go through any armor, Darkness let's you be faster at night but slower at day mobs don't harm you but peaceful mobs run away from you you are able to spawn ink creatures around you that are like dogs but are stronger. another thing in the mod is that there are other dimensions that can get you ores to make better armor and weapons, each dimensions are are good for a certain element though each dimension has a boss depending on which dimension one dimension has more than one boss, each elements are required to defeat the bosses with each others help.
    • Read the posts above yours, it tells you exactly how to do it, instructions are the same if it's making a forge installation or a vanilla one, just make a new folder for the game directory.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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