Fix crash making step sounds on servers.

This commit is contained in:
JozsefA 2021-03-30 18:50:07 -07:00
parent 0bb18db4b6
commit 65d21c374b
2 changed files with 18 additions and 18 deletions

View file

@ -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<AbstractContraptionEntity> getIntersectingContraptions(Entity entity) {
Set<AbstractContraptionEntity> contraptions = ContraptionHandler.loadedContraptions.get(entity.world)
private Set<AbstractContraptionEntity> getIntersectingContraptions() {
Set<AbstractContraptionEntity> 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<Contraption, BlockState, BlockPos> 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);
}
});

View file

@ -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