improve portal gun perf

This commit is contained in:
craisinlord committed 2026-10-12 15:00:42 -05:00
1 parent 759f511b00
commit 0cad456efd
17 files changed
+348 -126

No files matched your search

@@ -2,6 +2,8 @@ package com.craisinlord.antarchy.content.item;
import com.craisinlord.antarchy.content.AntarchySoundEvents;
import com.craisinlord.antarchy.content.entity.WormHookProjectileEntity;
import com.craisinlord.antarchy.content.gravity.AntarchyGravityApi;
import com.craisinlord.antarchy.content.gravity.AntarchyGravityRotationUtil;
import com.craisinlord.antarchy.content.util.WormHookRope;
import java.util.Map;
import java.util.UUID;
@@ -139,9 +141,9 @@ public final class WormHookTetherManager {
// the max length (which alone has no effect until the rope goes taut).
if (reeling && dist > MIN_LEN) {
Vec3 pull = towardPivot.scale(-REEL_PULL_STRENGTH);
Vec3 reelMotion = player.getDeltaMovement().add(pull);
Vec3 reelMotion = getWorldMotion(player).add(pull);
reelMotion = new Vec3(reelMotion.x, Mth.clamp(reelMotion.y, -0.6D, 0.6D), reelMotion.z);
player.setDeltaMovement(reelMotion);
setWorldMotion(player, reelMotion);
player.hurtMarked = true;
player.fallDistance = 0;
}
@@ -158,7 +160,7 @@ public final class WormHookTetherManager {
return;
}
Vec3 motion = player.getDeltaMovement();
Vec3 motion = getWorldMotion(player);
double outward = motion.dot(towardPivot);
if (outward > 0) {
motion = motion.subtract(towardPivot.scale(outward));
@@ -167,11 +169,19 @@ public final class WormHookTetherManager {
Vec3 correction = towardPivot.scale(-overshoot * PULL_CORRECTION);
Vec3 newMotion = motion.add(correction);
newMotion = new Vec3(newMotion.x, Mth.clamp(newMotion.y, -1.0D, 1.0D), newMotion.z);
player.setDeltaMovement(newMotion);
setWorldMotion(player, newMotion);
player.hurtMarked = true;
player.fallDistance = 0;
}
private static Vec3 getWorldMotion(ServerPlayer player) {
return AntarchyGravityRotationUtil.vecPlayerToWorld(player.getDeltaMovement(), AntarchyGravityApi.getGravityDirection(player));
}
private static void setWorldMotion(ServerPlayer player, Vec3 worldMotion) {
player.setDeltaMovement(AntarchyGravityRotationUtil.vecWorldToPlayer(worldMotion, AntarchyGravityApi.getGravityDirection(player)));
}
private static void tickFlyingSound(ServerPlayer player, TetherState state) {
if (state.flyingSoundCooldown > 0) {
state.flyingSoundCooldown--;
@@ -1,35 +1,41 @@
package com.craisinlord.antarchy.mixins.gravity;
import com.craisinlord.antarchy.content.gravity.AntarchyGravityApi;
import com.craisinlord.antarchy.content.gravity.AntarchyGravityDirection;
import com.craisinlord.antarchy.content.gravity.AntarchyGravityRotationUtil;
import com.craisinlord.antarchy.config.AntarchySettings;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.world.item.Item;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
@Mixin(FireworkRocketEntity.class)
/*
* Fixes firework boost dir for inverted elytra flight.
*/
public abstract class FireworkRocketGravityMixin {
@Shadow
@Nullable
private LivingEntity attachedToEntity;
@WrapOperation(method = "tick",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/LivingEntity;getLookAngle()Lnet/minecraft/world/phys/Vec3;"))
private Vec3 antarchy$fixFireworkThrustDirection(LivingEntity entity, Operation<Vec3> original) {
Vec3 look = original.call(entity);
AntarchyGravityDirection direction = AntarchyGravityApi.getGravityDirection(entity);
if (!direction.isInverted()) {
return look;
}
return AntarchyGravityRotationUtil.vecWorldToPlayer(look, direction);
}
@ModifyVariable(method = "tick", at = @At(value = "STORE"), ordinal = 0)
private Vec3 antarchy$fixFireworkThrustDirection(Vec3 velocity) {
if (!(this.attachedToEntity instanceof Player player)) return velocity;
if (!AntarchyGravityApi.isGravityInverted(player)) return velocity;
return AntarchyGravityRotationUtil.vecWorldToPlayer(
velocity,
AntarchyGravityApi.getGravityDirection(player)
);
@WrapOperation(method = "tick",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/entity/LivingEntity;getHandHoldingItemAngle(Lnet/minecraft/world/item/Item;)Lnet/minecraft/world/phys/Vec3;"))
private Vec3 antarchy$rotateAttachedRocketOffset(LivingEntity entity, Item item, Operation<Vec3> original) {
Vec3 offset = original.call(entity, item);
AntarchyGravityDirection direction = AntarchyGravityApi.getGravityDirection(entity);
if (!direction.isInverted()) {
return offset;
}
return AntarchyGravityRotationUtil.vecPlayerToWorld(offset, direction);
}
}
@@ -39,6 +39,15 @@ public abstract class LivingEntityMixin {
return AntarchyGravityRotationUtil.vecWorldToPlayer(entity.position(), direction).y;
}
@WrapOperation(method = "travel",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;getLookAngle()Lnet/minecraft/world/phys/Vec3;"))
private Vec3 antarchy$fixTravelLookAngle(LivingEntity entity, Operation<Vec3> original) {
Vec3 look = original.call(entity);
AntarchyGravityDirection direction = AntarchyGravityApi.getGravityDirection(entity);
if (!direction.isInverted() || !entity.isFallFlying()) return look;
return AntarchyGravityRotationUtil.vecWorldToPlayer(look, direction);
}
@ModifyVariable(method = "checkFallDamage", at = @At("HEAD"), ordinal = 0, argsOnly = true)
private double antarchy$invertLivingFallDamageY(double worldY) {
LivingEntity entity = (LivingEntity) (Object) this;