End lily
This commit is contained in:
parent
7584321c47
commit
819de9ae0a
22 changed files with 419 additions and 3 deletions
56
src/main/java/ru/betterend/blocks/BlockEndLily.java
Normal file
56
src/main/java/ru/betterend/blocks/BlockEndLily.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.BlockUnderwaterPlant;
|
||||
|
||||
public class BlockEndLily extends BlockUnderwaterPlant {
|
||||
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
|
||||
private static final VoxelShape SHAPE_BOTTOM = Block.createCuboidShape(4, 0, 4, 12, 16, 12);
|
||||
private static final VoxelShape SHAPE_TOP = Block.createCuboidShape(2, 0, 2, 14, 6, 14);
|
||||
|
||||
public BlockEndLily() {
|
||||
super(FabricBlockSettings.of(Material.UNDERWATER_PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.WET_GRASS)
|
||||
.breakByHand(true)
|
||||
.lightLevel((state) -> { return state.get(SHAPE) == TripleShape.TOP ? 13 : 0; })
|
||||
.noCollision());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
Vec3d vec3d = state.getModelOffset(view, pos);
|
||||
VoxelShape shape = state.get(SHAPE) == TripleShape.TOP ? SHAPE_TOP : SHAPE_BOTTOM;
|
||||
return shape.offset(vec3d.x, vec3d.y, vec3d.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(SHAPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidState getFluidState(BlockState state) {
|
||||
return state.get(SHAPE) == TripleShape.TOP ? Fluids.EMPTY.getDefaultState() : Fluids.WATER.getStill(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isTerrain(BlockState state) {
|
||||
return super.isTerrain(state) || state.getBlock() == this;
|
||||
}
|
||||
}
|
34
src/main/java/ru/betterend/blocks/BlockEndLilySeed.java
Normal file
34
src/main/java/ru/betterend/blocks/BlockEndLilySeed.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import ru.betterend.blocks.BlockProperties.TripleShape;
|
||||
import ru.betterend.blocks.basis.BlockUnderwaterPlantWithAge;
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public class BlockEndLilySeed extends BlockUnderwaterPlantWithAge {
|
||||
@Override
|
||||
public void grow(StructureWorldAccess world, Random random, BlockPos pos) {
|
||||
if (canGrow(world, pos)) {
|
||||
world.setBlockState(pos, BlockRegistry.END_LILY.getDefaultState().with(BlockEndLily.SHAPE, TripleShape.BOTTOM), 0);
|
||||
BlockPos up = pos.up();
|
||||
while (world.getFluidState(up).isStill()) {
|
||||
BlocksHelper.setWithoutUpdate(world, up, BlockRegistry.END_LILY.getDefaultState().with(BlockEndLily.SHAPE, TripleShape.MIDDLE));
|
||||
up = up.up();
|
||||
}
|
||||
BlocksHelper.setWithoutUpdate(world, up, BlockRegistry.END_LILY.getDefaultState().with(BlockEndLily.SHAPE, TripleShape.TOP));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canGrow(StructureWorldAccess world, BlockPos pos) {
|
||||
BlockPos up = pos.up();
|
||||
while (world.getBlockState(up).getFluidState().getFluid().equals(Fluids.WATER.getStill())) {
|
||||
up = up.up();
|
||||
}
|
||||
return world.isAir(up);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,8 @@ import ru.betterend.blocks.BlockBlueVine;
|
|||
import ru.betterend.blocks.BlockBlueVineLantern;
|
||||
import ru.betterend.blocks.BlockBlueVineSeed;
|
||||
import ru.betterend.blocks.BlockBubbleCoral;
|
||||
import ru.betterend.blocks.BlockEndLily;
|
||||
import ru.betterend.blocks.BlockEndLilySeed;
|
||||
import ru.betterend.blocks.BlockEndstoneDust;
|
||||
import ru.betterend.blocks.BlockGlowingMoss;
|
||||
import ru.betterend.blocks.BlockMossyGlowshroomCap;
|
||||
|
@ -62,6 +64,8 @@ public class BlockRegistry {
|
|||
public static final Block BLUE_VINE_FUR = registerBlock("blue_vine_fur", new BlockGlowingFur(BLUE_VINE_SEED, 3));
|
||||
|
||||
public static final Block BUBBLE_CORAL = registerBlock("bubble_coral", new BlockBubbleCoral());
|
||||
public static final Block END_LILY = registerBlockNI("end_lily", new BlockEndLily());
|
||||
public static final Block END_LILY_SEED = registerBlock("end_lily_seed", new BlockEndLilySeed());
|
||||
|
||||
// Vines //
|
||||
public static final Block DENSE_VINE = registerBlock("dense_vine", new BlockVine(15, true));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue