summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMerrg1n <[email protected]>2022-08-14 15:32:05 +0800
committerMerrg1n <[email protected]>2022-08-14 15:32:05 +0800
commit7f286f8d8801cb005e436f967e56ffef5e2683ae (patch)
tree8427dc8c3a412f03aba9f50a3046b56b5f4a9b76
parent6ff7b5fed718ca32c3a952c747365bda2abc5073 (diff)
rewrite force ripening mixins, may fix #11.16.5
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java3
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java2
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantPartBlockMixin.java48
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/AbstractPlantStemBlockMixin.java86
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/BambooBlockMixin.java89
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/CactusBlockMixin.java80
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/ChorusFlowerBlockMixin.java171
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/forceRipening/SugarCaneBlockMixin.java74
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java106
-rw-r--r--src/main/resources/ohmyvanillamc.mixins.json2
10 files changed, 169 insertions, 492 deletions
diff --git a/src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java b/src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java
index e820fd6..5c7000e 100644
--- a/src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java
+++ b/src/main/java/com/keuin/ohmyvanillamc/OmvmExtension.java
@@ -2,10 +2,13 @@ package com.keuin.ohmyvanillamc;
import carpet.CarpetExtension;
import carpet.CarpetServer;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
public class OmvmExtension implements CarpetExtension {
private static final OmvmExtension INSTANCE = new OmvmExtension();
+ public static final Logger LOGGER = LogManager.getLogger("OMVM");
public static OmvmExtension getInstance() {
return INSTANCE;
}
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java
index 9e82f09..0be9728 100644
--- a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java
+++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/disableFishSchooling/SchoolingFishEntityMixin.java
@@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(SchoolingFishEntity.class)
public abstract class SchoolingFishEntityMixin extends FishEntity {
-
+ // TODO: need profile
public SchoolingFishEntityMixin(EntityType<? extends FishEntity> type, World world) {
super(type, world);
}
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);
}
}
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java
index f4f8bec..d3c87d8 100644
--- a/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java
+++ b/src/main/java/com/keuin/ohmyvanillamc/mixins/rule/reintroduceLlamaItemDuping/PlayerManagerMixin.java
@@ -1,105 +1,29 @@
package com.keuin.ohmyvanillamc.mixins.rule.reintroduceLlamaItemDuping;
import com.keuin.ohmyvanillamc.OmvmSettings;
-import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.entity.Entity;
-import net.minecraft.network.Packet;
-import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
-import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
-import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.server.world.ServerWorld;
-import net.minecraft.stat.ServerStatHandler;
-import net.minecraft.stat.Stats;
-import org.apache.logging.log4j.Logger;
-import org.spongepowered.asm.mixin.Final;
+import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Overwrite;
-import org.spongepowered.asm.mixin.Shadow;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Redirect;
/**
* Reintroduce MC-161754 glitch
*/
@Mixin(PlayerManager.class)
public abstract class PlayerManagerMixin {
-
- @Shadow
- protected abstract void savePlayerData(ServerPlayerEntity player);
-
- @Shadow
- @Final
- private static Logger LOGGER;
-
- @Shadow
- @Final
- private List<ServerPlayerEntity> players;
-
- @Shadow
- @Final
- private MinecraftServer server;
-
- @Shadow
- @Final
- private Map<UUID, ServerPlayerEntity> playerMap;
-
- @Shadow
- @Final
- private Map<UUID, ServerStatHandler> statisticsMap;
-
- @Shadow
- @Final
- private Map<UUID, PlayerAdvancementTracker> advancementTrackers;
-
- @Shadow
- public abstract void sendToAll(Packet<?> packet);
-
- /**
- * @reason re-introduce llama item duplicating glitch.
- * @author trueKeuin
- */
- @Overwrite
- public void remove(ServerPlayerEntity player) {
- ServerWorld serverWorld = player.getServerWorld();
- player.incrementStat(Stats.LEAVE_GAME);
- this.savePlayerData(player);
- if (player.hasVehicle()) {
- Entity entity = player.getRootVehicle();
- if (entity.hasPlayerRider()) {
- LOGGER.debug("Removing player mount");
- player.stopRiding();
- serverWorld.removeEntity(entity);
- // entity.removed = true
- entity.removed = !OmvmSettings.reintroduceLlamaItemDuplicating || entity.removed;
-
- Entity entity2;
- for (Iterator var4 = entity.getPassengersDeep().iterator(); var4.hasNext(); // entity2.removed = true
- entity2.removed = !OmvmSettings.reintroduceLlamaItemDuplicating || entity2.removed) {
- entity2 = (Entity) var4.next();
- serverWorld.removeEntity(entity2);
- }
-
- serverWorld.getChunk(player.chunkX, player.chunkZ).markDirty();
- }
- }
-
- player.detach();
- serverWorld.removePlayer(player);
- player.getAdvancementTracker().clearCriteria();
- this.players.remove(player);
- this.server.getBossBarManager().onPlayerDisconnect(player);
- UUID uUID = player.getUuid();
- ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) this.playerMap.get(uUID);
- if (serverPlayerEntity == player) {
- this.playerMap.remove(uUID);
- this.statisticsMap.remove(uUID);
- this.advancementTrackers.remove(uUID);
- }
-
- this.sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.REMOVE_PLAYER, player));
+ @Redirect(
+ method = "remove",
+ at = @At(
+ value = "FIELD",
+ opcode = Opcodes.PUTFIELD,
+ target = "Lnet/minecraft/entity/Entity;removed:Z"
+ ),
+ require = 2
+ )
+ private void Entity_setRemoved(Entity entity, boolean value) {
+// OmvmExtension.LOGGER.info("set entity remove!");
+ entity.removed = !OmvmSettings.reintroduceLlamaItemDuplicating || entity.removed;
}
}
diff --git a/src/main/resources/ohmyvanillamc.mixins.json b/src/main/resources/ohmyvanillamc.mixins.json
index 21e12d2..4236410 100644
--- a/src/main/resources/ohmyvanillamc.mixins.json
+++ b/src/main/resources/ohmyvanillamc.mixins.json
@@ -6,7 +6,7 @@
"mixins": [
"fix.disableEntityTrackerEntrySpamming.EntityTrackerEntryMixin",
"rule.disableFishSchooling.SchoolingFishEntityMixin",
- "rule.forceRipening.AbstractPlantStemBlockMixin",
+ "rule.forceRipening.AbstractPlantPartBlockMixin",
"rule.forceRipening.BambooBlockMixin",
"rule.forceRipening.CactusBlockMixin",
"rule.forceRipening.ChorusFlowerBlockMixin",