mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed oats not growing after being collected
This commit is contained in:
parent
c6d5b75896
commit
6f0a11297a
2 changed files with 30 additions and 15 deletions
|
@ -4,12 +4,15 @@ import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.seasons.FertilizableUtil;
|
||||||
|
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.item.ItemConvertible;
|
import net.minecraft.item.ItemConvertible;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.IntProperty;
|
import net.minecraft.state.property.IntProperty;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.random.Random;
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.world.*;
|
import net.minecraft.world.*;
|
||||||
|
@ -103,6 +106,14 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
|
||||||
propagateGrowth(world, pos, state);
|
propagateGrowth(world, pos, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||||
|
if (direction == Direction.UP && !isNext(neighborState)) {
|
||||||
|
return state.with(getAgeProperty(), Math.min(state.get(getAgeProperty()), getMaxAge() - 1));
|
||||||
|
}
|
||||||
|
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||||
BlockPos tip = getTip(world, pos);
|
BlockPos tip = getTip(world, pos);
|
||||||
|
@ -116,9 +127,12 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
|
||||||
int age = getAge(state);
|
int age = getAge(state);
|
||||||
if (age < getMaxAge()) {
|
if (age < getMaxAge()) {
|
||||||
float moisture = CropBlock.getAvailableMoisture(world.getBlockState(root).getBlock(), world, root);
|
float moisture = CropBlock.getAvailableMoisture(world.getBlockState(root).getBlock(), world, root);
|
||||||
if (random.nextInt((int)(BASE_GROWTH_CHANCE / moisture) + 1) == 0) {
|
int steps = FertilizableUtil.getGrowthSteps(world, pos, state, random);
|
||||||
world.setBlockState(pos, withAge(age + 1), Block.NOTIFY_LISTENERS);
|
while (steps-- > 0) {
|
||||||
propagateGrowth(world, pos, state);
|
if (random.nextInt((int)(BASE_GROWTH_CHANCE / moisture) + 1) == 0) {
|
||||||
|
world.setBlockState(pos, withAge(age + 1), Block.NOTIFY_LISTENERS);
|
||||||
|
propagateGrowth(world, pos, state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,11 +141,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
|
||||||
private void propagateGrowth(World world, BlockPos pos, BlockState state) {
|
private void propagateGrowth(World world, BlockPos pos, BlockState state) {
|
||||||
int oldAge = getAge(state);
|
int oldAge = getAge(state);
|
||||||
state = world.getBlockState(pos);
|
state = world.getBlockState(pos);
|
||||||
int ageChange = getAge(state) - oldAge;
|
int ageChange = Math.max(1, getAge(state) - oldAge);
|
||||||
|
|
||||||
if (ageChange <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
onGrown(world, pos, state, ageChange);
|
onGrown(world, pos, state, ageChange);
|
||||||
|
|
||||||
|
@ -159,14 +169,19 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasRandomTicks(BlockState state) {
|
|
||||||
return super.hasRandomTicks(state) || nextSegmentSupplier != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) {
|
public boolean isFertilizable(WorldView world, BlockPos pos, BlockState state, boolean isClient) {
|
||||||
return super.isFertilizable(world, pos, state, isClient) || (nextSegmentSupplier != null && isNext(world.getBlockState(pos.up())));
|
if (super.isFertilizable(world, pos, state, isClient)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextSegmentSupplier == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = pos.up();
|
||||||
|
state = world.getBlockState(pos);
|
||||||
|
return state.isAir() || (isNext(state) && state.getBlock() instanceof Fertilizable f && f.isFertilizable(world, pos, state, isClient));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -113,7 +113,7 @@ public interface UBlocks {
|
||||||
() -> UItems.APPLE_PIE_HOOF
|
() -> UItems.APPLE_PIE_HOOF
|
||||||
));
|
));
|
||||||
|
|
||||||
SegmentedCropBlock OATS = register("oats", SegmentedCropBlock.create(11, 5, AbstractBlock.Settings.copy(Blocks.WHEAT), () -> UItems.OAT_SEEDS, null, () -> UBlocks.OATS_STEM));
|
SegmentedCropBlock OATS = register("oats", SegmentedCropBlock.create(11, 5, AbstractBlock.Settings.copy(Blocks.WHEAT), () -> UItems.OAT_SEEDS, null, null));
|
||||||
SegmentedCropBlock OATS_STEM = register("oats_stem", OATS.createNext(5));
|
SegmentedCropBlock OATS_STEM = register("oats_stem", OATS.createNext(5));
|
||||||
SegmentedCropBlock OATS_CROWN = register("oats_crown", OATS_STEM.createNext(5));
|
SegmentedCropBlock OATS_CROWN = register("oats_crown", OATS_STEM.createNext(5));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue