summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-15 16:20:19 +0800
committerkeuin <[email protected]>2021-01-15 16:20:19 +0800
commitec83595f2e6b722911a2bd97970728bf0d0c3132 (patch)
tree7845721c83eaa4bda931ddfc3b641b65f543c66d /src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java
parent05c4dbb3fdcc8e7af6a2dcb0a2edc5b2dd1fc337 (diff)
Small refactor to make the code looks better.
Diffstat (limited to 'src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java')
-rw-r--r--src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java54
1 files changed, 20 insertions, 34 deletions
diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java
index ea3ddf8..ba872fb 100644
--- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java
+++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809CactusBlockMixin.java
@@ -38,25 +38,7 @@ public abstract class Mc113809CactusBlockMixin extends Block {
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);
- }
-
- }
- }
+ realGrow(state, world, pos);
}
}
@@ -71,24 +53,28 @@ public abstract class Mc113809CactusBlockMixin extends Block {
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) {
- }
+ realGrow(state, world, pos);
+ }
+ }
- 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);
- }
+ 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);
}
+
}
}
}