diff options
Diffstat (limited to 'src/main/java/wtf/kity/uncrackable/mixin/DragonEggBlockMixin.java')
| -rw-r--r-- | src/main/java/wtf/kity/uncrackable/mixin/DragonEggBlockMixin.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/wtf/kity/uncrackable/mixin/DragonEggBlockMixin.java b/src/main/java/wtf/kity/uncrackable/mixin/DragonEggBlockMixin.java new file mode 100644 index 0000000..7690985 --- /dev/null +++ b/src/main/java/wtf/kity/uncrackable/mixin/DragonEggBlockMixin.java @@ -0,0 +1,64 @@ +package wtf.kity.uncrackable.mixin; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.util.Mth; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.DragonEggBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.border.WorldBorder; +import net.minecraft.world.level.material.PushReaction; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(DragonEggBlock.class) +public class DragonEggBlockMixin { + @ModifyVariable(method = "<init>", at = @At("HEAD"), ordinal = 0, argsOnly = true) + private static BlockBehaviour.Properties init(BlockBehaviour.Properties properties) { + return properties + .pushReaction(PushReaction.NORMAL) + .strength(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); + } + + /** + * @author ashkitten + * @reason fixing MC-2157 + */ + @Overwrite + private void teleport(BlockState state, Level level, BlockPos pos) { + if (level instanceof ServerLevel serverLevel) { + WorldBorder worldborder = level.getWorldBorder(); + + for (int i = 0; i < 1000; i++) { + BlockPos blockpos = pos.offset( + level.random.nextInt(16) - level.random.nextInt(16), + level.random.nextInt(8) - level.random.nextInt(8), + level.random.nextInt(16) - level.random.nextInt(16) + ); + if (level.getBlockState(blockpos).isAir() && worldborder.isWithinBounds(blockpos)) { + // slightly different behavior than vanilla, since we send 32x4 particles evenly distributed + // instead of 1x128 randomly distributed, but it actually points in the right fucking direction lol + for (int j = 0; j < 32; j++) { + double d0 = j / 32.0; + double d1 = Mth.lerp(d0, blockpos.getX(), pos.getX()) + (level.random.nextDouble() - 0.5) + 0.5; + double d2 = Mth.lerp(d0, blockpos.getY(), pos.getY()) + level.random.nextDouble() - 0.5; + double d3 = Mth.lerp(d0, blockpos.getZ(), pos.getZ()) + (level.random.nextDouble() - 0.5) + 0.5; + serverLevel.sendParticles(ParticleTypes.PORTAL, d1, d2, d3, 4, 0.1, 0.1, 0.1, 0.0); + } + + level.setBlock(blockpos, state, 2); + level.removeBlock(pos, false); + level.playSound(null, pos, SoundEvents.ENDERMAN_TELEPORT, SoundSource.BLOCKS); + + return; + } + } + } + } +} |