Jump to content

[1.14.4] addEnchantment() result only visible on reopen inventory


Recommended Posts

Posted (edited)

Hi,

im using the onCreated() method to enchant some Tools and Armor on different  conditions...

some of these conditions are working how expected and the item is already enchanted by taking the item out of the result Slot of the craftingtable...

others dont work like this, i have to close and reopen the inventory first, to see the enchantment and the glowing texture on the item...

what is the case for this behaivor? do i need packethandling? but why not for the other condition?

 

with this, the enchantment is showing up instant:

float moonPhaseFactor = Dimension.MOON_PHASE_FACTORS[world.dimension.getMoonPhase(world.dimension.getWorldTime())];
if (world.getDimension().getType() == DimensionType.OVERWORLD && moonPhaseFactor == 1.0f) {
   stack.addEnchantment(Enchantments.BINDING_CURSE ,1);
}

 

and with this, i Need to reopen the inventory:

BlockPos pos = new BlockPos(player);
if (world.getBiome(pos).hasStructure(Structures.PILLAGER_OUTPOST)) {
   if (Structures.PILLAGER_OUTPOST.isPositionInsideStructure(world, pos)) {
      stack.addEnchantment(Enchantments.PROJECTILE_PROTECTION, 1);
   }
}

 

thx for any hints

Edited by OsHeaven
Posted

What event are you using to call these methods? Is it possible that in the 2nd method, the item is being created before the event has had time to resolve, resulting in a race-condition between item creation and displaying the item's enchantments?

Posted

Hm... if it were me, I would start by commenting out the code on the BlockPos method, and replacing it with an exact copy of the moonPhaseFactor method. That way, you can narrow it down a bit. Either 1) the error will still exist when creating the moonPhaseFactor item, in which case you know it has to do with how the method is called, or 2) the error will not exist, in which case the error is definitely with your BlockPos method, though I can't see why that would be giving you issues, as it is.

 

Keep us updated.

Posted
11 minutes ago, StitchNChill said:

That way, you can narrow it down a bit

...that's the version that he says works...

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)
7 minutes ago, Draco18s said:

...that's the version that he says works...

Correct. OP is saying that he has multiple methods in his code, and that some work as expected while others don't. I'm suggesting he takes the working method, inserts it in place of the misbehaving method, and checks the output.

 

If the output is still incorrect even with the working method, the issue is not with the method(s), rather something else with the code.

If the output is correct using the working method, the issue is indeed with the original misbehaving method. However, the 'misbehaving' method looks spot-on to me, which is why I'm making this suggestion.

Edited by StitchNChill
Posted (edited)

i found some weird behaivor… if i add an isDaytime() check like this:

float moonPhaseFactor = Dimension.MOON_PHASE_FACTORS[world.dimension.getMoonPhase(world.dimension.getWorldTime())];
if (world.getDimension().getType() == DimensionType.OVERWORLD && moonPhaseFactor == 1.0f && world.isDaytime()) {
   stack.addEnchantment(Enchantments.BINDING_CURSE, 1);
}

 

on daytime: the crafted item Shows the enchantment like expected...

on nighttime: the crafted item Shows the enchantment, BUT after reopen the invontory, the enchantment and the glowing effect is gone

Edited by OsHeaven
Posted (edited)
8 minutes ago, OsHeaven said:

on nighttime: the crafted item Shows the enchantment, BUT after reopen the invontory, the enchantment and the glowing effect is gone

This is on the moonPhaseFactor, which was originally the working method, correct? So by what your code says here , because world.isDaytime() returns FALSE, it should never get to the stack.addEnchantment(...) line:

 

8 minutes ago, OsHeaven said:

if (world.getDimension().getType() == DimensionType.OVERWORLD && moonPhaseFactor == 1.0f && world.isDaytime()) {

 

I would insert parentheses to deterministically decclare the order of operations. While your code seems to look fine, there may be something I'm not catching. Just a quick change, maybe it'll solve your issues.

 

((world.getDimension().getType() == DimensionType.OVERWORLD) && (moonPhaseFactor == 1.0f) && (world.isDaytime()))

 

EDIT: there could be a compiler bug that doesn't appropriately perform the order of operations. here is how precedence should occur (https://introcs.cs.princeton.edu/java/11precedence/) but maybe your compiler doesn't want to play nice.

Edited by StitchNChill
Posted
6 minutes ago, StitchNChill said:

This is on the moonPhaseFactor, which was originally the working method, correct? So by what your code says here , because world.isDaytime() returns FALSE, it should never get to the stack.addEnchantment(...) line:

 

 

I would insert parentheses to deterministically decclare the order of operations. While your code seems to look fine, there may be something I'm not catching. Just a quick change, maybe it'll solve your issues.

 


((world.getDimension().getType() == DimensionType.OVERWORLD) && (moonPhaseFactor == 1.0f) && (world.isDaytime()))

 

EDIT: there could be a compiler bug that doesn't appropriately perform the order of operations. here is how precedence should occur (https://introcs.cs.princeton.edu/java/11precedence/) but maybe your compiler doesn't want to play nice.

 

isDaytime() Returns false…. so it shouldnt add the enchantment… yep.. BUT it does…

till reopening the inventory, then its removed...

im working with intellij…i dont think so, that a bug like this exists here

Posted
1 minute ago, OsHeaven said:

isDaytime() Returns false…. so it shouldnt add the enchantment… yep.. BUT it does…

Which is why I'm suggesting you add parentheses to see if it fixes the error. It could be a compiler issue within intellij.

 

2 minutes ago, OsHeaven said:

i dont think so, that a bug like this exists here

I can't help you unless you try.

Posted
11 minutes ago, StitchNChill said:

Which is why I'm suggesting you add parentheses to see if it fixes the error. It could be a compiler issue within intellij.

 

I can't help you unless you try.

i tried… Nothing changed

Posted (edited)

Hm.. try outputting each of the values individually and see what happens. See if any of them output as false whenever you execute the method. If you need help on system.out.println, you can read up on it a little first: https://docs.oracle.com/javase/tutorial/essential/io/formatting.html

 

float moonPhaseFactor = Dimension.MOON_PHASE_FACTORS[world.dimension.getMoonPhase(world.dimension.getWorldTime())];

System.out.println("is overworld? " + (world.getDimension().getType() == DimensionType.OVERWORLD));
System.out.println("is moonphasefactor? " + (moonPhaseFactor == 1.0f)); 
System.out.println("is daytime? " + world.isDaytime());

if (world.getDimension().getType() == DimensionType.OVERWORLD && moonPhaseFactor == 1.0f && world.isDaytime()) {
   stack.addEnchantment(Enchantments.BINDING_CURSE, 1);
}
Edited by StitchNChill
Posted (edited)

on daytime:

[22:06:34.727] [Client thread/INFO] [minecraft/Biome]: is Daytime:true
[22:06:34.730] [Server thread/INFO] [minecraft/Biome]: is Daytime:true

 

on night, only:

[22:06:52.652] [Client thread/INFO] [minecraft/Biome]: is Daytime:true

 

so, i think its a Server/Client synch issue...

how to synch the Client with the Server, when i take an item from the crafting result Slot?

i dont know anythingabout packethandling, and all documentations are pre 1.14 unfortunately

Edited by OsHeaven
  • Like 1
Posted
59 minutes ago, StitchNChill said:

It could be a compiler issue within intellij.

If an issue ever arises where someone suspects a bug in very popular software vs. their code, I will always assume its "their code" and not the popular software. Are there bugs in Intellij? Probably. But something like this would get noticed and fixed before it ever got released.

 

38 minutes ago, StitchNChill said:

System.out.println("is daytime? " + world.isDaytime());

This was literally the only helpful thing you said in this thread.

  • Like 1

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
20 minutes ago, diesieben07 said:

The problem is that onCrafting is called on server and client. You'll probably need to do some forced synchronization if the condition is only determinable on the server.

some world.isRemote checks? or @OnlyIn() ? Maybe not...

forced synchronization… exists any Information about that somewhere?

Posted
2 minutes ago, Draco18s said:

This was literally the only helpful thing you said in this thread.

Third time's the charm ?

 

Just now, OsHeaven said:

forced synchronization… exists any Information about that somewhere?

There's some older threads about it floating around. For example, googling something like "force craft synchronization server client forge" I was able to find this. I haven't read it yet, and it looks like it has to do with TileEntitys, so take that with a grain of salt - but maybe it'll help get you on the right path. 

 

Posted
4 minutes ago, StitchNChill said:

Third time's the charm ?

 

There's some older threads about it floating around. For example, googling something like "force craft synchronization server client forge" I was able to find this. I haven't read it yet, and it looks like it has to do with TileEntitys, so take that with a grain of salt - but maybe it'll help get you on the right path. 

 

yeah, ive found some older threads too… it is often not really helpful, if all the used classes and methods are renamed, removed or replaced in 1.14 ^^

but thx

Posted
3 hours ago, OsHeaven said:

yeah, ive found some older threads too… it is often not really helpful, if all the used classes and methods are renamed, removed or replaced in 1.14 ^^

If you need a bit more direction you need to create a custom packet using the SimpleImpl

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
18 hours ago, Animefan8888 said:

If you need a bit more direction you need to create a custom packet using the SimpleImpl

Thx, ive looked at it and some older mod codes… ive a first idea what to do, but ive some Questions now...

what type of package do i have to create? and what data to send? i need to synch the Client.. so the Server data of daytime, respectively the structure data? or the container data?

and it seems IMessage doesnt exists anymore… what type do i have to extends for my custom one? 

Posted
1 hour ago, OsHeaven said:

it seems IMessage doesnt exists anymore… what type do i have to extends for my custom one? 

You don't need to implement or extend anything.

https://github.com/Draco18s/ReasonableRealism/tree/1.14.4/src/main/java/com/draco18s/harderores/network

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
On 8/14/2019 at 11:19 PM, Draco18s said:

thx for showing your Code. i will try to implement something to synch the structures data on Client...

for the isDaytime check, i simply use world.dimension.getWorldTime() == 13000 instead of !isDaytime()… it works on Client as well

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.