(fix) Optimized Entity Movement

This commit is contained in:
kirillsaint 2024-05-09 14:24:49 +06:00
parent 9aeb693478
commit 3a3b5c05e8
12 changed files with 238 additions and 13 deletions

View File

@ -93,7 +93,8 @@ jar {
"MixinConfigs": 'mixins.SilentClient.json',
"TweakClass": "net.silentclient.client.mixin.SilentClientTweaker",
"TweakOrder": 0,
"Manifest-Version": 1.0
"Manifest-Version": 1.0,
'FMLAT': 'silentclient_at.cfg'
)
configurations.embed.each { dep ->

View File

@ -1,10 +1,7 @@
package net.silentclient.client.mixin;
import net.minecraft.launchwrapper.IClassTransformer;
import net.silentclient.client.Client;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import java.lang.reflect.Modifier;
@ -18,14 +15,14 @@ public class SilentClientTransformer implements IClassTransformer {
return null;
}
if(transformedName.equals("bfl$e") || transformedName.equals("bfl$r") || transformedName.equals("bnm$a") || transformedName.equals("ajd$a") || transformedName.equals("bha$a")) {
Client.logger.info("Transforming class: " + transformedName);
ClassReader classreader = new ClassReader(bytes);
ClassWriter classwriter = new ClassWriter(1);
SilentClientTransformer.AccessTransformerVisitor visitor = new SilentClientTransformer.AccessTransformerVisitor(262144, classwriter);
classreader.accept(visitor, 0);
return classwriter.toByteArray();
}
// if(transformedName.equals("bfl$e") || transformedName.equals("bfl$r") || transformedName.equals("bnm$a") || transformedName.equals("ajd$a") || transformedName.equals("bha$a")) {
// Client.logger.info("Transforming class: " + transformedName);
// ClassReader classreader = new ClassReader(bytes);
// ClassWriter classwriter = new ClassWriter(1);
// SilentClientTransformer.AccessTransformerVisitor visitor = new SilentClientTransformer.AccessTransformerVisitor(262144, classwriter);
// classreader.accept(visitor, 0);
// return classwriter.toByteArray();
// }
return bytes;
}

View File

@ -0,0 +1,9 @@
package net.silentclient.client.mixin.accessors;
import net.minecraft.entity.EntityLiving;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(value={EntityLiving.class})
public interface EntityLivingAccessor {
}

View File

@ -0,0 +1,44 @@
package net.silentclient.client.mixin.accessors;
import net.minecraft.entity.ai.EntityLookHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(value={EntityLookHelper.class})
public interface EntityLookHelperAccessor {
@Accessor(value="deltaLookYaw")
public float getDeltaLookYaw();
@Accessor(value="deltaLookYaw")
public void setDeltaLookYaw(float var1);
@Accessor(value="deltaLookPitch")
public float getDeltaLookPitch();
@Accessor(value="deltaLookPitch")
public void setDeltaLookPitch(float var1);
@Accessor(value="isLooking")
public boolean isLooking();
@Accessor(value="isLooking")
public void setLooking(boolean var1);
@Accessor(value="posX")
public double getPosX();
@Accessor(value="posX")
public void setPosX(double var1);
@Accessor(value="posY")
public double getPosY();
@Accessor(value="posY")
public void setPosY(double var1);
@Accessor(value="posZ")
public double getPosZ();
@Accessor(value="posZ")
public void setPosZ(double var1);
}

View File

@ -0,0 +1,5 @@
package net.silentclient.client.mixin.ducks;
public interface EntityAITasksExt {
Object client$getTaskEntries();
}

View File

@ -0,0 +1,7 @@
package net.silentclient.client.mixin.ducks;
public interface EntityLivingExt {
void client$setLookHelper(Object var1);
Object client$getTasks();
}

View File

@ -0,0 +1,19 @@
package net.silentclient.client.mixin.mixins;
import net.minecraft.entity.ai.EntityAITasks;
import net.silentclient.client.mixin.ducks.EntityAITasksExt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
@Mixin(EntityAITasks.class)
public class EntityAITasksMixin implements EntityAITasksExt {
@Shadow private List<EntityAITasks.EntityAITaskEntry> taskEntries;
@Override
public Object client$getTaskEntries() {
return this.taskEntries;
}
}

View File

@ -0,0 +1,26 @@
package net.silentclient.client.mixin.mixins;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAITasks;
import net.minecraft.entity.ai.EntityLookHelper;
import net.silentclient.client.mixin.ducks.EntityLivingExt;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(EntityLiving.class)
public class EntityLivingMixin implements EntityLivingExt {
@Shadow private EntityLookHelper lookHelper;
@Shadow @Final protected EntityAITasks tasks;
@Override
public void client$setLookHelper(Object var1) {
this.lookHelper = (EntityLookHelper) var1;
}
@Override
public Object client$getTasks() {
return this.tasks;
}
}

View File

@ -0,0 +1,61 @@
package net.silentclient.client.mods.other.ai;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityLookHelper;
import net.minecraft.util.MathHelper;
import net.silentclient.client.mixin.accessors.EntityLookHelperAccessor;
/**
* Created by Dark on 7/20/2015.
*/
public class FixedEntityLookHelper extends EntityLookHelper
{
public FixedEntityLookHelper(EntityLiving entity)
{
super(entity);
}
@Override
public void onUpdateLook() {
this.entity.rotationPitch = 0.0f;
if (((EntityLookHelperAccessor)((Object)this)).isLooking()) {
((EntityLookHelperAccessor)((Object)this)).setLooking(false);
double d0 = ((EntityLookHelperAccessor)((Object)this)).getPosX() - this.entity.posX;
double d1 = ((EntityLookHelperAccessor)((Object)this)).getPosY() - (this.entity.posY + (double)this.entity.getEyeHeight());
double d2 = ((EntityLookHelperAccessor)((Object)this)).getPosZ() - this.entity.posZ;
double d3 = MathHelper.sqrt_double(d0 * d0 + d2 * d2);
float f = (float)((double)FixedEntityLookHelper.tan(d2, d0) * 180.0 / Math.PI) - 90.0f;
float f1 = (float)(-((double)FixedEntityLookHelper.tan(d1, d3) * 180.0 / Math.PI));
this.entity.rotationPitch = this.updateRotation(this.entity.rotationPitch, f1, ((EntityLookHelperAccessor)((Object)this)).getDeltaLookPitch());
this.entity.rotationYawHead = this.updateRotation(this.entity.rotationYawHead, f, ((EntityLookHelperAccessor)((Object)this)).getDeltaLookYaw());
} else {
this.entity.rotationYawHead = this.updateRotation(this.entity.rotationYawHead, this.entity.renderYawOffset, 10.0f);
}
float f2 = MathHelper.wrapAngleTo180_float(this.entity.rotationYawHead - this.entity.renderYawOffset);
if (!this.entity.getNavigator().noPath()) {
if (f2 < -75.0f) {
this.entity.rotationYawHead = this.entity.renderYawOffset - 75.0f;
}
if (f2 > 75.0f) {
this.entity.rotationYawHead = this.entity.renderYawOffset + 75.0f;
}
}
}
private float updateRotation(float a, float b, float c) {
float f = MathHelper.wrapAngleTo180_float(b - a);
if (f > c) {
f = c;
}
if (f < -c) {
f = -c;
}
return a + f;
}
public static float tan(double a, double b)
{
return FastTrig.atan2(a, b);
}
}

View File

@ -3,16 +3,31 @@ package net.silentclient.client.mods.settings;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAITasks;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.ai.EntityLookHelper;
import net.minecraft.init.Blocks;
import net.silentclient.client.Client;
import net.silentclient.client.event.EventManager;
import net.silentclient.client.event.EventTarget;
import net.silentclient.client.event.impl.EntityJoinLevelEvent;
import net.silentclient.client.mixin.accessors.EntityLookHelperAccessor;
import net.silentclient.client.mixin.ducks.EntityAITasksExt;
import net.silentclient.client.mixin.ducks.EntityLivingExt;
import net.silentclient.client.mods.Mod;
import net.silentclient.client.mods.ModCategory;
import net.silentclient.client.mods.Setting;
import net.silentclient.client.mods.other.ai.FastTrig;
import net.silentclient.client.mods.other.ai.FixedEntityLookHelper;
import net.silentclient.client.utils.HUDCaching;
import net.silentclient.client.utils.NotificationUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class FPSBoostMod extends Mod {
@ -82,9 +97,42 @@ public class FPSBoostMod extends Mod {
this.addBooleanSetting("Check glError",this, false); // ready
this.addBooleanSetting("Do memory debug",this, true); // ready
EventManager.register(new HUDCaching());
FastTrig.init();
}
@EventTarget
public void onJoinWorldEvent(EntityJoinLevelEvent event) {
if(!Client.getInstance().getSettingsManager().getSettingByClass(FPSBoostMod.class, "Optimized Entity Movement").getValBoolean()) {
return;
}
Entity entity = event.getEntity();
if (entity instanceof EntityLiving) {
EntityLiving living = (EntityLiving)entity;
Iterator<EntityAITasks.EntityAITaskEntry> it = ((List<EntityAITasks.EntityAITaskEntry>) ((EntityAITasksExt) ((EntityLivingExt)((Object)living)).client$getTasks()).client$getTaskEntries()).iterator();
while (it.hasNext()) {
EntityAITasks.EntityAITaskEntry obj = it.next();
if (!(obj instanceof EntityAITasks.EntityAITaskEntry)) continue;
EntityAITasks.EntityAITaskEntry task = obj;
if (task.action instanceof EntityAIWatchClosest) {
it.remove();
continue;
}
if (!(task.action instanceof EntityAILookIdle)) continue;
it.remove();
}
if (living.getLookHelper() == null || living.getLookHelper().getClass() == EntityLookHelper.class) {
EntityLookHelper oldHelper = living.getLookHelper();
((EntityLivingExt)((Object)living)).client$setLookHelper(new FixedEntityLookHelper(living));
((EntityLookHelperAccessor)((Object)living.getLookHelper())).setPosX(((EntityLookHelperAccessor)((Object)oldHelper)).getPosX());
((EntityLookHelperAccessor)((Object)living.getLookHelper())).setPosY(((EntityLookHelperAccessor)((Object)oldHelper)).getPosY());
((EntityLookHelperAccessor)((Object)living.getLookHelper())).setPosZ(((EntityLookHelperAccessor)((Object)oldHelper)).getPosZ());
((EntityLookHelperAccessor)((Object)living.getLookHelper())).setLooking(((EntityLookHelperAccessor)((Object)oldHelper)).isLooking());
((EntityLookHelperAccessor)((Object)living.getLookHelper())).setDeltaLookPitch(((EntityLookHelperAccessor)((Object)oldHelper)).getDeltaLookPitch());
((EntityLookHelperAccessor)((Object)living.getLookHelper())).setDeltaLookYaw(((EntityLookHelperAccessor)((Object)oldHelper)).getDeltaLookYaw());
}
}
}
public static boolean basicEnabled() {
return Client.getInstance().getSettingsManager().getSettingByClass(FPSBoostMod.class, "FPS Boost").getValBoolean();

View File

@ -4,6 +4,8 @@
"refmap": "mixins.SilentClient.refmap.json",
"mixins": [
"accessors.EntityArrowAccessor",
"accessors.EntityLivingAccessor",
"accessors.EntityLookHelperAccessor",
"accessors.FontRendererAccessor",
"accessors.GuiAccessor",
"accessors.GuiInGameAccessor",
@ -32,8 +34,10 @@
"mixins.ChunkRenderDispatcherMixin",
"mixins.CommandHandlerMixin",
"mixins.EffectRendererMixin",
"mixins.EntityAITasksMixin",
"mixins.EntityFXMixin",
"mixins.EntityLivingBaseMixin",
"mixins.EntityLivingMixin",
"mixins.EntityMixin",
"mixins.EntityOtherPlayerMPMixin",
"mixins.EntityPacketsMixin",

View File

@ -11,3 +11,7 @@ public net.minecraft.client.renderer.tileentity.TileEntityBannerRenderer$TimedBa
# BlockRedstoneTorch
public net.minecraft.block.BlockRedstoneTorch$Toggle
# EntityAITasks
public net.minecraft.entity.ai.EntityAITasks$EntityAITaskEntry
public net.minecraft.entity.ai.EntityLookHelper field_75659_a #EntityLiving entity;