Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

  • Author

It prints out two times in the console saying it set.

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.

  • Author

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.

  • Author

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.

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.

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)...

  • Author

What do you mean by the same tool? And there would be no final code as of yet considering my problem is not solved.

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.

  • Author

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.