From 4a0e006c6e3dc63567d84e6bdb28839ea3380941 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Jan 2021 15:33:52 +0800 Subject: Implement MC-113809 (zero-tick plants farm) reintroduction (only cactus is implemented). --- .../java/com/keuin/ohmyvanillamc/DebugUtil.java | 7 ++ .../com/keuin/ohmyvanillamc/OmvmConfiguration.java | 18 +++-- .../mixin/Mc113809SugarCaneBlockMixin.java | 83 ++++++++++++++++++++++ .../mixin/ReintroduceLlamaItemDuping.java | 3 + src/main/resources/ohmyvanillamc.mixins.json | 3 +- 5 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/keuin/ohmyvanillamc/DebugUtil.java create mode 100644 src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java (limited to 'src') diff --git a/src/main/java/com/keuin/ohmyvanillamc/DebugUtil.java b/src/main/java/com/keuin/ohmyvanillamc/DebugUtil.java new file mode 100644 index 0000000..2be644d --- /dev/null +++ b/src/main/java/com/keuin/ohmyvanillamc/DebugUtil.java @@ -0,0 +1,7 @@ +package com.keuin.ohmyvanillamc; + +public class DebugUtil { + public static void printThreadInfo(String mark) { + System.out.printf("[%s] Thread %s : id=%d%n", mark, Thread.currentThread().getName(), Thread.currentThread().getId()); + } +} diff --git a/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java b/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java index b9e42f4..b3d7b83 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java +++ b/src/main/java/com/keuin/ohmyvanillamc/OmvmConfiguration.java @@ -9,17 +9,19 @@ public class OmvmConfiguration { private final boolean disablePhantomSpawning; private final boolean disableWanderingTraderSpawning; private final boolean reintroduceLlamaItemDuplicating; + private final boolean reintroduceZeroTickFarm; public OmvmConfiguration() { - this(true, false, false, false, false); + this(true, false, false, false, false, false); } - public OmvmConfiguration(boolean fixEntityTrackerEntrySpamming, boolean disableFishSchooling, boolean disablePhantomSpawning, boolean disableWanderingTraderSpawning, boolean reintroduceLlamaItemDuplicating) { + public OmvmConfiguration(boolean fixEntityTrackerEntrySpamming, boolean disableFishSchooling, boolean disablePhantomSpawning, boolean disableWanderingTraderSpawning, boolean reintroduceLlamaItemDuplicating, boolean reintroduceZeroTickFarm) { this.fixEntityTrackerEntrySpamming = fixEntityTrackerEntrySpamming; this.disableFishSchooling = disableFishSchooling; this.disablePhantomSpawning = disablePhantomSpawning; this.disableWanderingTraderSpawning = disableWanderingTraderSpawning; this.reintroduceLlamaItemDuplicating = reintroduceLlamaItemDuplicating; + this.reintroduceZeroTickFarm = reintroduceZeroTickFarm; } public boolean isFixEntityTrackerEntrySpamming() { @@ -42,6 +44,10 @@ public class OmvmConfiguration { return reintroduceLlamaItemDuplicating; } + public boolean isReintroduceZeroTickFarm() { + return reintroduceZeroTickFarm; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -51,12 +57,13 @@ public class OmvmConfiguration { disableFishSchooling == that.disableFishSchooling && disablePhantomSpawning == that.disablePhantomSpawning && disableWanderingTraderSpawning == that.disableWanderingTraderSpawning && - reintroduceLlamaItemDuplicating == that.reintroduceLlamaItemDuplicating; + reintroduceLlamaItemDuplicating == that.reintroduceLlamaItemDuplicating && + reintroduceZeroTickFarm == that.reintroduceZeroTickFarm; } @Override public int hashCode() { - return Objects.hash(fixEntityTrackerEntrySpamming, disableFishSchooling, disablePhantomSpawning, disableWanderingTraderSpawning, reintroduceLlamaItemDuplicating); + return Objects.hash(fixEntityTrackerEntrySpamming, disableFishSchooling, disablePhantomSpawning, disableWanderingTraderSpawning, reintroduceLlamaItemDuplicating, reintroduceZeroTickFarm); } @Override @@ -66,7 +73,8 @@ public class OmvmConfiguration { s += "(Optimization) Disable Fish Schooling: " + disableFishSchooling + "\n"; s += "(Exotic Feature) Disable Phantom Spawning: " + disablePhantomSpawning + "\n"; s += "(Exotic Feature) Disable Wandering Trader Spawning: " + disableWanderingTraderSpawning + "\n"; - s += "(Obsolete Vanilla Feature) Reintroduce Llama Item Duplicating: " + reintroduceLlamaItemDuplicating; + s += "(Obsolete Vanilla Feature) Reintroduce Llama Item Duplicating: " + reintroduceLlamaItemDuplicating + "\n"; + s += "(Obsolete Vanilla Feature) Reintroduce 0-tick Plants Farm: " + reintroduceZeroTickFarm; return s; } } 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 { diff --git a/src/main/resources/ohmyvanillamc.mixins.json b/src/main/resources/ohmyvanillamc.mixins.json index 70db4c5..86a0242 100644 --- a/src/main/resources/ohmyvanillamc.mixins.json +++ b/src/main/resources/ohmyvanillamc.mixins.json @@ -8,7 +8,8 @@ "DisableFishSchooling", "DisablePhantomSpawning", "DisableWanderingTraderSpawning", - "ReintroduceLlamaItemDuping" + "ReintroduceLlamaItemDuping", + "Mc113809SugarCaneBlockMixin" ], "injectors": { "defaultRequire": 1 -- cgit v1.2.3