Skip to content

Commit

Permalink
Fix minor issues with show_entity hover in messages (#3908)
Browse files Browse the repository at this point in the history
* actually use show entity hover event type, instead of using name in the wrong place

* don't attempt to getString of null resources when showing entity type in hover

EntityList does not contain all possible entity types. It does not contain entries for:
FishingHook, lightning, Weather, Player, or ComplexPart.
Trying to use a hover show entity of one of these types would cause a null pointer exception.
And before the previous commit the type was actually the name.
Which caused showing entities with a name of "Player" or one of the other types mentioned above to cause this error.
Preventing the message from being sent.
  • Loading branch information
Anna-28 authored Nov 3, 2023
1 parent 67cf694 commit b42ffa2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public abstract class HoverEventMixin implements HoverEventBridge {
String name = nbt.getString("name");
EntityType type = null;
if (nbt.hasKey("type", Constants.NBT.TAG_STRING)) {
type = SpongeImpl.getGame().getRegistry().getType(EntityType.class, name).orElse(null);
type = SpongeImpl.getGame().getRegistry().getType(EntityType.class, nbt.getString("type")).orElse(null);
}

UUID uniqueId = UUID.fromString(nbt.getString("id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.entity.EntityList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.event.HoverEvent;
Expand Down Expand Up @@ -66,7 +67,10 @@ public static HoverEvent getHandle(HoverAction<?> action) {
nbt.setString("id", entity.getUniqueId().toString());

if (entity.getType().isPresent()) {
nbt.setString("type", EntityList.getKey(((SpongeEntityType) entity.getType().get()).entityClass).toString());
ResourceLocation resource = EntityList.getKey(((SpongeEntityType) entity.getType().get()).entityClass);
if (resource != null) {
nbt.setString("type", resource.toString());
}
}

nbt.setString("name", entity.getName());
Expand Down

0 comments on commit b42ffa2

Please sign in to comment.