Jump to content

Recommended Posts

Posted

I'm subscribing to the PlayerTickEvent in order to setup some NBT on items as they enter an inventory. However, the code used to create the NBT is being run twice on the Server Thread. You can look at my event here as well as the class I used to generate the NBT. I feel like I'm missing something obvious but I have code very similar to this which works perfectly fine and is only called once per tick in 1.11.2. For whatever reason the method in the second gist gets called twice. Another thing that is weird is when looking at the output, the item is always assigned the rarity from the first call but there's another variable which just stores a number which is always assigned to the second call. I'm just not sure what's happening, so any help is appreciated.

Developer of Levels and Lost Eclipse

Posted

PlayerTickEvent is one of the events that has a phase, START and END.

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.

Posted

Are you checking Server vs. Client as well?

 

I don't know because you haven't posted any code

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.

Posted
	@SubscribeEvent
	public void onPlayerTick(PlayerTickEvent event)
	{
		if (!event.player.getEntityWorld().isRemote)
		{
			if (event.phase == Phase.START)
			{
				System.out.println(event.player.world.getTotalWorldTime());
			}
		}
	}

I am not able to replicate.

42997
42998
42999
43000
43001
43002

If it was running twice per tick, I would see doubled output.

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.

Posted (edited)

Ok, that helps somewhat - I might've made a logical error somewhere then.

 

public static void createWeapon(ItemStack stack, EntityPlayer player)
	{
		NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
		IPlayerInformation playerInfo = player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null);

		if (playerInfo != null)
		{
			if (Rarity.getRarity(nbt) == Rarity.DEFAULT)
			{
				nbt.setInteger("HideFlags", 6); // hides Attribute Modifier and Unbreakable tags
				Rarity.setRarity(nbt, Rarity.getRandomRarity(nbt, player.getEntityWorld().rand)); // sets a random rarity
				nbt.setInteger("Level", 1); // set level to current player level
				setRandomAttributes(stack, nbt, Rarity.getRarity(nbt), player);
				setAttributeModifiers(nbt, stack, player);
				stack.setStackDisplayName(Rarity.getRarity(nbt).getColor() + stack.getDisplayName());
				NBTHelper.saveStackNBT(stack, nbt);
			}
		}
	}

 

This is the method that gets fired from the PlayerTickEvent. If I output the world time in this block, it gets run twice (and increments too). Shouldn't it only run once though?

Edit: I have very similar code also running on 1.11.2 that only gets run once in this period of time, which is why I'm confused.

Edited by TheXFactor117

Developer of Levels and Lost Eclipse

Posted

I don't know why you're doing this in PlayerTick anyway.

But that aside...

 

1) Do you have more than one sword in your inventory?

2) Are you calling this function from anywhere else?

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.

Posted (edited)

I'm using PlayerTick because that's the only event where I can setup the NBT for the item for crafting, drops, chest loot, you name it, unless there is a better way to do that.

 

1) But no, there is only one sword. It wouldn't matter because the NBT value is unique to each stack.

2) Nope, the event is the only place this is called.

Edited by TheXFactor117

Developer of Levels and Lost Eclipse

Posted

PlayerEvent.ItemPickupEvent will handle anything dropped into the world.

AnvilRepairEvent will handle anything with the anvil.

PlayerContainerEvent.Open will handle chests.

PlayerEvent.ItemCraftedEvent handles crafting.

 

However. Since we're dealing with 1.12 and the fact that you should be using Capabilities...

 

You should be using the AttachCapabilitiesEvent<ItemStack> event to attach a capability to the stack when it is created.

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.

Posted

Yeah I've already thought about migrating. But ItemCraftedEvent doesn't work properly - adding NBT to the stack doesn't work for whatever reason.

I need to look into capabilities for items - I've used them for player and entities before. I might make another topic about that because I have some more questions about that but I want to look more in-depth at it first. As far as this issue goes, I have no idea why it's getting called twice - ItemCraftedEvent calls it once and PlayerTickEvent calls it twice.

Developer of Levels and Lost Eclipse

  • 3 years later...
Posted
On 7/8/2017 at 1:11 AM, Draco18s said:

PlayerTickEvent is one of the events that has a phase, START and END.

Turns out the ServerTickEvent also has a phase.
Solved my double tick count issue, thanks.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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