summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/ohmyvanillamc
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-15 16:03:05 +0800
committerkeuin <[email protected]>2021-01-15 16:03:05 +0800
commit1c745f43a3547241f23b4b29bfe3596889b21f3f (patch)
treea1f3e105c7763026b4c4d2d9b9968c9228b9331e /src/main/java/com/keuin/ohmyvanillamc
parent4a0e006c6e3dc63567d84e6bdb28839ea3380941 (diff)
Implement MC-113809 (zero-tick plants farm) reintroduction (for cactus).
Diffstat (limited to 'src/main/java/com/keuin/ohmyvanillamc')
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java95
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java2
2 files changed, 96 insertions, 1 deletions
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java
new file mode 100644
index 0000000..ea3ddf8
--- /dev/null
+++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java
@@ -0,0 +1,95 @@
+package com.keuin.ohmyvanillamc.mixin;
+
+import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft;
+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 java.util.Random;
+
+@Mixin(CactusBlock.class)
+public abstract class Mc113809CactusBlockMixin extends Block {
+
+ public Mc113809CactusBlockMixin(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 {
+ // here goes 1.16.4 version randomTick impl.
+ 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 = (Integer) state.get(AGE);
+ if (j == 15) {
+ world.setBlockState(blockPos, this.getDefaultState());
+ BlockState blockState = (BlockState) state.with(AGE, 0);
+ world.setBlockState(pos, blockState, 4);
+ blockState.neighborUpdate(world, blockPos, this, pos, false);
+ } else {
+ world.setBlockState(pos, (BlockState) state.with(AGE, j + 1), 4);
+ }
+
+ }
+ }
+ }
+ }
+
+ /**
+ * 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 (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm()) {
+ 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 = (Integer) state.get(AGE);
+ if (j == 15) {
+ world.setBlockState(blockPos, this.getDefaultState());
+ BlockState blockState = (BlockState) state.with(AGE, 0);
+ world.setBlockState(pos, blockState, 4);
+ blockState.neighborUpdate(world, blockPos, this, pos, false);
+ } else {
+ world.setBlockState(pos, (BlockState) state.with(AGE, j + 1), 4);
+ }
+
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java
index 23d4507..63874cc 100644
--- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java
+++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java
@@ -36,7 +36,7 @@ public abstract class Mc113809SugarCaneBlockMixin extends Block {
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())) {
+ } else if (world.isAir(pos.up())) { // here goes 1.16.4 version randomTick impl.
int i;
for (i = 1; world.getBlockState(pos.down(i)).isOf((SugarCaneBlock) (Object) this); ++i) {
}