This commit is contained in:
paulevsGitch 2020-10-09 18:59:06 +03:00
parent 7584321c47
commit 819de9ae0a
22 changed files with 419 additions and 3 deletions

View file

@ -77,7 +77,8 @@ public class BlockUnderwaterPlant extends BlockBaseNotFull implements IRenderTyp
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockState down = world.getBlockState(pos.down());
return isTerrain(down);
state = world.getBlockState(pos);
return isTerrain(down) && state.getFluidState().getFluid().equals(Fluids.WATER.getStill());
}
protected boolean isTerrain(BlockState state) {
@ -87,7 +88,7 @@ public class BlockUnderwaterPlant extends BlockBaseNotFull implements IRenderTyp
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.getDefaultState();
return Blocks.WATER.getDefaultState();
}
else {
return state;

View file

@ -0,0 +1,33 @@
package ru.betterend.blocks.basis;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.IntProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.StructureWorldAccess;
public abstract class BlockUnderwaterPlantWithAge extends BlockUnderwaterPlant {
public static final IntProperty AGE = IntProperty.of("age", 0, 3);
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
stateManager.add(AGE);
}
public abstract void grow(StructureWorldAccess world, Random random, BlockPos pos);
@Override
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
int age = state.get(AGE);
if (age < 3) {
world.setBlockState(pos, state.with(AGE, age + 1));
}
else {
grow(world, random, pos);
}
}
}