Properly Handle Blockdata in Click Event#7886
Conversation
Absolutionism
left a comment
There was a problem hiding this comment.
imo, kinda weird having the conditions go from
object instanceof to entity != null then to object instanceof
|
Also, maybe this can be a good opportunity for a JUnit test. |
it's either that or I check |
Why would you need to check it twice? I believe the only real fix was just adding the |
there would be one inside there and another outside (the one I moved) |
|
I just tested with this return type.check(event, (Predicate<Object>) object -> {
if (entity != null) {
if (object instanceof EntityData<?> entityData) {
return entityData.isInstance(entity);
} else if (object instanceof ItemType itemType) {
Relation compare = DefaultComparators.entityItemComparator.compare(EntityData.fromEntity(entity), itemType);
return Relation.EQUAL.isImpliedBy(compare);
}
} else if (object instanceof ItemType itemType) {
return itemType.isOfType(block);
} else if (blockDataCheck != null && object instanceof BlockData blockData) {
return blockDataCheck.matches(blockData);
}
return false;
});You wouldnt need a
|
|
It might not hurt to have a comment there to clarify why a BlockData check isn't necessary (even though an ItemType check is present) |
its for comparing like a boat item to an entity boat if that's what you are asking |
He was saying to put a comment in the code |
|
language barrier :( |
* fix * whoops * indentation * add comment
Problem
If you use the
on right click on %blockdata%pattern and click on an entity, it always assumes the object is either an entity or an item type, but not block data, which can cause the server to crash.Solution
Moved the blockdata check a bit earlier to fix the issue and added an
instanceof ItemTypecheck to prevent possible crashes in the future.Testing Completed
Tested
on right click on pig,on right click on stone,on right click on stone_button[]andon right click on stone_button[powered=false]to ensure nothing was broken with this fix.Completes: #7885
Related: none