Jump to content

Minecraft sets Both NBTTags equal


Kloonder

Recommended Posts

Hey guys, I don't know why, but Minecraft sets the NBTTags of two ItemStacks equal. So I mean, I wrote this code:

slots[2].stackTagCompound = slots[1].stackTagCompound

But my problem is, every time I change the NBt from slots[2], it also changes slots[1], I think the solution is really simple and I'm also not new in Java, but sometimes even a good java programer gets stick in something easy java, sorry for that :)

 

public void updateEntity(){ 
	if(slots[2] == null && rh.getWorkingItemGroupBasedRecipe(slots) != -1 && System.currentTimeMillis() -10 > lastCrafted && !(System.currentTimeMillis()-50 > lastCrafted)){
		System.out.println("Gecraftet");
	}

	this.slots[2] = rh.addOutputSlotManagerforItemBase(slots, 2);
	if(rh.getWorkingItemGroupBasedRecipe(slots) != -1){
		lastCrafted = System.currentTimeMillis();
	}
	if(ItemStack.areItemStacksEqual(slots[1], slots[2])){
		System.out.println("Gleich");
	}
	craftingSystem();
	this.openInventory();
}

private void craftingSystem() {

	if(slots[0] != null && slots[1] != null){
		if((slots[0].getItem() == Extrashoes.SingleJetBoot || slots[0].getItem() == Extrashoes.JetBoots) && ItemGroup.isItemPartofItemGroup(slots[1].getItem(), Extrashoes.ModifiableShoesGroup)){
			handleJetStuff();
		}
	}


}

private void handleJetStuff(){

	if(slots[0].getItem() == Extrashoes.SingleJetBoot){
		if(!slots[1].stackTagCompound.getBoolean("Jetboots")){
			if(slots[1] != slots[2]){
				slots[2] = null;
				slots[2] = new ItemStack(Extrashoes.ModifiableShoe[Extrashoes.ModifiableShoesGroup.getNumberofIteminItemGroup(slots[1].getItem(), Extrashoes.ModifiableShoesGroup)]);
				slots[2].stackTagCompound = slots[1].stackTagCompound;
				slots[2].stackTagCompound.setString("TypeofBoot", "golden_boots");
				if(slots[2].stackTagCompound.getBoolean("SingleJetBoot")){

					if(slots[2].stackTagCompound.getDouble("Remaining Weight") > 5){
						slots[2].stackTagCompound.setBoolean("JetBoots", true);
						slots[2].stackTagCompound.setBoolean("SingleJetBoot", false);
						double rw = slots[2].stackTagCompound.getDouble("Remaining Weight");
						slots[2].stackTagCompound.setDouble("Remaining Weight", rw - 5);
					}
				}else{
					if(slots[2].stackTagCompound.getDouble("Remaining Weight") > 5){
						slots[2].stackTagCompound.setBoolean("SingleJetBoot", true);
						double rw = slots[2].stackTagCompound.getDouble("Remaining Weight");
						slots[2].stackTagCompound.setDouble("Remaining Weight", rw - 5);
					}
				}
			}
		}
	}
}

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Link to comment
Share on other sites

Take this code:

Object a = new Object();
Object b = a;

 

Both variables point to the same object! Variables are just pointers that point to an Object. If you change that object, all the variables stay the same, they still point to the same object. But of course the contents of the object then has changed in all the variables, because they point to the same thing.

You probably want to create a copy of the NBT, use .copy().

OMG thank you, I really forgot that, now it works thank you :D

 

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

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.



×
×
  • Create New...

Important Information

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