Implemented most passenger offsets in <= 1.20.1

This commit is contained in:
FlorianMichael 2023-09-23 21:21:03 +02:00
parent d01f2913fb
commit 531ef3eea3
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 30 additions and 5 deletions

View File

@ -17,8 +17,8 @@
*/ */
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity; package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
import net.minecraft.entity.EntityDimensions;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -34,6 +34,7 @@ import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.*;
@ -61,6 +62,8 @@ public abstract class MixinEntity {
public abstract void setVelocity(Vec3d velocity); public abstract void setVelocity(Vec3d velocity);
@Shadow protected abstract Vector3f getPassengerAttachmentPos(Entity passenger, EntityDimensions dimensions, float scaleFactor);
@ModifyConstant(method = "movementInputToVelocity", constant = @Constant(doubleValue = 1E-7)) @ModifyConstant(method = "movementInputToVelocity", constant = @Constant(doubleValue = 1E-7))
private static double injectMovementInputToVelocity(double epsilon) { private static double injectMovementInputToVelocity(double epsilon) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) {
@ -190,4 +193,13 @@ public abstract class MixinEntity {
cir.setReturnValue(blockPos); cir.setReturnValue(blockPos);
} }
} }
@Redirect(method = "getPassengerRidingPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPassengerAttachmentPos(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/EntityDimensions;F)Lorg/joml/Vector3f;"))
public Vector3f revertStaticRidingOffsetCalculation(Entity instance, Entity passenger, EntityDimensions dimensions, float scaleFactor) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return new Vector3f(0.0F, dimensions.height * 0.75F, 0.0F);
}
return getPassengerAttachmentPos(passenger, dimensions, scaleFactor);
}
} }

View File

@ -22,10 +22,7 @@ import de.florianmichael.viafabricplus.base.settings.groups.ExperimentalSettings
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.TrapdoorBlock; import net.minecraft.block.TrapdoorBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.*;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.SkeletonHorseEntity; import net.minecraft.entity.mob.SkeletonHorseEntity;
import net.minecraft.fluid.Fluid; import net.minecraft.fluid.Fluid;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -38,6 +35,7 @@ import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.raphimc.vialoader.util.VersionEnum; import net.raphimc.vialoader.util.VersionEnum;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.*;
@ -209,4 +207,12 @@ public abstract class MixinLivingEntity extends Entity {
} }
} }
@Redirect(method = "getPassengerRidingPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPassengerAttachmentPos(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/EntityDimensions;F)Lorg/joml/Vector3f;"))
public Vector3f revertStaticRidingOffsetCalculation(LivingEntity instance, Entity entity, EntityDimensions entityDimensions, float v) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
return new Vector3f(0.0F, entityDimensions.height * 0.75F, 0.0F);
}
return getPassengerAttachmentPos(entity, entityDimensions, v);
}
} }

View File

@ -133,4 +133,11 @@ public abstract class MixinPlayerEntity extends LivingEntity {
} }
return instance.isSprinting(); return instance.isSprinting();
} }
@Inject(method = "getUnscaledRidingOffset", at = @At("HEAD"), cancellable = true)
public void setStaticScale(Entity vehicle, CallbackInfoReturnable<Float> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
cir.setReturnValue(-0.35F);
}
}
} }