mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-28 22:05:01 +01:00
Fix crash making step sounds on servers.
This commit is contained in:
parent
0bb18db4b6
commit
65d21c374b
2 changed files with 18 additions and 18 deletions
|
@ -16,6 +16,7 @@ import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.gen.feature.template.Template;
|
import net.minecraft.world.gen.feature.template.Template;
|
||||||
import org.apache.logging.log4j.util.TriConsumer;
|
import org.apache.logging.log4j.util.TriConsumer;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
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.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -30,6 +31,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Mixin(Entity.class)
|
@Mixin(Entity.class)
|
||||||
public abstract class StepSoundMixin {
|
public abstract class StepSoundMixin {
|
||||||
|
private final Entity self = (Entity) (Object) this;
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public boolean collided;
|
public boolean collided;
|
||||||
|
@ -37,6 +39,7 @@ public abstract class StepSoundMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
public World world;
|
public World world;
|
||||||
|
|
||||||
|
@Final
|
||||||
@Shadow
|
@Shadow
|
||||||
protected Random rand;
|
protected Random rand;
|
||||||
|
|
||||||
|
@ -58,21 +61,20 @@ public abstract class StepSoundMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
protected abstract void playStepSound(BlockPos p_180429_1_, BlockState p_180429_2_);
|
protected abstract void playStepSound(BlockPos p_180429_1_, BlockState p_180429_2_);
|
||||||
|
|
||||||
private Set<AbstractContraptionEntity> getIntersectingContraptions(Entity entity) {
|
private Set<AbstractContraptionEntity> getIntersectingContraptions() {
|
||||||
Set<AbstractContraptionEntity> contraptions = ContraptionHandler.loadedContraptions.get(entity.world)
|
Set<AbstractContraptionEntity> contraptions = ContraptionHandler.loadedContraptions.get(this.world)
|
||||||
.values()
|
.values()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Reference::get)
|
.map(Reference::get)
|
||||||
.filter(cEntity -> cEntity != null && cEntity.collidingEntities.containsKey(entity))
|
.filter(cEntity -> cEntity != null && cEntity.collidingEntities.containsKey(self))
|
||||||
.collect(Collectors.toSet());
|
.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;
|
return contraptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forCollision(Vec3d anchorPos, TriConsumer<Contraption, BlockState, BlockPos> action) {
|
private void forCollision(Vec3d anchorPos, TriConsumer<Contraption, BlockState, BlockPos> action) {
|
||||||
Entity thi = (Entity) (Object) this;
|
getIntersectingContraptions().forEach(cEntity -> {
|
||||||
getIntersectingContraptions(thi).forEach(cEntity -> {
|
|
||||||
Vec3d localPos = ContraptionCollider.getWorldToLocalTranslation(anchorPos, cEntity);
|
Vec3d localPos = ContraptionCollider.getWorldToLocalTranslation(anchorPos, cEntity);
|
||||||
|
|
||||||
localPos = anchorPos.add(localPos);
|
localPos = anchorPos.add(localPos);
|
||||||
|
@ -90,15 +92,14 @@ public abstract class StepSoundMixin {
|
||||||
|
|
||||||
@Inject(at = @At(
|
@Inject(at = @At(
|
||||||
value = "JUMP",
|
value = "JUMP",
|
||||||
opcode = 154, //IFNE
|
opcode = 154, // IFNE line 587 injecting before `!blockstate.isAir(this.world, blockpos)`
|
||||||
ordinal = 4
|
ordinal = 4
|
||||||
),
|
),
|
||||||
method = "move"
|
method = "move"
|
||||||
)
|
)
|
||||||
private void movementMixin(MoverType mover, Vec3d movement, CallbackInfo ci) {
|
private void movementMixin(MoverType mover, Vec3d movement, CallbackInfo ci) {
|
||||||
Entity thi = (Entity) (Object) this;
|
|
||||||
World entityWorld = world;
|
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);
|
AtomicBoolean stepped = new AtomicBoolean(false);
|
||||||
|
|
||||||
forCollision(worldPos, (contraption, blockstate, blockPos) -> {
|
forCollision(worldPos, (contraption, blockstate, blockPos) -> {
|
||||||
|
@ -113,18 +114,17 @@ public abstract class StepSoundMixin {
|
||||||
world = entityWorld;
|
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) {
|
private void createRunningParticlesMixin(CallbackInfo ci) {
|
||||||
Entity thi = (Entity) (Object) this;
|
Vec3d worldPos = self.getPositionVector().add(0, -0.2, 0);
|
||||||
Vec3d worldPos = thi.getPositionVector().add(0, -0.2, 0);
|
|
||||||
BlockPos pos = new BlockPos(worldPos); // pos where particles are spawned
|
BlockPos pos = new BlockPos(worldPos); // pos where particles are spawned
|
||||||
|
|
||||||
forCollision(worldPos, (contraption, blockstate, blockpos) -> {
|
forCollision(worldPos, (contraption, blockstate, blockpos) -> {
|
||||||
if (!blockstate.addRunningEffects(world, blockpos, thi) && blockstate.getRenderType() != BlockRenderType.INVISIBLE) {
|
if (!blockstate.addRunningEffects(world, blockpos, self) && blockstate.getRenderType() != BlockRenderType.INVISIBLE) {
|
||||||
Vec3d vec3d = thi.getMotion();
|
Vec3d vec3d = self.getMotion();
|
||||||
this.world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, blockstate).setPos(pos),
|
this.world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, blockstate).setPos(pos),
|
||||||
thi.getX() + ((double) rand.nextFloat() - 0.5D) * (double) thi.getWidth(),
|
self.getX() + ((double) rand.nextFloat() - 0.5D) * (double) self.getWidth(),
|
||||||
thi.getY() + 0.1D, thi.getZ() + ((double) rand.nextFloat() - 0.5D) * (double) thi.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);
|
vec3d.x * -4.0D, 1.5D, vec3d.z * -4.0D);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
"package": "com.simibubi.create.foundation.mixin",
|
"package": "com.simibubi.create.foundation.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"refmap": "create.refmap.json",
|
"refmap": "create.refmap.json",
|
||||||
"mixins": ["StepSoundMixin"],
|
|
||||||
"client": [
|
"client": [
|
||||||
"TileWorldHookMixin",
|
"TileWorldHookMixin",
|
||||||
"CancelTileEntityRenderMixin",
|
"CancelTileEntityRenderMixin",
|
||||||
|
@ -13,7 +12,8 @@
|
||||||
"NetworkLightUpdateMixin",
|
"NetworkLightUpdateMixin",
|
||||||
"RenderHooksMixin",
|
"RenderHooksMixin",
|
||||||
"ShaderCloseMixin",
|
"ShaderCloseMixin",
|
||||||
"TileRemoveMixin"
|
"TileRemoveMixin",
|
||||||
|
"StepSoundMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Reference in a new issue