diff options
author | Keuin <[email protected]> | 2021-01-15 15:33:52 +0800 |
---|---|---|
committer | keuin <[email protected]> | 2021-01-15 15:33:52 +0800 |
commit | 4a0e006c6e3dc63567d84e6bdb28839ea3380941 (patch) | |
tree | d08778929e7ab872651844bd0047a351122cf557 /src/main/java/com/keuin/ohmyvanillamc/mixin | |
parent | d044c4ebf8c4ad577711afb1875ce5265bc669d8 (diff) |
Implement MC-113809 (zero-tick plants farm) reintroduction (only cactus is implemented).
Diffstat (limited to 'src/main/java/com/keuin/ohmyvanillamc/mixin')
-rw-r--r-- | src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java | 83 | ||||
-rw-r--r-- | src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java | 3 |
2 files changed, 86 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java new file mode 100644 index 0000000..23d4507 --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java @@ -0,0 +1,83 @@ +package com.keuin.ohmyvanillamc.mixin; + +import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft; +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 java.util.Random; + +@Mixin(SugarCaneBlock.class) +public abstract class Mc113809SugarCaneBlockMixin extends Block { + + public Mc113809SugarCaneBlockMixin(Settings settings) { + super(settings); + } + + @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 (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm()) { + scheduledTick(state, world, pos, random); + } else if (world.isAir(pos.up())) { + 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); + } + } + } + + } + + /** + * 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()) && OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm()) { + 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); + } + } + } + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java index 29ed03a..f3c0b60 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/ReintroduceLlamaItemDuping.java @@ -22,6 +22,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; +/** + * Reintroduce MC-161754 glitch + */ @Mixin(PlayerManager.class) public abstract class ReintroduceLlamaItemDuping { |