From ec83595f2e6b722911a2bd97970728bf0d0c3132 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Jan 2021 16:20:19 +0800 Subject: Small refactor to make the code looks better. --- .../mixin/Mc113809SugarCaneBlockMixin.java | 40 +++++++++------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java') diff --git a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java index 63874cc..88f45fc 100644 --- a/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java +++ b/src/main/java/com/keuin/ohmyvanillamc/mixin/Mc113809SugarCaneBlockMixin.java @@ -37,19 +37,7 @@ public abstract class Mc113809SugarCaneBlockMixin extends Block { if (OhMyVanillaMinecraft.getConfiguration().isReintroduceZeroTickFarm()) { scheduledTick(state, world, pos, random); } 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) { - } - - 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); - } - } + realGrow(state, world, pos); } } @@ -65,18 +53,22 @@ public abstract class Mc113809SugarCaneBlockMixin extends Block { 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) { - } + 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); - } + 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); } } } -- cgit v1.2.3