From 2dd7fbbb5530961f5bd25f2df72bfab81d3639bf Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 26 Mar 2024 00:04:00 +0000 Subject: [PATCH] Fix a whole bunch of gravity related issues --- .../unicopia/client/UnicopiaClient.java | 18 +++++ .../unicopia/entity/EntityPhysics.java | 10 +++ .../unicopia/entity/duck/RotatedView.java | 3 +- .../unicopia/entity/player/PlayerPhysics.java | 17 ----- .../unicopia/mixin/MixinLivingEntity.java | 10 --- .../unicopia/mixin/MixinMobEntity.java | 13 ---- .../unicopia/mixin/MixinPlayerEntity.java | 8 -- .../unicopia/mixin/MixinWorld.java | 30 -------- .../mixin/client/MixinKeyboardInput.java | 4 +- .../mixin/{ => gravity}/MixinBrain.java | 4 +- .../mixin/gravity/MixinClientWorld.java | 30 ++++++++ .../unicopia/mixin/gravity/MixinEntity.java | 76 +++++++++++++++++++ .../mixin/gravity/MixinLivingEntity.java | 22 ++++++ .../mixin/gravity/MixinMobEntity.java | 28 +++++++ .../mixin/gravity/MixinServerWorld.java | 29 +++++++ .../mixin/gravity/MixinSoundSource.java | 17 +++++ .../unicopia/mixin/gravity/MixinWorld.java | 43 +++++++++++ .../mixin/{ => gravity}/MixinWorldChunk.java | 2 +- src/main/resources/unicopia.mixin.json | 13 +++- 19 files changed, 290 insertions(+), 87 deletions(-) rename src/main/java/com/minelittlepony/unicopia/mixin/{ => gravity}/MixinBrain.java (87%) create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinClientWorld.java create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinEntity.java create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinLivingEntity.java create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinMobEntity.java create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinServerWorld.java create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinSoundSource.java create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinWorld.java rename src/main/java/com/minelittlepony/unicopia/mixin/{ => gravity}/MixinWorldChunk.java (96%) diff --git a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java index e7face1d..c8d9bcff 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java +++ b/src/main/java/com/minelittlepony/unicopia/client/UnicopiaClient.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.client; import java.util.Optional; import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; import com.minelittlepony.common.client.gui.element.Button; import com.minelittlepony.common.event.ScreenInitCallback; @@ -33,11 +34,14 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.OpenToLanScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreens; +import net.minecraft.client.render.Camera; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.resource.ResourceType; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; public class UnicopiaClient implements ClientModInitializer { @@ -66,6 +70,20 @@ public class UnicopiaClient implements ClientModInitializer { return Optional.empty(); } + + public static Vec3d getAdjustedSoundPosition(Vec3d pos) { + PlayerCamera cam = getCamera().orElse(null); + if (cam == null) { + return pos; + } + Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera(); + + Vector3f rotated = pos.subtract(camera.getPos()).toVector3f(); + rotated = rotated.rotateAxis(cam.calculateRoll() * MathHelper.RADIANS_PER_DEGREE, 0, 1, 0); + + return new Vec3d(rotated).add(camera.getPos()); + } + public static Race getPreferredRace() { if (!Unicopia.getConfig().ignoreMineLP.get() && MinecraftClient.getInstance().player != null) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java index 1529989b..538e7e4a 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java @@ -8,7 +8,9 @@ import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; import net.minecraft.block.FenceGateBlock; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityPose; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.MovementType; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.mob.MobEntity; import net.minecraft.nbt.NbtCompound; @@ -35,6 +37,14 @@ public class EntityPhysics implements Physics, Copyable entity.getWorld().getHeight() + 64) { entity.damage(entity.getDamageSources().outOfWorld(), 4.0F); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/duck/RotatedView.java b/src/main/java/com/minelittlepony/unicopia/entity/duck/RotatedView.java index e5c60d40..0bc5855b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/duck/RotatedView.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/duck/RotatedView.java @@ -39,7 +39,8 @@ public interface RotatedView { if (!hasTransform() || rotations.isEmpty()) { return y; } - return y - ((y - rotations.peek()) * 2); + + return (rotations.peek() * 2) - y; } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 35116ead..f6c82b63 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -32,7 +32,6 @@ import com.minelittlepony.unicopia.util.*; import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBlockTags; import net.minecraft.block.*; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityType; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.LightningEntity; @@ -253,18 +252,6 @@ public class PlayerPhysics extends EntityPhysics implements Tickab final MutableVector velocity = new MutableVector(entity.getVelocity()); - if (isGravityNegative()) { - velocity.y *= -1; - } - - if (isGravityNegative() && !entity.isSneaking() && entity.isInSneakingPose()) { - float currentHeight = entity.getDimensions(entity.getPose()).height; - float sneakingHeight = entity.getDimensions(EntityPose.STANDING).height; - - entity.setPos(entity.getX(), entity.getY() + currentHeight - sneakingHeight, entity.getZ()); - entity.setPose(EntityPose.STANDING); - } - FlightType type = recalculateFlightType(); boolean typeChanged = type != lastFlightType; @@ -396,10 +383,6 @@ public class PlayerPhysics extends EntityPhysics implements Tickab velocity.z /= heavyness; } - if (isGravityNegative()) { - velocity.y *= -1; - } - entity.setVelocity(velocity.toImmutable()); if (isFlying() && !entity.isFallFlying() && !pony.getAcrobatics().isHanging() && pony.isClient()) { diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java index f71ef863..b1e811b0 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java @@ -5,9 +5,7 @@ import java.util.Optional; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -178,14 +176,6 @@ abstract class MixinLivingEntity extends Entity implements LivingEntityDuck, Equ } } - @ModifyConstant(method = "travel(Lnet/minecraft/util/math/Vec3d;)V", constant = { - @Constant(doubleValue = 0.08D), - @Constant(doubleValue = 0.01D) - }) - private double modifyGravity(double initial) { - return get().getPhysics().calcGravity(initial); - } - @Override public void updateItemUsage(Hand hand, ItemStack stack, int time) { activeItemStack = stack; diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinMobEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinMobEntity.java index d836f0fc..d9200a75 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinMobEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinMobEntity.java @@ -9,7 +9,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.minelittlepony.unicopia.entity.*; -import com.minelittlepony.unicopia.entity.duck.RotatedView; import com.minelittlepony.unicopia.item.enchantment.WantItNeedItEnchantment; import net.minecraft.entity.EntityType; @@ -33,18 +32,6 @@ abstract class MixinMobEntity extends LivingEntity implements Equine.Container info) { diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java index d61ad769..b67432fc 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java @@ -97,14 +97,6 @@ abstract class MixinPlayerEntity extends LivingEntity implements Equine.Containe get().getMotion().getDimensions().calculateActiveEyeHeight(dimensions).ifPresent(info::setReturnValue); } - /* - @Inject(method = "getDimensions(Lnet/minecraft/entity/EntityPose;)Lnet/minecraft/entity/EntityDimensions;", - at = @At("RETURN"), - cancellable = true) - private void onGetDimensions(EntityPose pose, CallbackInfoReturnable info) { - get().getMotion().getDimensions().calculateDimensions().ifPresent(info::setReturnValue); - }*/ - @Redirect(method = "getDimensions(Lnet/minecraft/entity/EntityPose;)Lnet/minecraft/entity/EntityDimensions;", at = @At( value = "INVOKE", diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinWorld.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinWorld.java index 04db071b..99ca9150 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinWorld.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinWorld.java @@ -1,19 +1,13 @@ package com.minelittlepony.unicopia.mixin; -import java.util.Stack; import java.util.function.Supplier; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - import com.minelittlepony.unicopia.entity.duck.RotatedView; import com.minelittlepony.unicopia.server.world.BlockDestructionManager; -import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; @@ -22,20 +16,8 @@ abstract class MixinWorld implements WorldAccess, BlockDestructionManager.Source private final Supplier destructions = BlockDestructionManager.create((World)(Object)this); - private int recurseCount = 0; - private final Stack rotations = new Stack<>(); private boolean mirrorEntityStatuses; - @Override - public Stack getRotations() { - return rotations; - } - - @Override - public boolean hasTransform() { - return recurseCount <= 0; - } - @Override public void setMirrorEntityStatuses(boolean enable) { mirrorEntityStatuses = enable; @@ -52,17 +34,5 @@ abstract class MixinWorld implements WorldAccess, BlockDestructionManager.Source entity.handleStatus(status); } } - - @ModifyVariable(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD")) - private BlockPos modifyBlockPos(BlockPos pos) { - pos = applyRotation(pos); - recurseCount = Math.max(0, recurseCount) + 1; - return pos; - } - - @Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("RETURN")) - public void onSetBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable info) { - recurseCount = Math.max(0, recurseCount - 1); - } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java index 7bc83f17..55c8a70b 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java @@ -28,11 +28,11 @@ abstract class MixinKeyboardInput extends Input { movementSideways = -movementSideways; - if (player.asEntity().getAbilities().flying && !player.getPhysics().isFlying()) { + /*if (player.asEntity().getAbilities().flying && !player.getPhysics().isFlying()) { tmp = jumping; jumping = sneaking; sneaking = tmp; - } + }*/ } if (EffectUtils.getAmplifier(MinecraftClient.getInstance().player, UEffects.PARALYSIS) > 1) { diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinBrain.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinBrain.java similarity index 87% rename from src/main/java/com/minelittlepony/unicopia/mixin/MixinBrain.java rename to src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinBrain.java index 7a7a7737..4e794c6a 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinBrain.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinBrain.java @@ -1,4 +1,4 @@ -package com.minelittlepony.unicopia.mixin; +package com.minelittlepony.unicopia.mixin.gravity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -21,7 +21,7 @@ abstract class MixinBrain { Equine eq = Equine.of(entity).orElse(null); if (eq instanceof Living && eq.getPhysics().isGravityNegative()) { - ((RotatedView)world).pushRotation((int)entity.getY()); + ((RotatedView)world).pushRotation((int)(entity.getY() + entity.getHeight() * 0.5F)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinClientWorld.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinClientWorld.java new file mode 100644 index 00000000..98701eec --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinClientWorld.java @@ -0,0 +1,30 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minelittlepony.unicopia.entity.Equine; +import com.minelittlepony.unicopia.entity.duck.RotatedView; + +import net.minecraft.client.world.ClientWorld; +import net.minecraft.entity.Entity; + +@Mixin(ClientWorld.class) +abstract class MixinClientWorld implements RotatedView { + + @Inject(method = "tickEntity", at = @At("HEAD")) + private void beforeTickEntity(Entity entity, CallbackInfo info) { + if (entity instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + // pushRotation((int)(entity.getY() + entity.getHeight() * 0.5F)); + } + } + + @Inject(method = "tickEntity", at = @At("RETURN")) + private void afterTickEntity(Entity entity, CallbackInfo info) { + if (entity instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + // popRotation(); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinEntity.java new file mode 100644 index 00000000..c0725d94 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinEntity.java @@ -0,0 +1,76 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.minelittlepony.unicopia.entity.Equine; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.MovementType; +import net.minecraft.util.math.Vec3d; + +@Mixin(value = Entity.class, priority = 29000) +abstract class MixinEntity { + + // we invert y when moving + @ModifyVariable(method = "move", at = @At("HEAD"), argsOnly = true) + private Vec3d modifyMovement(Vec3d movement) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + return movement.multiply(1, -1, 1); + } + return movement; + } + + // fix on ground check + @Inject(method = "move", at = @At(value = "FIELD", target = "net/minecraft/entity/Entity.groundCollision:Z", shift = Shift.AFTER, ordinal = 0)) + private void onUpdateOnGroundFlag(MovementType movementType, Vec3d movement, CallbackInfo info) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + eq.get().asEntity().groundCollision = eq.get().asEntity().verticalCollision && movement.y > 0.0; + } + } + + // invert jumping velocity so we can jump + @Inject(method = "getJumpVelocityMultiplier", at = @At("RETURN"), cancellable = true) + private void onGetJumpVelocityMultiplier(CallbackInfoReturnable info) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + info.setReturnValue(-info.getReturnValue()); + } + } + + // invert offsets so it can properly find the block we're walking on + @ModifyVariable(method = "getPosWithYOffset", at = @At("HEAD"), argsOnly = true) + private float onGetPosWithYOffset(float offset) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + return -(eq.get().asEntity().getHeight() + offset); + } + return offset; + } + + // fix sprinting particles + @Inject(method = "spawnSprintingParticles", at = @At("HEAD"), cancellable = true) + protected void spawnSprintingParticles(CallbackInfo info) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + eq.get().getPhysics().spawnSprintingParticles(); + info.cancel(); + } + } + + // invert check for walking up a step + @ModifyVariable( + method = "adjustMovementForCollisions(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Box;Lnet/minecraft/world/World;Ljava/util/List;)Lnet/minecraft/util/math/Vec3d;", + at = @At("HEAD"), + argsOnly = true) + + private static Vec3d modifyMovementForStepheight(Vec3d movement, @Nullable Entity entity) { + if (entity != null && movement.getY() == entity.getStepHeight()) { + return movement.multiply(1, -1, 1); + } + return movement; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinLivingEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinLivingEntity.java new file mode 100644 index 00000000..2d9dfe6c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinLivingEntity.java @@ -0,0 +1,22 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; +import com.minelittlepony.unicopia.entity.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; + +@Mixin(LivingEntity.class) +abstract class MixinLivingEntity extends Entity implements Equine.Container> { + + private MixinLivingEntity() { super(null, null); } + + @ModifyConstant(method = "travel(Lnet/minecraft/util/math/Vec3d;)V", constant = { + @Constant(doubleValue = 0.08D), + @Constant(doubleValue = 0.01D) + }) + private double modifyGravity(double initial) { + return Math.abs(get().getPhysics().calcGravity(initial)); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinMobEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinMobEntity.java new file mode 100644 index 00000000..e72ec42a --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinMobEntity.java @@ -0,0 +1,28 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.minelittlepony.unicopia.entity.*; +import com.minelittlepony.unicopia.entity.duck.RotatedView; + +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.mob.MobEntity; + +@Mixin(MobEntity.class) +abstract class MixinMobEntity extends LivingEntity implements Equine.Container { + private MixinMobEntity() { super(null, null); } + + @Inject(method = "tickNewAi", at = @At("HEAD")) + public void beforeTickAi(CallbackInfo into) { + if (get().getPhysics().isGravityNegative()) { + ((RotatedView)getWorld()).pushRotation((int)(getY() + getHeight() * 0.5F)); + } + } + + @Inject(method = "tickNewAi", at = @At("RETURN")) + public void afterTickAi(CallbackInfo into) { + ((RotatedView)getWorld()).popRotation(); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinServerWorld.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinServerWorld.java new file mode 100644 index 00000000..d43d1570 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinServerWorld.java @@ -0,0 +1,29 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.minelittlepony.unicopia.entity.Equine; +import com.minelittlepony.unicopia.entity.duck.RotatedView; +import net.minecraft.entity.Entity; +import net.minecraft.server.world.ServerWorld; + +@Mixin(ServerWorld.class) +abstract class MixinServerWorld implements RotatedView { + + @Inject(method = "tickEntity", at = @At("HEAD")) + private void beforeTickEntity(Entity entity, CallbackInfo info) { + if (entity instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + // pushRotation((int)(entity.getY() + entity.getHeight() * 0.5F)); + } + } + + @Inject(method = "tickEntity", at = @At("RETURN")) + private void afterTickEntity(Entity entity, CallbackInfo info) { + if (entity instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + // popRotation(); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinSoundSource.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinSoundSource.java new file mode 100644 index 00000000..7ffbad9f --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinSoundSource.java @@ -0,0 +1,17 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +import com.minelittlepony.unicopia.client.UnicopiaClient; +import net.minecraft.client.sound.Source; +import net.minecraft.util.math.Vec3d; + +@Mixin(Source.class) +abstract class MixinSoundSource { + @ModifyVariable(method = "setPosition", at = @At("HEAD"), argsOnly = true) + private Vec3d modifyPosition(Vec3d pos) { + return UnicopiaClient.getAdjustedSoundPosition(pos); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinWorld.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinWorld.java new file mode 100644 index 00000000..71428388 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinWorld.java @@ -0,0 +1,43 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import java.util.Stack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.minelittlepony.unicopia.entity.duck.RotatedView; +import net.minecraft.block.BlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; + +@Mixin(World.class) +abstract class MixinWorld implements WorldAccess, RotatedView { + + private int recurseCount = 0; + private final Stack rotations = new Stack<>(); + + @Override + public Stack getRotations() { + return rotations; + } + + @Override + public boolean hasTransform() { + return recurseCount <= 0; + } + + @ModifyVariable(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD")) + private BlockPos modifyBlockPos(BlockPos pos) { + pos = applyRotation(pos); + recurseCount = Math.max(0, recurseCount) + 1; + return pos; + } + + @Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("RETURN")) + public void onSetBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable info) { + recurseCount = Math.max(0, recurseCount - 1); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinWorldChunk.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinWorldChunk.java similarity index 96% rename from src/main/java/com/minelittlepony/unicopia/mixin/MixinWorldChunk.java rename to src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinWorldChunk.java index 97f137d8..4a3c2ced 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinWorldChunk.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinWorldChunk.java @@ -1,4 +1,4 @@ -package com.minelittlepony.unicopia.mixin; +package com.minelittlepony.unicopia.mixin.gravity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index d59bf63e..0d34a3bf 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -13,7 +13,6 @@ "MixinBlockEntityType", "MixinBlockItem", "MixinBoatEntity", - "MixinBrain", "MixinChunkBlockLightProvider", "MutableBlockLightStorage", "MixinDamageSource", @@ -53,8 +52,14 @@ "MixinVanillaBiomeParameters", "MixinWardenEntity", "MixinWorld", - "MixinWorldChunk", "PointOfInterestTypesAccessor", + "gravity.MixinBrain", + "gravity.MixinEntity", + "gravity.MixinLivingEntity", + "gravity.MixinMobEntity", + "gravity.MixinWorld", + "gravity.MixinServerWorld", + "gravity.MixinWorldChunk", "trinkets.MixinTrinketSurvivalSlot", "trinkets.MixinTrinketItem", "trinkets.MixinTrinketInventory", @@ -88,7 +93,9 @@ "client.MixinWorldRenderer", "client.sodium.MixinSodiumWorldRenderer", "client.minelp.MixinPonyPosture", - "trinkets.MixinTrinketCreativeSlot" + "trinkets.MixinTrinketCreativeSlot", + "gravity.MixinClientWorld", + "gravity.MixinSoundSource" ], "injectors": { "defaultRequire": 1