Jump to content

[1.7.10] Trouble with stackTagCompound


HappyKiller1O1

Recommended Posts

I do check if it is the server:

if(world.isRemote)
    return;

 

And when it printed out it said this:

[01:38:47] [server thread/INFO] [sTDOUT]: [com.happykiller.crewmod.items.tools.CrewHammer:onCreated:46]: {MiningSize:"1x1",}
[01:38:47] [server thread/INFO] [sTDOUT]: [com.happykiller.crewmod.items.tools.CrewHammer:onCreated:46]: {MiningSize:"3x3",}

 

The fixNBT sets it to 1x1 and then I set it to 3x3. Both of those are called by doing:

System.out.println(stack.stackTagCompound);

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Even when I do that, it would still require me to be able to set and update the nbt for the item from the GUI class.

Yes, but use it instead... It's better...

Are you sure that you are using same tool.

Now, please, if you can, post your final code and console log (with print in stack tag)...

Link to comment
Share on other sites

So, I did what you said but still the same problem. :/ I moved my code under the "onBlockDestroyed" method in my item class yet, the NBT of the stack still returns null. Am I not setting it correctly?

 

Ignore the GUI stuff.

public void onCreated(ItemStack stack, World world, EntityPlayer player) {
	if(world.isRemote)
		return;

	NBTTagCompound cmp = stack.stackTagCompound;

	if(cmp == null) {
		System.out.println("NBT TAG SET");

		cmp = new NBTTagCompound();
		stack.stackTagCompound = cmp;
	}

	this.fixNBT(stack);

	System.out.println(stack.stackTagCompound);

	cmp.setString("MiningSize", "3x3");
}

public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean flag) {
	list.add(EnumChatFormatting.RED + "Use SHIFT + Right-Click to");
	list.add(EnumChatFormatting.RED + "open the modification menu.");
	list.add("");
	list.add(EnumChatFormatting.GREEN + "Hit Left-ALT to open the");
	list.add(EnumChatFormatting.GREEN + "quick change menu.");
}

public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	if(player.isSneaking()) {
		FMLNetworkHandler.openGui(player, CrewMod.instance, GuiId.guiCrewHammerID, world, (int)player.posX, (int)player.posY, (int)player.posZ);
	}

	return stack;
}

public static void fixNBT(ItemStack hammer){
	NBTTagCompound cmp = hammer.stackTagCompound;

	if(cmp == null) {
		System.out.println("CMP WAS NULL, FIXING...");

		hammer.stackTagCompound = new NBTTagCompound();
		cmp = hammer.stackTagCompound;
	}

	if(!cmp.hasKey("MiningSize")){
		System.out.println("MiningSize WAS NULL, FIXING...");

		cmp.setString("MiningSize", "1x1");
	}

	hammer.stackTagCompound = cmp;
}

public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) {
	EntityPlayer player = (EntityPlayer)entity;

	System.out.println("CALLED");

	if(world != null && player != null) {
		System.out.println("WORLD WAS NOT NULL NOR WAS PLAYER");

		if(player.inventory.getCurrentItem() != null) {
			if(player.inventory.getCurrentItem().getItem().equals(CrewMod.crewHammer)) {
				int direction = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

				ItemStack hammer = stack;

				//System.out.println("ITEM IN HAND IS CREW HAMMER");

				//Block block = event.block;

				//World world = event.world;

				//int x = event.x;
				//int y = event.y;
				//int z = event.z;

				CrewHammer.fixNBT(hammer);

				NBTTagCompound cmp = hammer.stackTagCompound;

				//if(event.isCanceled())
					//return;

				String miningArea = null;

				if(cmp != null) {
					miningArea = cmp.getString("MiningSize");

					//System.out.println("CMP WAS NOT NULL");
				}

				System.out.println(miningArea);

				this.breakBlock(world, player, hammer, x, y, z, direction, miningArea);
			}else {
				super.onBlockDestroyed(stack, world, block, x, y, z, entity);
			}
		}else {
			super.onBlockDestroyed(stack, world, block, x, y, z, entity);
		}
	}

	return true;
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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.