Commit 7bfd61e4 by Jonathan Thomas

Migrate all Entity classes to MobEntity for consistency

parent d8d4e234
Pipeline #11948 passed with stage
in 20 seconds
......@@ -9,7 +9,7 @@ import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
......@@ -57,7 +57,7 @@ public class ClickHandler {
// Update the chat data manager on the client-side
client.execute(() -> { // Make sure to run on the client thread
Entity entity = ClientEntityFinder.getEntityByUUID(client.world, entityId);
MobEntity entity = ClientEntityFinder.getEntityByUUID(client.world, entityId);
if (entity != null) {
ChatDataManager chatDataManager = ChatDataManager.getClientInstance();
ChatDataManager.EntityChatData chatData = chatDataManager.getOrCreateChatData(entity.getUuidAsString());
......@@ -105,10 +105,10 @@ public class ClickHandler {
// Get all entities
List<Entity> nearbyEntities = world.getOtherEntities(null, area);
// Filter out living entities
List<LivingEntity> nearbyCreatures = nearbyEntities.stream()
.filter(entity -> entity instanceof LivingEntity)
.map(entity -> (LivingEntity) entity)
// Filter out MobEntity/Living entities
List<MobEntity> nearbyCreatures = nearbyEntities.stream()
.filter(entity -> entity instanceof MobEntity)
.map(entity -> (MobEntity) entity)
.collect(Collectors.toList());
// Get the player from the client
......@@ -121,11 +121,11 @@ public class ClickHandler {
Vec3d lookVec = player.getRotationVec(1.0F);
Vec3d endRay = startRay.add(lookVec.normalize().multiply(renderDistance));
Entity closestEntity = null;
MobEntity closestEntity = null;
double closestDistance = Double.MAX_VALUE; // Start with the largest possible distance
// Iterate through the entities to check for hits
for (Entity entity : nearbyCreatures) {
for (MobEntity entity : nearbyCreatures) {
if (entity.getType() == EntityType.PLAYER) {
// Skip Player
continue;
......
package com.owlmaddie;
import net.minecraft.entity.Entity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
import java.util.UUID;
// Find Client Entity from UUID
public class ClientEntityFinder {
public static Entity getEntityByUUID(ClientWorld world, UUID uuid) {
public static MobEntity getEntityByUUID(ClientWorld world, UUID uuid) {
for (Entity entity : world.getEntities()) {
if (entity.getUuid().equals(uuid)) {
return entity;
if (entity.getUuid().equals(uuid) && entity instanceof MobEntity) {
return (MobEntity)entity;
}
}
return null; // Entity not found
......
......@@ -13,7 +13,7 @@ import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
......@@ -140,7 +140,7 @@ public class ClientInit implements ClientModInitializer {
RenderSystem.disableDepthTest();
}
private void drawEntityIcon(MatrixStack matrices, Entity entity, float x, float y, float width, float height) {
private void drawEntityIcon(MatrixStack matrices, MobEntity entity, float x, float y, float width, float height) {
// Get entity renderer
EntityRenderer renderer = EntityRendererAccessor.getEntityRenderer(entity);
String entity_icon_path = renderer.getTexture(entity).getPath();
......@@ -200,7 +200,7 @@ public class ClientInit implements ClientModInitializer {
false, matrix, immediate, TextLayerType.NORMAL, 0, fullBright);
}
private void drawEntityName(Entity entity, Matrix4f matrix, VertexConsumerProvider immediate,
private void drawEntityName(MobEntity entity, Matrix4f matrix, VertexConsumerProvider immediate,
int fullBright, float yOffset) {
if (entity.getCustomName() != null) {
TextRenderer fontRenderer = MinecraftClient.getInstance().textRenderer;
......@@ -235,13 +235,13 @@ public class ClientInit implements ClientModInitializer {
// Get all entities
List<Entity> nearbyEntities = world.getOtherEntities(null, area);
// Filter living entities
List<LivingEntity> nearbyCreatures = nearbyEntities.stream()
.filter(entity -> entity instanceof LivingEntity)
.map(entity -> (LivingEntity) entity)
// Filter MobEntity/Living entities
List<MobEntity> nearbyCreatures = nearbyEntities.stream()
.filter(entity -> entity instanceof MobEntity)
.map(entity -> (MobEntity) entity)
.collect(Collectors.toList());
for (Entity entity : nearbyCreatures) {
for (MobEntity entity : nearbyCreatures) {
if (entity.getType() == EntityType.PLAYER) {
// Skip Player
continue;
......
......@@ -9,7 +9,6 @@ import com.owlmaddie.json.QuestJson;
import com.owlmaddie.message.Behavior;
import com.owlmaddie.message.MessageParser;
import com.owlmaddie.message.ParsedMessage;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
......@@ -176,7 +175,7 @@ public class ChatDataManager {
contextData.put("world_moon_phase", moonPhaseDescription);
// Get Entity details
LivingEntity entity = (LivingEntity) ServerEntityFinder.getEntityByUUID(player.getServerWorld(), UUID.fromString(entityId));
MobEntity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), UUID.fromString(entityId));
if (entity.getCustomName() == null) {
contextData.put("entity_name", "");
} else {
......@@ -215,7 +214,7 @@ public class ChatDataManager {
ParsedMessage result = MessageParser.parseMessage(output_message.replace("\n", " "));
// Apply behaviors (if any)
MobEntity entity = (MobEntity) ServerEntityFinder.getEntityByUUID(player.getServerWorld(), UUID.fromString(entityId));
MobEntity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), UUID.fromString(entityId));
for (Behavior behavior : result.getBehaviors()) {
LOGGER.info("Behavior: " + behavior.getName() + (behavior.getArgument() != null ?
", Argument: " + behavior.getArgument() : ""));
......
......@@ -49,11 +49,11 @@ public class ModInit implements ModInitializer {
// Ensure that the task is synced with the server thread
server.execute(() -> {
Entity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
MobEntity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
if (entity != null) {
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, (MobEntity)entity, 3.5F);
EntityBehaviorManager.addGoal((MobEntity)entity, talkGoal, GoalPriority.TALK_PLAYER);
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, entity, 3.5F);
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entity.getUuidAsString());
if (chatData.status == ChatDataManager.ChatStatus.NONE ||
......@@ -83,11 +83,11 @@ public class ModInit implements ModInitializer {
// Ensure that the task is synced with the server thread
server.execute(() -> {
Entity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
MobEntity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
if (entity != null) {
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, (MobEntity)entity, 3.5F);
EntityBehaviorManager.addGoal((MobEntity)entity, talkGoal, GoalPriority.TALK_PLAYER);
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, entity, 3.5F);
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entity.getUuidAsString());
if (chatData.status == ChatDataManager.ChatStatus.DISPLAY) {
......@@ -105,11 +105,11 @@ public class ModInit implements ModInitializer {
// Ensure that the task is synced with the server thread
server.execute(() -> {
Entity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
MobEntity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
if (entity != null) {
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, (MobEntity)entity, 7F);
EntityBehaviorManager.addGoal((MobEntity)entity, talkGoal, GoalPriority.TALK_PLAYER);
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, entity, 7F);
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
}
});
});
......@@ -121,11 +121,11 @@ public class ModInit implements ModInitializer {
// Ensure that the task is synced with the server thread
server.execute(() -> {
Entity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
MobEntity entity = ServerEntityFinder.getEntityByUUID(player.getServerWorld(), entityId);
if (entity != null) {
// Set talk to player goal (prevent entity from walking off)
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, (MobEntity)entity, 3.5F);
EntityBehaviorManager.addGoal((MobEntity)entity, talkGoal, GoalPriority.TALK_PLAYER);
TalkPlayerGoal talkGoal = new TalkPlayerGoal(player, entity, 3.5F);
EntityBehaviorManager.addGoal(entity, talkGoal, GoalPriority.TALK_PLAYER);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entity.getUuidAsString());
if (chatData.status == ChatDataManager.ChatStatus.END) {
......@@ -174,7 +174,7 @@ public class ModInit implements ModInitializer {
public static void BroadcastPacketMessage(ChatDataManager.EntityChatData chatData) {
for (ServerWorld world : serverInstance.getWorlds()) {
UUID entityId = UUID.fromString(chatData.entityId);
Entity entity = ServerEntityFinder.getEntityByUUID(world, entityId);
MobEntity entity = ServerEntityFinder.getEntityByUUID(world, entityId);
if (entity != null) {
// Set custom name (if none)
if (entity.getCustomName() == null && chatData.status != ChatDataManager.ChatStatus.PENDING) {
......
package com.owlmaddie;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.world.ServerWorld;
import java.util.UUID;
// Find Server Entity from UUID
public class ServerEntityFinder {
public static Entity getEntityByUUID(ServerWorld world, UUID uuid) {
public static MobEntity getEntityByUUID(ServerWorld world, UUID uuid) {
for (Entity entity : world.iterateEntities()) {
if (entity.getUuid().equals(uuid)) {
return entity;
if (entity.getUuid().equals(uuid) && entity instanceof MobEntity) {
return (MobEntity)entity;
}
}
return null; // Entity not found
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment