diff --git a/src/main/java/com/simibubi/create/foundation/mixin/StepSoundMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/StepSoundMixin.java index ba640af84..f7ecb40c2 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/StepSoundMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/StepSoundMixin.java @@ -16,6 +16,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.gen.feature.template.Template; import org.apache.logging.log4j.util.TriConsumer; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -30,6 +31,7 @@ import java.util.stream.Collectors; @Mixin(Entity.class) public abstract class StepSoundMixin { + private final Entity self = (Entity) (Object) this; @Shadow public boolean collided; @@ -37,6 +39,7 @@ public abstract class StepSoundMixin { @Shadow public World world; + @Final @Shadow protected Random rand; @@ -58,21 +61,20 @@ public abstract class StepSoundMixin { @Shadow protected abstract void playStepSound(BlockPos p_180429_1_, BlockState p_180429_2_); - private Set getIntersectingContraptions(Entity entity) { - Set contraptions = ContraptionHandler.loadedContraptions.get(entity.world) + private Set getIntersectingContraptions() { + Set contraptions = ContraptionHandler.loadedContraptions.get(this.world) .values() .stream() .map(Reference::get) - .filter(cEntity -> cEntity != null && cEntity.collidingEntities.containsKey(entity)) + .filter(cEntity -> cEntity != null && cEntity.collidingEntities.containsKey(self)) .collect(Collectors.toSet()); - contraptions.addAll(entity.world.getEntitiesWithinAABB(AbstractContraptionEntity.class, getBoundingBox().grow(1f))); + contraptions.addAll(this.world.getEntitiesWithinAABB(AbstractContraptionEntity.class, getBoundingBox().grow(1f))); return contraptions; } private void forCollision(Vec3d anchorPos, TriConsumer action) { - Entity thi = (Entity) (Object) this; - getIntersectingContraptions(thi).forEach(cEntity -> { + getIntersectingContraptions().forEach(cEntity -> { Vec3d localPos = ContraptionCollider.getWorldToLocalTranslation(anchorPos, cEntity); localPos = anchorPos.add(localPos); @@ -90,15 +92,14 @@ public abstract class StepSoundMixin { @Inject(at = @At( value = "JUMP", - opcode = 154, //IFNE + opcode = 154, // IFNE line 587 injecting before `!blockstate.isAir(this.world, blockpos)` ordinal = 4 ), method = "move" ) private void movementMixin(MoverType mover, Vec3d movement, CallbackInfo ci) { - Entity thi = (Entity) (Object) this; World entityWorld = world; - Vec3d worldPos = thi.getPositionVector().add(0, -0.2, 0); + Vec3d worldPos = self.getPositionVector().add(0, -0.2, 0); AtomicBoolean stepped = new AtomicBoolean(false); forCollision(worldPos, (contraption, blockstate, blockPos) -> { @@ -113,18 +114,17 @@ public abstract class StepSoundMixin { world = entityWorld; } - @Inject(method = {"Lnet/minecraft/entity/Entity;createRunningParticles()V"}, at = @At(value = "TAIL")) + @Inject(method = "createRunningParticles", at = @At("TAIL")) private void createRunningParticlesMixin(CallbackInfo ci) { - Entity thi = (Entity) (Object) this; - Vec3d worldPos = thi.getPositionVector().add(0, -0.2, 0); + Vec3d worldPos = self.getPositionVector().add(0, -0.2, 0); BlockPos pos = new BlockPos(worldPos); // pos where particles are spawned forCollision(worldPos, (contraption, blockstate, blockpos) -> { - if (!blockstate.addRunningEffects(world, blockpos, thi) && blockstate.getRenderType() != BlockRenderType.INVISIBLE) { - Vec3d vec3d = thi.getMotion(); + if (!blockstate.addRunningEffects(world, blockpos, self) && blockstate.getRenderType() != BlockRenderType.INVISIBLE) { + Vec3d vec3d = self.getMotion(); this.world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, blockstate).setPos(pos), - thi.getX() + ((double) rand.nextFloat() - 0.5D) * (double) thi.getWidth(), - thi.getY() + 0.1D, thi.getZ() + ((double) rand.nextFloat() - 0.5D) * (double) thi.getWidth(), + self.getX() + ((double) rand.nextFloat() - 0.5D) * (double) self.getWidth(), + self.getY() + 0.1D, self.getZ() + ((double) rand.nextFloat() - 0.5D) * (double) self.getWidth(), vec3d.x * -4.0D, 1.5D, vec3d.z * -4.0D); } }); diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 24c2db2a5..3ee1cb74c 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -4,7 +4,6 @@ "package": "com.simibubi.create.foundation.mixin", "compatibilityLevel": "JAVA_8", "refmap": "create.refmap.json", - "mixins": ["StepSoundMixin"], "client": [ "TileWorldHookMixin", "CancelTileEntityRenderMixin", @@ -13,7 +12,8 @@ "NetworkLightUpdateMixin", "RenderHooksMixin", "ShaderCloseMixin", - "TileRemoveMixin" + "TileRemoveMixin", + "StepSoundMixin" ], "injectors": { "defaultRequire": 1