Block constructors refactoring and fixes

This commit is contained in:
paulevsGitch 2021-12-04 10:32:48 +03:00
parent 3dacd0727f
commit f8eb65d600
18 changed files with 161 additions and 113 deletions

View file

@ -30,7 +30,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@SuppressWarnings("deprecation")
public class BasePathBlock extends BaseBlockNotFull { public class BasePathBlock extends BaseBlockNotFull {
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16); private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16);
@ -56,11 +55,13 @@ public class BasePathBlock extends BaseBlockNotFull {
} }
@Override @Override
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE; return SHAPE;
} }
@Override @Override
@SuppressWarnings("deprecation")
public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE; return SHAPE;
} }

View file

@ -27,7 +27,7 @@ public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockM
} }
public BaseRotatedPillarBlock(Block block) { public BaseRotatedPillarBlock(Block block) {
super(FabricBlockSettings.copyOf(block)); this(FabricBlockSettings.copyOf(block));
} }
@Override @Override

View file

@ -64,10 +64,7 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, Cust
public BaseSignBlock(Block source) { public BaseSignBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK); super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK);
this.registerDefaultState(this.stateDefinition.any() this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false));
.setValue(ROTATION, 0)
.setValue(FLOOR, false)
.setValue(WATERLOGGED, false));
this.parent = source; this.parent = source;
} }

View file

@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class BaseStairsBlock extends StairBlock implements BlockModelProvider { public class BaseStairsBlock extends StairBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
public BaseStairsBlock(Block source) { public BaseStairsBlock(Block source) {

View file

@ -6,7 +6,6 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
public class BaseStoneButtonBlock extends BaseButtonBlock { public class BaseStoneButtonBlock extends BaseButtonBlock {
public BaseStoneButtonBlock(Block source) { public BaseStoneButtonBlock(Block source) {
super(source, FabricBlockSettings.copyOf(source).noOcclusion(), false); super(source, FabricBlockSettings.copyOf(source).noOcclusion(), false);
} }

View file

@ -10,6 +10,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.TrapDoorBlock; import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Half; import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
@ -29,7 +30,11 @@ import java.util.Optional;
public class BaseTrapdoorBlock extends TrapDoorBlock implements RenderLayerProvider, BlockModelProvider { public class BaseTrapdoorBlock extends TrapDoorBlock implements RenderLayerProvider, BlockModelProvider {
public BaseTrapdoorBlock(Block source) { public BaseTrapdoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); this(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion());
}
public BaseTrapdoorBlock(BlockBehaviour.Properties properties) {
super(properties);
} }
@Override @Override

View file

@ -1,7 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
@ -15,22 +14,25 @@ import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer { public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer {
public BaseUnderwaterWallPlantBlock() { public BaseUnderwaterWallPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT) this(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.WATER_PLANT)
.sound(SoundType.WET_GRASS) .breakByHand(true)
.noCollission()); .sound(SoundType.WET_GRASS)
.noCollission()
);
} }
public BaseUnderwaterWallPlantBlock(int light) { public BaseUnderwaterWallPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT) this(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.WATER_PLANT)
.luminance(light) .breakByHand(true)
.sound(SoundType.WET_GRASS) .luminance(light)
.noCollission()); .sound(SoundType.WET_GRASS)
.noCollission()
);
} }
public BaseUnderwaterWallPlantBlock(Properties settings) { public BaseUnderwaterWallPlantBlock(Properties settings) {

View file

@ -50,12 +50,18 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid
} }
public BaseVineBlock(int light, boolean bottomOnly) { public BaseVineBlock(int light, boolean bottomOnly) {
super(FabricBlockSettings.of(Material.PLANT) this(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.PLANT)
.sound(SoundType.GRASS) .breakByHand(true)
.lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) .sound(SoundType.GRASS)
.noCollission()); .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light)
.noCollission()
);
}
public BaseVineBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM)); this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM));
} }

View file

@ -26,7 +26,6 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class BaseWallBlock extends WallBlock implements BlockModelProvider { public class BaseWallBlock extends WallBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
public BaseWallBlock(Block source) { public BaseWallBlock(Block source) {

View file

@ -3,7 +3,6 @@ package ru.bclib.blocks;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.context.BlockPlaceContext;
@ -29,32 +28,32 @@ import java.util.EnumMap;
public abstract class BaseWallPlantBlock extends BasePlantBlock { public abstract class BaseWallPlantBlock extends BasePlantBlock {
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of( private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(
Direction.NORTH, Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16),
Block.box(1, 1, 8, 15, 15, 16), Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8),
Direction.SOUTH, Direction.WEST, Block.box(8, 1, 1, 16, 15, 15),
Block.box(1, 1, 0, 15, 15, 8), Direction.EAST, Block.box(0, 1, 1, 8, 15, 15)
Direction.WEST,
Block.box(8, 1, 1, 16, 15, 15),
Direction.EAST,
Block.box(0, 1, 1, 8, 15, 15)
)); ));
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public BaseWallPlantBlock() { public BaseWallPlantBlock() {
this(FabricBlockSettings.of(Material.PLANT) this(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.PLANT)
.sound(SoundType.GRASS) .breakByHand(true)
.noCollission()); .sound(SoundType.GRASS)
.noCollission()
);
} }
public BaseWallPlantBlock(int light) { public BaseWallPlantBlock(int light) {
this(FabricBlockSettings.of(Material.PLANT) this(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.PLANT)
.luminance(light) .breakByHand(true)
.sound(SoundType.GRASS) .luminance(light)
.noCollission()); .sound(SoundType.GRASS)
.noCollission()
);
} }
public BaseWallPlantBlock(Properties settings) { public BaseWallPlantBlock(Properties settings) {

View file

@ -6,7 +6,6 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
public class BaseWoodenButtonBlock extends BaseButtonBlock { public class BaseWoodenButtonBlock extends BaseButtonBlock {
public BaseWoodenButtonBlock(Block source) { public BaseWoodenButtonBlock(Block source) {
super(source, FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion(), true); super(source, FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion(), true);
} }

View file

@ -4,18 +4,27 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import java.util.function.Function;
public abstract class FeatureHangingSaplingBlock extends FeatureSaplingBlock { public abstract class FeatureHangingSaplingBlock extends FeatureSaplingBlock {
private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12); private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12);
public FeatureHangingSaplingBlock() {
super(); public FeatureHangingSaplingBlock(Function<BlockState, Feature<?>> featureSupplier) {
super(featureSupplier);
} }
public FeatureHangingSaplingBlock(int light) { public FeatureHangingSaplingBlock(Function<BlockState, Feature<?>> featureSupplier, int light) {
super(light); super(light, featureSupplier);
}
public FeatureHangingSaplingBlock(BlockBehaviour.Properties properties, Function<BlockState, Feature<?>> featureSupplier) {
super(properties, featureSupplier);
} }
@Override @Override

View file

@ -2,6 +2,7 @@ package ru.bclib.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import ru.bclib.api.TagAPI; import ru.bclib.api.TagAPI;
@ -10,29 +11,37 @@ import ru.bclib.interfaces.RenderLayerProvider;
public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider { public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider {
public SimpleLeavesBlock(MaterialColor color) { public SimpleLeavesBlock(MaterialColor color) {
super(FabricBlockSettings.of(Material.LEAVES) this(
.strength(0.2F) FabricBlockSettings
.color(color) .of(Material.LEAVES)
.sound(SoundType.GRASS) .strength(0.2F)
.noOcclusion() .color(color)
.isValidSpawn((state, world, pos, type) -> false) .sound(SoundType.GRASS)
.isSuffocating((state, world, pos) -> false) .noOcclusion()
.isViewBlocking((state, world, pos) -> false)); .isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
TagAPI.addTags(this, TagAPI.BLOCK_LEAVES); .isViewBlocking((state, world, pos) -> false)
);
} }
public SimpleLeavesBlock(MaterialColor color, int light) { public SimpleLeavesBlock(MaterialColor color, int light) {
super(FabricBlockSettings.of(Material.LEAVES) this(
.luminance(light) FabricBlockSettings
.color(color) .of(Material.LEAVES)
.strength(0.2F) .luminance(light)
.sound(SoundType.GRASS) .color(color)
.noOcclusion() .strength(0.2F)
.isValidSpawn((state, world, pos, type) -> false) .sound(SoundType.GRASS)
.isSuffocating((state, world, pos) -> false) .noOcclusion()
.isViewBlocking((state, world, pos) -> false)); .isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false)
);
}
public SimpleLeavesBlock(BlockBehaviour.Properties properties) {
super(properties);
// TODO handle all tags instead of adding them like this
TagAPI.addTags(this, TagAPI.BLOCK_LEAVES); TagAPI.addTags(this, TagAPI.BLOCK_LEAVES);
} }

View file

@ -22,6 +22,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlockContainer; import net.minecraft.world.level.block.LiquidBlockContainer;
import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
@ -50,11 +51,12 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg
private static final VoxelShape[] SHAPES; private static final VoxelShape[] SHAPES;
public StalactiteBlock(Block source) { public StalactiteBlock(Block source) {
super(FabricBlockSettings.copy(source).noOcclusion()); this(FabricBlockSettings.copy(source).noOcclusion());
this.registerDefaultState(getStateDefinition().any() }
.setValue(SIZE, 0)
.setValue(IS_FLOOR, true) public StalactiteBlock(BlockBehaviour.Properties properties) {
.setValue(WATERLOGGED, false)); super(properties);
this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false));
} }
@Override @Override

View file

@ -36,25 +36,28 @@ import ru.bclib.interfaces.RenderLayerProvider;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer { public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public UnderwaterPlantBlock() { public UnderwaterPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT) this(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.WATER_PLANT)
.sound(SoundType.WET_GRASS) .breakByHand(true)
.noCollission()); .sound(SoundType.WET_GRASS)
.noCollission()
);
} }
public UnderwaterPlantBlock(int light) { public UnderwaterPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT) this(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.WATER_PLANT)
.luminance(light) .breakByHand(true)
.sound(SoundType.WET_GRASS) .luminance(light)
.noCollission()); .sound(SoundType.WET_GRASS)
.noCollission()
);
} }
public UnderwaterPlantBlock(Properties settings) { public UnderwaterPlantBlock(Properties settings) {
@ -62,6 +65,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
} }
@Override @Override
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
Vec3 vec3d = state.getOffset(view, pos); Vec3 vec3d = state.getOffset(view, pos);
return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z);
@ -73,6 +77,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
} }
@Override @Override
@SuppressWarnings("deprecation")
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below()); BlockState down = world.getBlockState(pos.below());
state = world.getBlockState(pos); state = world.getBlockState(pos);
@ -82,6 +87,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
protected abstract boolean isTerrain(BlockState state); protected abstract boolean isTerrain(BlockState state);
@Override @Override
@SuppressWarnings("deprecation")
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) { if (!canSurvive(state, world, pos)) {
world.destroyBlock(pos, true); world.destroyBlock(pos, true);
@ -144,6 +150,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R
} }
@Override @Override
@SuppressWarnings("deprecation")
public FluidState getFluidState(BlockState state) { public FluidState getFluidState(BlockState state) {
return Fluids.WATER.getSource(false); return Fluids.WATER.getSource(false);
} }

View file

@ -1,7 +1,6 @@
package ru.bclib.blocks; package ru.bclib.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.WorldGenLevel;
@ -18,12 +17,14 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE; public static final IntegerProperty AGE = BlockProperties.AGE;
public UnderwaterPlantWithAgeBlock() { public UnderwaterPlantWithAgeBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT) super(
.breakByTool(FabricToolTags.SHEARS) FabricBlockSettings
.breakByHand(true) .of(Material.WATER_PLANT)
.sound(SoundType.WET_GRASS) .breakByHand(true)
.randomTicks() .sound(SoundType.WET_GRASS)
.noCollission()); .randomTicks()
.noCollission()
);
} }
@Override @Override

View file

@ -17,6 +17,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
@ -28,26 +29,32 @@ import ru.bclib.interfaces.RenderLayerProvider;
import java.util.List; import java.util.List;
@SuppressWarnings("deprecation")
public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider { public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12);
public UpDownPlantBlock() { public UpDownPlantBlock() {
super(FabricBlockSettings.of(Material.PLANT) this(FabricBlockSettings
.breakByTool(FabricToolTags.SHEARS) .of(Material.PLANT)
.breakByHand(true) .breakByHand(true)
.sound(SoundType.GRASS) .sound(SoundType.GRASS)
.noCollission()); .noCollission()
);
}
public UpDownPlantBlock(BlockBehaviour.Properties properties) {
super(properties);
} }
protected abstract boolean isTerrain(BlockState state); protected abstract boolean isTerrain(BlockState state);
@Override @Override
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE; return SHAPE;
} }
@Override @Override
@SuppressWarnings("deprecation")
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
BlockState down = world.getBlockState(pos.below()); BlockState down = world.getBlockState(pos.below());
BlockState up = world.getBlockState(pos.above()); BlockState up = world.getBlockState(pos.above());
@ -59,6 +66,7 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende
} }
@Override @Override
@SuppressWarnings("deprecation")
public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
if (!canSurvive(state, world, pos)) { if (!canSurvive(state, world, pos)) {
return Blocks.AIR.defaultBlockState(); return Blocks.AIR.defaultBlockState();

View file

@ -2,12 +2,12 @@ package ru.bclib.blocks;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
@ -16,14 +16,20 @@ import java.util.List;
public abstract class WallMushroomBlock extends BaseWallPlantBlock { public abstract class WallMushroomBlock extends BaseWallPlantBlock {
public WallMushroomBlock(int light) { public WallMushroomBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT) this(
.breakByTool(FabricToolTags.AXES) FabricBlockSettings
.breakByHand(true) .of(Material.PLANT)
.luminance(light) .breakByHand(true)
.destroyTime(0.2F) .luminance(light)
.sound(SoundType.GRASS) .destroyTime(0.2F)
.sound(SoundType.WOOD) .sound(SoundType.GRASS)
.noCollission()); .sound(SoundType.WOOD)
.noCollission()
);
}
public WallMushroomBlock(BlockBehaviour.Properties properties) {
super(properties);
} }
@Override @Override