From eda5e8c5e0760ff351df0ddc0575d454f6c5c4da Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 13 Apr 2023 21:47:47 -0400 Subject: [PATCH] Fix #2114 (metaMonster can be null) --- .../game/entity/EntityMonster.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java index 7c5d2f629..30770e0fb 100644 --- a/src/main/java/emu/grasscutter/game/entity/EntityMonster.java +++ b/src/main/java/emu/grasscutter/game/entity/EntityMonster.java @@ -34,6 +34,7 @@ import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; import lombok.Getter; import lombok.Setter; +import javax.annotation.Nullable; import java.util.Optional; import static emu.grasscutter.scripts.constants.EventType.EVENT_SPECIFIC_MONSTER_HP_CHANGE; @@ -53,7 +54,7 @@ public class EntityMonster extends GameEntity { @Getter @Setter private int poseId; @Getter @Setter private int aiId = -1; - @Getter @Setter private SceneMonster metaMonster; + @Nullable @Getter @Setter private SceneMonster metaMonster; public EntityMonster(Scene scene, MonsterData monsterData, Position pos, int level) { super(scene); @@ -206,15 +207,19 @@ public class EntityMonster extends GameEntity { @Override public SceneEntityInfo toProto() { + var data = this.getMonsterData(); + var authority = EntityAuthorityInfo.newBuilder() .setAbilityInfo(AbilitySyncStateInfo.newBuilder()) .setRendererChangedInfo(EntityRendererChangedInfo.newBuilder()) - .setAiInfo(SceneEntityAiInfo.newBuilder().setIsAiOpen(true).setBornPos(this.getBornPos().toProto())) + .setAiInfo(SceneEntityAiInfo.newBuilder() + .setIsAiOpen(true) + .setBornPos(this.getBornPos().toProto())) .setBornPos(this.getBornPos().toProto()) .build(); var entityInfo = SceneEntityInfo.newBuilder() - .setEntityId(getId()) + .setEntityId(this.getId()) .setEntityType(ProtEntityType.PROT_ENTITY_TYPE_MONSTER) .setMotionInfo(this.getMotionInfo()) .addAnimatorParaList(AnimatorParameterValueInfoPair.newBuilder()) @@ -226,25 +231,27 @@ public class EntityMonster extends GameEntity { entityInfo.addPropList(PropPair.newBuilder() .setType(PlayerProperty.PROP_LEVEL.getId()) - .setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, getLevel())) + .setPropValue(ProtoHelper.newPropValue(PlayerProperty.PROP_LEVEL, this.getLevel())) .build()); var monsterInfo = SceneMonsterInfo.newBuilder() .setMonsterId(getMonsterId()) .setGroupId(this.getGroupId()) .setConfigId(this.getConfigId()) - .addAllAffixList(getMonsterData().getAffix()) - .setAuthorityPeerId(getWorld().getHostPeerId()) + .addAllAffixList(data.getAffix()) + .setAuthorityPeerId(this.getWorld().getHostPeerId()) .setPoseId(this.getPoseId()) - .setBlockId(getScene().getId()) + .setBlockId(this.getScene().getId()) .setBornType(MonsterBornType.MONSTER_BORN_TYPE_DEFAULT); - if (metaMonster.special_name_id != 0) { - monsterInfo.setTitleId(metaMonster.title_id) - .setSpecialNameId(metaMonster.special_name_id); - } else if (getMonsterData().getDescribeData() != null) { - monsterInfo.setTitleId(getMonsterData().getDescribeData().getTitleId()) - .setSpecialNameId(getMonsterData().getSpecialNameId()); + if (this.metaMonster != null) { + if (this.metaMonster.special_name_id != 0) { + monsterInfo.setTitleId(this.metaMonster.title_id) + .setSpecialNameId(this.metaMonster.special_name_id); + } else if (data.getDescribeData() != null) { + monsterInfo.setTitleId(data.getDescribeData().getTitleId()) + .setSpecialNameId(data.getSpecialNameId()); + } } if (this.getMonsterWeaponId() > 0) {