Commit 3ba6c909 by Jonathan Thomas

Adding accesswidener for SlimeMoveControl access. New helper code to make…

Adding accesswidener for SlimeMoveControl access. New helper code to make Slime's look at the player (in survival mode) and correctly follow the player.
parent 6f885653
Pipeline #11967 passed with stage
in 23 seconds
......@@ -19,6 +19,7 @@ repositories {
}
loom {
accessWidenerPath = file("src/main/resources/mobgpt.accesswidener")
splitEnvironmentSourceSets()
mods {
......
package com.owlmaddie.goals;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.SlimeEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.MathHelper;
/**
* The {@code EntityLook} class allows an entity to look at the player, with some custom fixes
* for certain mobs that refuse to use the normal LookControls (i.e. Slime).
*/
public class EntityLook {
public static void LookAtEntity(ServerPlayerEntity player, MobEntity entity) {
// Make the entity look at the player without moving towards them
entity.getLookControl().lookAt(player, 10.0F, (float)entity.getMaxLookPitchChange());
// Fix Slimes (who handle looking differently)
if (entity instanceof SlimeEntity) {
// Calculate direction which entity needs to face
double deltaX = player.getX() - entity.getX();
double deltaZ = player.getZ() - entity.getZ();
float currentYaw = entity.getYaw();
float targetYaw = (float) Math.toDegrees(Math.atan2(deltaZ, deltaX)) - 90.0F;
float yawDifference = MathHelper.wrapDegrees(targetYaw - currentYaw); // Ensures the difference is within -180 to 180
float yawChange = MathHelper.clamp(yawDifference, -10.0F, 10.0F); // Limits the change to 10 degrees
((SlimeEntity.SlimeMoveControl) entity.getMoveControl()).look(currentYaw + yawChange, false);
}
}
}
......@@ -49,7 +49,7 @@ public class FollowPlayerGoal extends Goal {
// Check if the entity is further away than 4 blocks (16 when squared)
if (squaredDistanceToPlayer > 16) {
// Entity is more than 4 blocks away, look at the player and start moving towards them
this.entity.getLookControl().lookAt(this.targetPlayer, 10.0F, (float) this.entity.getMaxLookPitchChange());
EntityLook.LookAtEntity(this.targetPlayer, this.entity);
this.navigation.startMovingTo(this.targetPlayer, this.speed);
} else if (squaredDistanceToPlayer < 9) {
// Entity is closer than 3 blocks, stop moving to maintain distance
......
......@@ -50,7 +50,7 @@ public class TalkPlayerGoal extends Goal {
@Override
public void tick() {
// Make the entity look at the player without moving towards them
this.entity.getLookControl().lookAt(this.targetPlayer, 10.0F, (float)this.entity.getMaxLookPitchChange());
EntityLook.LookAtEntity(this.targetPlayer, this.entity);
// Continuously stop the entity's navigation to ensure it remains stationary
this.navigation.stop();
}
......
......@@ -30,6 +30,7 @@
"environment": "client"
}
],
"accessWidener": "mobgpt.accesswidener",
"depends": {
"fabricloader": ">=0.14.22",
"minecraft": "~1.20.2",
......
accessWidener v1 named
# Access slime movement
accessible class net/minecraft/entity/mob/SlimeEntity$SlimeMoveControl
accessible method net/minecraft/entity/mob/SlimeEntity$SlimeMoveControl look (FZ)V
\ No newline at end of file
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