summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-16 23:36:03 +0800
committerkeuin <[email protected]>2021-01-16 23:36:03 +0800
commit81b6c329ae1c886dbed7ea3253580c985fcea92d (patch)
tree2523e4cee7d7a32ae5a9dd25978acc1ed8bb391b
parentc96ce10cdcf75cf642101b00cc9572304d276851 (diff)
MC113809: now supports all 5 plants in 20w11a for zero tick farms: cactus, sugar cane, bamboo, twisted vine and weeping vine.
Simple tests are passed. However, further tests are needed.
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java86
-rw-r--r--src/main/resources/ohmyvanillamc.mixins.json3
3 files changed, 89 insertions, 2 deletions
diff --git a/gradle.properties b/gradle.properties
index fe31ad3..e790de9 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,7 +6,7 @@ minecraft_version=1.16.4
yarn_mappings=1.16.4+build.9
loader_version=0.11.0
# Mod Properties
-mod_version=1.5.3
+mod_version=1.5.4
maven_group=com.keuin.omvm
archives_base_name=oh-my-vanilla-mc
# Dependencies
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java
new file mode 100644
index 0000000..1571981
--- /dev/null
+++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809AbstractPlantStemBlockMixin.java
@@ -0,0 +1,86 @@
+package com.keuin.ohmyvanillamc.mixin;
+
+import com.keuin.ohmyvanillamc.OhMyVanillaMinecraft;
+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 Mc113809AbstractPlantStemBlockMixin extends AbstractPlantPartBlock {
+
+ protected Mc113809AbstractPlantStemBlockMixin(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 bamboo.
+ */
+ @Override
+ 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()) {
+ 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 (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm()) {
+ 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/resources/ohmyvanillamc.mixins.json b/src/main/resources/ohmyvanillamc.mixins.json
index 1070400..ce61122 100644
--- a/src/main/resources/ohmyvanillamc.mixins.json
+++ b/src/main/resources/ohmyvanillamc.mixins.json
@@ -11,7 +11,8 @@
"ReintroduceLlamaItemDuping",
"Mc113809SugarCaneBlockMixin",
"Mc113809CactusBlockMixin",
- "Mc113809ChorusFlowerBlockMixin"
+ "Mc113809ChorusFlowerBlockMixin",
+ "Mc113809AbstractPlantStemBlockMixin"
],
"injectors": {
"defaultRequire": 1