diff options
Diffstat (limited to 'src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening')
6 files changed, 149 insertions, 399 deletions
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantPartBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantPartBlockMixin.java new file mode 100644 index 0000000..fc12e01 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantPartBlockMixin.java @@ -0,0 +1,48 @@ +package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; + +import com.keuin.ohmyvanillamc.OmvmSettings; +import net.minecraft.block.AbstractPlantPartBlock; +import net.minecraft.block.AbstractPlantStemBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +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 java.util.Random; + +@Mixin(AbstractPlantPartBlock.class) +public abstract class AbstractPlantPartBlockMixin extends Block { + + public AbstractPlantPartBlockMixin(Settings settings) { + super(settings); + } + + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTick_mixin1(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableStemForceRipening) + ci.cancel(); + } + + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTick_mixin2(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + AbstractPlantPartBlock $this = (AbstractPlantPartBlock) (Object) this; + if (OmvmSettings.enableStemForceRipening && ($this instanceof AbstractPlantStemBlock)) + $this.randomTick(state, world, pos, random); + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java deleted file mode 100644 index 1092816..0000000 --- a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; - -import com.keuin.ohmyvanillamc.OmvmSettings; -import net.minecraft.block.AbstractPlantPartBlock; -import net.minecraft.block.AbstractPlantStemBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.shape.VoxelShape; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Random; - -@Mixin(AbstractPlantStemBlock.class) -public abstract class AbstractPlantStemBlockMixin extends AbstractPlantPartBlock { - - protected AbstractPlantStemBlockMixin(Settings settings, Direction growthDirection, VoxelShape outlineShape, boolean tickWater) { - super(settings, growthDirection, outlineShape, tickWater); - } - - @Shadow - @Final - public static IntProperty AGE; - - @Shadow - @Final - private double growthChance; - - @Shadow - protected abstract boolean chooseStemState(BlockState state); - - /** - * @reason Revert to the super class's impl (Block's). - * @author trueKeuin - */ - @Overwrite - public boolean hasRandomTicks(BlockState state) { - return super.hasRandomTicks(state); - } - - /** - * Reintroduce the MC-113809 glitch for kelp, twisted vine and weeping vine. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for kelp, twisted vine and weeping vine. - */ - @Override - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OmvmSettings.enableStemForceRipening) { - realGrow(state, world, pos, random); - } - } - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OmvmSettings.enableStemForceRipening) { - scheduledTick(state, world, pos, random); - } else { - realGrow(state, world, pos, random); - } - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (state.get(AGE) < 25 && random.nextDouble() < this.growthChance) { - BlockPos blockPos = pos.offset(this.growthDirection); - if (this.chooseStemState(world.getBlockState(blockPos))) { - world.setBlockState(blockPos, state.cycle(AGE)); - } - } - } - -} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java index 0dd9be6..5d692c1 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java @@ -5,14 +5,12 @@ import net.minecraft.block.BambooBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Random; @@ -24,67 +22,28 @@ public abstract class BambooBlockMixin extends Block { } @Shadow - @Final - public static IntProperty STAGE; - - @Shadow - protected abstract int countBambooBelow(BlockView world, BlockPos pos); - - @Shadow - protected abstract void updateLeaves(BlockState state, World world, BlockPos pos, Random random, int height); - - /** - * Reintroduce the base class's implementation. - * - * @reason reintroduce base class's implementation. - * @author trueKeuin - */ - @Overwrite - public boolean hasRandomTicks(BlockState state) { - boolean zf = OmvmSettings.enableBambooForceRipening; - return ((state.get(STAGE) == 0) && !zf) || (randomTicks && zf); + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTick_mixin1(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableBambooForceRipening) + ci.cancel(); } - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OmvmSettings.enableBambooForceRipening) { - scheduledTick(state, world, pos, random); - } else { - realGrow(state, world, pos, random); - } + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTick_mixin2(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableBambooForceRipening) + this.randomTick(state, world, pos, random); } - - /** - * Reintroduce the MC-113809 glitch for bamboo. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for bamboo. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OmvmSettings.enableBambooForceRipening) { - realGrow(state, world, pos, random); - } - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (state.get(STAGE) == 0) { - if (random.nextInt(3) == 0 && world.isAir(pos.up()) && world.getBaseLightLevel(pos.up(), 0) >= 9) { - int i = this.countBambooBelow(world, pos) + 1; - if (i < 16) { - this.updateLeaves(state, world, pos, random, i); - } - } - } - } - } diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java index d5feaf9..94f024e 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java @@ -5,12 +5,12 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.CactusBlock; import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Random; @@ -22,60 +22,28 @@ public abstract class CactusBlockMixin extends Block { } @Shadow - @Final - public static IntProperty AGE; - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OmvmSettings.enableCactusForceRipening) { - scheduledTick(state, world, pos, random); - } else { - // here goes 1.16.4 version randomTick impl. - realGrow(state, world, pos); - } - } - - /** - * Reintroduce the MC-113809 glitch for cactus. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for cactus. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OmvmSettings.enableCactusForceRipening) { - realGrow(state, world, pos); - } + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTick_mixin1(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableCactusForceRipening) + ci.cancel(); } - private void realGrow(BlockState state, ServerWorld world, BlockPos pos) { - BlockPos blockPos = pos.up(); - if (world.isAir(blockPos)) { - int i; - for (i = 1; world.getBlockState(pos.down(i)).isOf(this); ++i) { - } - - if (i < 3) { - int j = state.get(AGE); - if (j == 15) { - world.setBlockState(blockPos, this.getDefaultState()); - BlockState blockState = state.with(AGE, 0); - world.setBlockState(pos, blockState, 4); - blockState.neighborUpdate(world, blockPos, this, pos, false); - } else { - world.setBlockState(pos, state.with(AGE, j + 1), 4); - } - - } - } + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTick_mixin2(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableCactusForceRipening) + this.randomTick(state, world, pos, random); } } diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java index fb79848..74c0fd0 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java @@ -1,18 +1,16 @@ package com.keuin.ohmyvanillamc.mixins.rule.forceRipening; import com.keuin.ohmyvanillamc.OmvmSettings; -import net.minecraft.block.*; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.ChorusFlowerBlock; import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import net.minecraft.world.WorldView; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Random; @@ -24,139 +22,28 @@ public abstract class ChorusFlowerBlockMixin extends Block { } @Shadow - @Final - public static IntProperty AGE; - - @Shadow - @Final - private ChorusPlantBlock plantBlock; - - @Shadow - private static boolean isSurroundedByAir(WorldView world, BlockPos pos, @Nullable Direction exceptDirection) { - throw new RuntimeException("Mixin error. Program should not go here."); - } - - @Shadow - private void grow(World world, BlockPos pos, int age) { - throw new RuntimeException("Mixin error. Program should not go here."); - } - - @Shadow - private void die(World world, BlockPos pos) { - throw new RuntimeException("Mixin error. Program should not go here."); - } - - /** - * Reintroduce the MC-113809 glitch for chorus flower. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for chorus flower. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (OmvmSettings.enableChorusFlowerForceRipening) { - realGrow(state, world, pos, random); - } - - } - - /** - * Reintroduce the base class's implementation. - * - * @reason reintroduce base class's implementation. - * @author trueKeuin - */ - @Overwrite - public boolean hasRandomTicks(BlockState state) { - boolean zf = OmvmSettings.enableChorusFlowerForceRipening; - return ((state.get(AGE) < 5) && !zf) || (randomTicks && zf); + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTick_mixin1(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableChorusFlowerForceRipening) + ci.cancel(); + } + + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTick_mixin2(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableChorusFlowerForceRipening) + this.randomTick(state, world, pos, random); } - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OmvmSettings.enableChorusFlowerForceRipening) { - scheduledTick(state, world, pos, random); - } else { - realGrow(state, world, pos, random); - } - - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos, Random random) { - BlockPos blockPos = pos.up(); - if (world.isAir(blockPos) && blockPos.getY() < 256) { - int i = state.get(AGE); - if (i < 5) { - boolean bl = false; - boolean bl2 = false; - BlockState blockState = world.getBlockState(pos.down()); - Block block = blockState.getBlock(); - int l; - if (block == Blocks.END_STONE) { - bl = true; - } else if (block == this.plantBlock) { - l = 1; - - for (int k = 0; k < 4; ++k) { - Block block2 = world.getBlockState(pos.down(l + 1)).getBlock(); - if (block2 != this.plantBlock) { - if (block2 == Blocks.END_STONE) { - bl2 = true; - } - break; - } - - ++l; - } - - if (l < 2 || l <= random.nextInt(bl2 ? 5 : 4)) { - bl = true; - } - } else if (blockState.isAir()) { - bl = true; - } - - if (bl && isSurroundedByAir(world, blockPos, (Direction) null) && world.isAir(pos.up(2))) { - world.setBlockState(pos, this.plantBlock.withConnectionProperties(world, pos), 2); - this.grow(world, blockPos, i); - } else if (i < 4) { - l = random.nextInt(4); - if (bl2) { - ++l; - } - - boolean bl3 = false; - - for (int m = 0; m < l; ++m) { - Direction direction = Direction.Type.HORIZONTAL.random(random); - BlockPos blockPos2 = pos.offset(direction); - if (world.isAir(blockPos2) && world.isAir(blockPos2.down()) && isSurroundedByAir(world, blockPos2, direction.getOpposite())) { - this.grow(world, blockPos2, i + 1); - bl3 = true; - } - } - - if (bl3) { - world.setBlockState(pos, this.plantBlock.withConnectionProperties(world, pos), 2); - } else { - this.die(world, pos); - } - } else { - this.die(world, pos); - } - - } - } - } - - } diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java index 6cce2a3..e94283e 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java @@ -5,12 +5,12 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.SugarCaneBlock; import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.IntProperty; import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Random; @@ -22,54 +22,28 @@ public abstract class SugarCaneBlockMixin extends Block { } @Shadow - @Final - public static IntProperty AGE; - - /** - * Revert to base class (Block) implementation of randomTick: just simply call scheduledTick. - * (both 1.15.2 and 1.16.4 are the same) - * - * @author trueKeuin - * @reason revert to the base class `Block` implementation. - */ - @Overwrite - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (OmvmSettings.enableSugarCaneForceRipening) { - scheduledTick(state, world, pos, random); - } else if (world.isAir(pos.up())) { // here goes 1.16.4 version randomTick impl. - realGrow(state, world, pos); - } - + public abstract void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random); + + @Inject( + method = "scheduledTick", + at = @At( + value = "INVOKE", + shift = At.Shift.AFTER, + target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ), + cancellable = true + ) + private void scheduleTick_mixin1(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableSugarCaneForceRipening) + ci.cancel(); } - /** - * Reintroduce the MC-113809 glitch for sugar cane. The implementation is identical to Minecraft 1.15.2. - * - * @author trueKeuin - * @reason reintroduce MC-113809 for sugar cane. - */ - @Overwrite - public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - if (!state.canPlaceAt(world, pos)) { - world.breakBlock(pos, true); - } else if (world.isAir(pos.up()) && OmvmSettings.enableSugarCaneForceRipening) { - realGrow(state, world, pos); - } - } - - private void realGrow(BlockState state, ServerWorld world, BlockPos pos) { - int i; - for (i = 1; world.getBlockState(pos.down(i)).isOf((SugarCaneBlock) (Object) this); ++i) { - } - - if (i < 3) { - int j = state.get(AGE); - if (j == 15) { - world.setBlockState(pos.up(), this.getDefaultState()); - world.setBlockState(pos, state.with(AGE, 0), 4); - } else { - world.setBlockState(pos, state.with(AGE, j + 1), 4); - } - } + @Inject( + method = "scheduledTick", + at = @At("TAIL") + ) + private void scheduleTick_mixin2(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + if (OmvmSettings.enableSugarCaneForceRipening) + this.randomTick(state, world, pos, random); } } |