Skip to content

Commit

Permalink
Add MixinPathEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin452 committed Feb 4, 2024
1 parent 07f7daa commit 0936a6d
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ public enum Mixin implements IMixin {

common_core_MixinEntityTracker(Side.COMMON, m -> OptimizationsandTweaksConfig.enableMixinEntityTracker,
"core.MixinEntityTracker"),
common_core_pathfinding_MixinPathEntity(Side.COMMON, m -> OptimizationsandTweaksConfig.enablePathfinderOptimizations,
"core.pathfinding.MixinPathEntity"),
common_core_pathfinding_MixinPathNavigate(Side.COMMON, m -> OptimizationsandTweaksConfig.enablePathfinderOptimizations,
"core.pathfinding.MixinPathNavigate"),
common_core_pathfinding_MixinPathFinder(Side.COMMON, m -> OptimizationsandTweaksConfig.enablePathfinderOptimizations,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package fr.iamacat.optimizationsandtweaks.mixins.common.core.pathfinding;

import net.minecraft.entity.Entity;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.pathfinding.PathPoint;
import net.minecraft.util.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(PathEntity.class)
public class MixinPathEntity {


/** The actual points in the path */
@Shadow
private final PathPoint[] points;
/** PathEntity Array Index the Entity is currently targeting */
@Shadow
private int currentPathIndex;
/** The total length of the path */
@Shadow
private int pathLength;
/**
* Directs this path to the next point in its array
*/
@Shadow
public void incrementPathIndex()
{
++this.currentPathIndex;
}

/**
* Returns true if this path has reached the end
*/
@Shadow
public boolean isFinished()
{
return this.currentPathIndex >= this.pathLength;
}

/**
* returns the last PathPoint of the Array
*/
@Shadow
public PathPoint getFinalPathPoint()
{
return this.pathLength > 0 ? this.points[this.pathLength - 1] : null;
}

/**
* return the PathPoint located at the specified PathIndex, usually the current one
*/
@Shadow
public PathPoint getPathPointFromIndex(int p_75877_1_)
{
return this.points[p_75877_1_];
}
@Shadow
public int getCurrentPathLength()
{
return this.pathLength;
}
@Shadow
public void setCurrentPathLength(int p_75871_1_)
{
this.pathLength = p_75871_1_;
}
@Shadow
public int getCurrentPathIndex()
{
return this.currentPathIndex;
}
@Shadow
public void setCurrentPathIndex(int p_75872_1_)
{
this.currentPathIndex = p_75872_1_;
}

public MixinPathEntity(PathPoint[] p_i2136_1_)
{
this.points = p_i2136_1_;
this.pathLength = p_i2136_1_.length;
}
/**
* Gets the vector of the PathPoint associated with the given index.
*/
@Overwrite
public synchronized Vec3 getVectorFromIndex(Entity p_75881_1_, int p_75881_2_)
{
double d0 = (double)this.points[p_75881_2_].xCoord + ((int)(p_75881_1_.width + 1.0F)) * 0.5D;
double d1 = this.points[p_75881_2_].yCoord;
double d2 = (double)this.points[p_75881_2_].zCoord + ((int)(p_75881_1_.width + 1.0F)) * 0.5D;
return Vec3.createVectorHelper(d0, d1, d2);
}

/**
* returns the current PathEntity target node as Vec3D
*/
public Vec3 getPosition(Entity p_75878_1_)
{
return this.getVectorFromIndex(p_75878_1_, this.currentPathIndex);
}

/**
* Returns true if the EntityPath are the same. Non instance related equals.
*/
@Overwrite
public boolean isSamePath(PathEntity p_75876_1_)
{
if (p_75876_1_ == null)
{
return false;
}
else if (p_75876_1_.points.length != this.points.length)
{
return false;
}
else
{
for (int i = 0; i < this.points.length; ++i)
{
if (this.points[i].xCoord != p_75876_1_.points[i].xCoord || this.points[i].yCoord != p_75876_1_.points[i].yCoord || this.points[i].zCoord != p_75876_1_.points[i].zCoord)
{
return false;
}
}

return true;
}
}

/**
* Returns true if the final PathPoint in the PathEntity is equal to Vec3D coords.
*/
@Overwrite
public boolean isDestinationSame(Vec3 p_75880_1_)
{
PathPoint pathpoint = this.getFinalPathPoint();
return pathpoint == null ? false : pathpoint.xCoord == (int)p_75880_1_.xCoord && pathpoint.zCoord == (int)p_75880_1_.zCoord;
}
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/optimizationsandtweaks_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public codechicken.nei.api.ItemInfo *
public net.minecraft.pathfinding.PathFinder *
public net.minecraft.pathfinding.Path *
public net.minecraft.pathfinding.PathPoint *
public net.minecraft.pathfinding.PathEntity *
public net.minecraft.world.WorldServer *
public net.minecraft.world.World *
public net.minecraft.server.management.PlayerManager *

0 comments on commit 0936a6d

Please sign in to comment.