Jump to content

[1.12]Custom ItemStack NBT not saving


GiantNuker

Recommended Posts

Show more of your code. There are several reasons why this might fail, but in order to determine which one of those it is, we need to know where this code is.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

10 minutes ago, Draco18s said:

Show more of your code. There are several reasons why this might fail, but in order to determine which one of those it is, we need to know where this code is.

That bit of code is in my API, here it is from the item:

public static boolean isUsable(ItemStack stack) {
		return ((NBTTagInt) ItemData.getStackNBTTag(stack, "damag", new NBTTagInt(0))).getInt() > WingsConfig.detachableDamage ? false : true;
	}
	public static void useDamage(ItemStack stack) {
		int currDam = ((NBTTagInt) ItemData.getStackNBTTag(stack, "damag", new NBTTagInt(0))).getInt();
		if (isUsable(stack)) ItemData.setStackNBTTag(stack, "damag", new NBTTagInt(currDam + 1));
	}
	public boolean isDamageable() {
		return false;
	}
	
	public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) {
		return repair.getItem() == Items.LEATHER;
	}
	
	public double getDurabilityForDisplay(ItemStack stack) {
		return (double)((NBTTagInt) ItemData.getStackNBTTag(stack, "damag", new NBTTagInt(0))).getInt() / WingsConfig.detachableDamage;
	}
	
	public boolean showDurabilityBar(ItemStack stack) {
		return getDurabilityForDisplay(stack) != 0;
	}

and what calls useDamage:

@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void check(TickEvent.PlayerTickEvent te) {
		try {if (WingsMod.getStateForPlayer(Minecraft.getMinecraft().player) != FlightState.HOVERING && WingsMod.tsc < 1 && Minecraft.getMinecraft().player.onGround) WingsMod.setFlightState(FlightState.NOT_FLYING);
		else if (WingsMod.tsc < 1 && Minecraft.getMinecraft().player.onGround) WingsMod.setFlightState(FlightState.GLIDING);;
		} catch(NullPointerException e) {}
		try {if (WingsMod.getStateForPlayer(te.player) == FlightState.HOVERING && !Minecraft.getMinecraft().player.capabilities.isFlying) Minecraft.getMinecraft().player.capabilities.isFlying = true;} catch(NullPointerException e) {}
		if (WingsMod.tsc > 0) WingsMod.tsc--;
		if (WingsMod.renderHoverVal < -0.5f || WingsMod.renderHoverVal > 0.5f) WingsMod.renderHoverDown = !WingsMod.renderHoverDown;
		if (WingsMod.renderHoverDown) {
			WingsMod.renderHoverVal = WingsMod.renderHoverVal - 0.05f;
		} else {
			WingsMod.renderHoverVal = WingsMod.renderHoverVal + 0.05f;
		}
		
		try {EntityPlayer p = Minecraft.getMinecraft().player;

		 //WingsCapability cap = player.getCapability(WingsCapability.Provider.WINGS_CAP, null);
		if (/*cap.hasWings() ||  */p.getItemStackFromSlot(EntityEquipmentSlot.CHEST).getItem() == WingsMod.wings && ItemDetatchableWings.isUsable(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST))) {
			KeyBinding incVelocity = Minecraft.getMinecraft().gameSettings.keyBindJump;
			
			if (WingsMod.getStateForPlayer(p) == FlightState.GLIDING && incVelocity.isKeyDown() && (p.motionX < 2.7) && (p.motionY < 2.7) && (p.motionZ < 2.7)) { // Fly Up/Increase Velocity
				float yaw = p.rotationYaw;
			    float pitch = p.rotationPitch;
			    float f = 0.02F;
			    double motionX = (double)(-MathHelper.sin(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f);
			    double motionZ = (double)(MathHelper.cos(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f);
			    double motionY = (double)(-MathHelper.sin((pitch) / 180.0F * (float)Math.PI) * f);
			    p.addVelocity(motionX, motionY, motionZ);
			    if (!p.getName().equals("GiantNuker")) {
				    p.getFoodStats().addExhaustion(WingsConfig.hunger_speedup);
				    ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
				    ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
			    }
			} else if (WingsMod.getStateForPlayer(p) == FlightState.NOT_FLYING && incVelocity.isKeyDown() && p.fallDistance > 3) {
				WingsMod.setFlightState(FlightState.GLIDING);
			} else if(WingsMod.getStateForPlayer(p) == FlightState.GLIDING && WingsKeyBinds.slow.isKeyDown() && (p.motionX > 0.1) && (p.motionY > 0.1) && (p.motionZ > 0.1)) { // Fly Down/Decrease Velocity
				float yaw = p.rotationYaw;
			    float pitch = p.rotationPitch;
			    float f = 0.04F;
			    double motionX = (double)(-MathHelper.sin(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f);
			    double motionZ = (double)(MathHelper.cos(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f);
			    double motionY = (double)(-MathHelper.sin((pitch) / 180.0F * (float)Math.PI) * f);
			    p.addVelocity(-motionX, -motionY, -motionZ);
			    if (!p.getName().equals("GiantNuker")) {
				    p.getFoodStats().addExhaustion(WingsConfig.hunger_slowdown);
				    ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
			    }
			} else if(WingsKeyBinds.launch.isKeyDown() && p.onGround) {
				float yaw = p.rotationYaw; 
			    float pitch = p.rotationPitch;
			    float f = 0.8F;
			    double motionX = (double)(-MathHelper.sin(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f);
			    double motionZ = (double)(MathHelper.cos(yaw / 180.0F * (float)Math.PI) * MathHelper.cos(pitch / 180.0F * (float)Math.PI) * f);
			    double motionY = (double)(-MathHelper.sin((pitch) / 180.0F * (float)Math.PI) * f);
			    WingsMod.setFlightState(FlightState.GLIDING);
			    p.addVelocity(motionX, motionY + 1F, motionZ);
			    if (!p.getName().equals("GiantNuker")) {
				    ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
				    ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
				    ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
				    p.getFoodStats().addExhaustion(WingsConfig.hunger_launch);
			    }
			} else if(WingsKeyBinds.hover.isPressed()) {
				WingsMod.setFlightState(WingsMod.getStateForPlayer(p) == FlightState.HOVERING ? FlightState.GLIDING : FlightState.HOVERING);
				if (WingsMod.getStateForPlayer(p) == FlightState.HOVERING && p.onGround) p.addVelocity(0, 0.5F, 0);
			}
			try {if (p.capabilities.isFlying && WingsMod.getStateForPlayer(p) != FlightState.HOVERING ) WingsMod.setFlightState(FlightState.NOT_FLYING);} catch (NullPointerException e) {}
			if (WingsMod.getStateForPlayer(p) == FlightState.GLIDING) if (!p.getName().equals("GiantNuker")) ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
			else if (WingsMod.getStateForPlayer(p) == FlightState.HOVERING) {
				if (!p.getName().equals("GiantNuker")) {
					ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
					ItemDetatchableWings.useDamage(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST));
					p.getFoodStats().addExhaustion(WingsConfig.hunger_hover);
				}
			}
			if (!ItemDetatchableWings.isUsable(p.getItemStackFromSlot(EntityEquipmentSlot.CHEST))) {
				WingsMod.setFlightState(FlightState.NOT_FLYING);
			}
		}} catch (NullPointerException e) {}
		
	}

 

Link to comment
Share on other sites

try {EntityPlayer p = Minecraft.getMinecraft().player;

You're doing everything on the client. The server then synchronizes everything and overwrites your changes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yes. Do whatever it is you're doing on the server thread.

If you can't, then no, you need packets.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.