Skip to content

Commit

Permalink
don't attempt to getString of null resources when showing entity type…
Browse files Browse the repository at this point in the history
… 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 committed Oct 27, 2023
1 parent 8bf157b commit 63e4b1a
Showing 1 changed file with 5 additions and 1 deletion.
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 63e4b1a

Please sign in to comment.