Various fixes

This commit is contained in:
Aleksey 2021-06-22 16:05:46 +03:00
parent dccb49f51c
commit 7d79452220
52 changed files with 130 additions and 101 deletions

View file

@ -1,5 +1,6 @@
package ru.bclib.blockentities;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
@ -26,13 +27,13 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
private NonNullList<ItemStack> inventory;
private int viewerCount;
private BaseBarrelBlockEntity(BlockEntityType<?> type) {
super(type);
private BaseBarrelBlockEntity(BlockEntityType<?> type, BlockPos blockPos, BlockState blockState) {
super(type, blockPos, blockState);
this.inventory = NonNullList.withSize(27, ItemStack.EMPTY);
}
public BaseBarrelBlockEntity() {
this(BaseBlockEntities.BARREL);
public BaseBarrelBlockEntity(BlockPos blockPos, BlockState blockState) {
this(BaseBlockEntities.BARREL, blockPos, blockState);
}
public CompoundTag save(CompoundTag tag) {
@ -44,8 +45,8 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
return tag;
}
public void load(BlockState state, CompoundTag tag) {
super.load(state, tag);
public void load(CompoundTag tag) {
super.load(tag);
this.inventory = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
if (!this.tryLoadLootTable(tag)) {
ContainerHelper.loadAllItems(tag, this.inventory);
@ -97,10 +98,7 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
public void tick() {
if (level != null) {
int x = worldPosition.getX();
int y = worldPosition.getY();
int z = worldPosition.getZ();
viewerCount = ChestBlockEntity.getOpenCount(level, this, x, y, z);
viewerCount = ChestBlockEntity.getOpenCount(level, worldPosition);
if (viewerCount > 0) {
scheduleUpdate();
} else {

View file

@ -1,10 +1,12 @@
package ru.bclib.blockentities;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.registry.BaseBlockEntities;
public class BaseChestBlockEntity extends ChestBlockEntity {
public BaseChestBlockEntity() {
super(BaseBlockEntities.CHEST);
public BaseChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(BaseBlockEntities.CHEST, blockPos, blockState);
}
}

View file

@ -1,5 +1,6 @@
package ru.bclib.blockentities;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.player.Inventory;
@ -7,11 +8,12 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.FurnaceMenu;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.registry.BaseBlockEntities;
public class BaseFurnaceBlockEntity extends AbstractFurnaceBlockEntity {
public BaseFurnaceBlockEntity() {
super(BaseBlockEntities.FURNACE, RecipeType.SMELTING);
public BaseFurnaceBlockEntity(BlockPos blockPos, BlockState blockState) {
super(BaseBlockEntities.FURNACE, blockPos, blockState, RecipeType.SMELTING);
}
protected Component getDefaultName() {

View file

@ -38,6 +38,7 @@ public class DynamicBlockEntityType<T extends BlockEntity> extends BlockEntityTy
}
@FunctionalInterface
public
interface BlockEntitySupplier<T extends BlockEntity> {
T create(BlockPos blockPos, BlockState blockState);
}

View file

@ -35,7 +35,7 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro
public static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;
public BaseAnvilBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.ANVIL).materialColor(color));
super(FabricBlockSettings.copyOf(Blocks.ANVIL).mapColor(color));
}
@Override
@ -43,8 +43,9 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro
super.createBlockStateDefinition(builder);
builder.add(DESTRUCTION);
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack dropStack = new ItemStack(this);
int destruction = state.getValue(DESTRUCTION);

View file

@ -16,12 +16,13 @@ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import ru.bclib.util.BlocksHelper;
@SuppressWarnings("deprecation")
public abstract class BaseAttachedBlock extends BaseBlockNotFull {
public static final DirectionProperty FACING = BlockStateProperties.FACING;
public BaseAttachedBlock(Properties settings) {
super(settings);
this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.UP));
registerDefaultState(defaultBlockState().setValue(FACING, Direction.UP));
}
@Override
@ -31,7 +32,7 @@ public abstract class BaseAttachedBlock extends BaseBlockNotFull {
@Override
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
BlockState blockState = this.defaultBlockState();
BlockState blockState = defaultBlockState();
LevelReader worldView = ctx.getLevel();
BlockPos blockPos = ctx.getClickedPos();
Direction[] directions = ctx.getNearestLookingDirections();
@ -47,7 +48,7 @@ public abstract class BaseAttachedBlock extends BaseBlockNotFull {
@Override
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
Direction direction = (Direction) state.getValue(FACING);
Direction direction = state.getValue(FACING);
BlockPos blockPos = pos.relative(direction.getOpposite());
return canSupportCenter(world, blockPos, direction) || world.getBlockState(blockPos).is(BlockTags.LEAVES);
}

View file

@ -46,11 +46,12 @@ public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider {
}
@Override
public BlockEntity newBlockEntity(BlockGetter world) {
return BaseBlockEntities.BARREL.create();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return BaseBlockEntities.BARREL.create(blockPos, blockState);
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
List<ItemStack> drop = super.getDrops(state, builder);
drop.add(new ItemStack(this.asItem()));

View file

@ -17,6 +17,7 @@ public class BaseBlock extends Block implements BlockModelProvider {
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -3,6 +3,7 @@ package ru.bclib.blocks;
import java.util.Collections;
import java.util.List;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.BaseEntityBlock;
@ -16,11 +17,12 @@ public class BaseBlockWithEntity extends BaseEntityBlock {
}
@Override
public BlockEntity newBlockEntity(BlockGetter world) {
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return null;
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -35,6 +35,7 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -29,10 +29,11 @@ import ru.bclib.interfaces.IRenderTyped;
public class BaseChainBlock extends ChainBlock implements BlockModelProvider, IRenderTyped {
public BaseChainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.CHAIN).materialColor(color));
super(FabricBlockSettings.copyOf(Blocks.CHAIN).mapColor(color));
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -3,6 +3,7 @@ package ru.bclib.blocks;
import java.util.List;
import java.util.Optional;
import net.minecraft.core.BlockPos;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType;
@ -33,12 +34,12 @@ public class BaseChestBlock extends ChestBlock implements BlockModelProvider {
}
@Override
public BlockEntity newBlockEntity(BlockGetter world)
{
return BaseBlockEntities.CHEST.create();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return BaseBlockEntities.CHEST.create(blockPos, blockState);
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder)
{
List<ItemStack> drop = super.getDrops(state, builder);

View file

@ -28,8 +28,9 @@ public class BaseComposterBlock extends ComposterBlock implements BlockModelProv
public BaseComposterBlock(Block source) {
super(FabricBlockSettings.copyOf(source));
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this.asItem()));
}

View file

@ -28,6 +28,7 @@ public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockM
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this.asItem()));
}

View file

@ -106,8 +106,9 @@ public class BaseCropBlock extends BasePlantBlock {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return state.getValue(AGE) < 3;
}
@Override
@SuppressWarnings("deprecation")
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.tick(state, world, pos, random);
if (isBonemealSuccess(world, random, pos, state) && random.nextInt(8) == 0) {

View file

@ -36,6 +36,7 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
if (state.getValue(HALF) == DoubleBlockHalf.LOWER)
return Collections.singletonList(new ItemStack(this.asItem()));

View file

@ -38,6 +38,7 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.BlocksHelper;
@SuppressWarnings("deprecation")
public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12);
public static final IntegerProperty ROTATION = BlockProperties.ROTATION;
@ -110,7 +111,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I
}
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -35,6 +35,7 @@ public class BaseFenceBlock extends FenceBlock implements BlockModelProvider {
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -42,8 +42,8 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider
}
@Override
public BlockEntity newBlockEntity(BlockGetter world) {
return new BaseFurnaceBlockEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new BaseFurnaceBlockEntity(blockPos, blockState);
}
@Override
@ -95,8 +95,9 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider
public BCLRenderLayer getRenderLayer() {
return BCLRenderLayer.CUTOUT;
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
List<ItemStack> drop = Lists.newArrayList(new ItemStack(this));
BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);

View file

@ -33,6 +33,7 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -39,6 +39,7 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.BlocksHelper;
@SuppressWarnings("deprecation")
public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, BlockModelProvider {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
@ -57,17 +58,14 @@ public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, B
stateManager.add(WATERLOGGED);
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
switch (state.getValue(FACING)) {
case SOUTH:
return SOUTH_SHAPE;
case WEST:
return WEST_SHAPE;
case EAST:
return EAST_SHAPE;
default:
return NORTH_SHAPE;
}
return switch (state.getValue(FACING)) {
case SOUTH -> SOUTH_SHAPE;
case WEST -> WEST_SHAPE;
case EAST -> EAST_SHAPE;
default -> NORTH_SHAPE;
};
}
private boolean canPlaceOn(BlockGetter world, BlockPos pos, Direction side) {
@ -78,7 +76,7 @@ public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, B
@Override
public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
Direction direction = state.getValue(FACING);
return this.canPlaceOn(world, pos.relative(direction.getOpposite()), direction);
return canPlaceOn(world, pos.relative(direction.getOpposite()), direction);
}
@Override

View file

@ -29,7 +29,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
public BaseLeavesBlock(Block sapling, MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.materialColor(color)
.mapColor(color)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
@ -41,7 +41,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
public BaseLeavesBlock(Block sapling, MaterialColor color, int light) {
super(FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.materialColor(color)
.mapColor(color)
.luminance(light)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
@ -55,12 +55,13 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
public BCLRenderLayer getRenderLayer() {
return BCLRenderLayer.CUTOUT;
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null) {
if (tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Collections.singletonList(new ItemStack(this));
}
int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool);

View file

@ -34,6 +34,7 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@ -99,7 +100,7 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi
@Environment(EnvType.CLIENT)
public boolean skipRendering(BlockState state, BlockState stateFrom, Direction direction) {
if (direction.getAxis().isVertical() && stateFrom.getBlock().is(this) && !stateFrom.equals(state)) {
if (direction.getAxis().isVertical() && stateFrom.getBlock() == this && !stateFrom.equals(state)) {
return false;
}
return super.skipRendering(state, stateFrom, direction);

View file

@ -8,6 +8,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
@ -26,26 +27,20 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider {
private final Item dropItem;
private final int minCount;
private final int maxCount;
private final int experience;
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
.hardness(3F)
.resistance(9F)
.requiresCorrectToolForDrops()
.sound(SoundType.STONE));
.sound(SoundType.STONE), UniformInt.of(1, experience));
this.dropItem = drop;
this.minCount = minCount;
this.maxCount = maxCount;
this.experience = experience;
}
@Override
protected int xpOnDrop(Random random) {
return this.experience > 0 ? random.nextInt(experience) + 1 : 0;
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.isCorrectToolForDrops(state)) {

View file

@ -33,6 +33,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
@SuppressWarnings("deprecation")
public abstract class BasePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
@ -97,7 +98,7 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -53,8 +53,9 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) {
return true;
}
@Override
@SuppressWarnings("deprecation")
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.tick(state, world, pos, random);
if (random.nextInt(8) == 0) {

View file

@ -33,6 +33,7 @@ public class BasePressurePlateBlock extends PressurePlateBlock implements BlockM
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -30,8 +30,9 @@ public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockM
public BaseRotatedPillarBlock(Block block) {
super(FabricBlockSettings.copyOf(block));
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -48,6 +48,7 @@ import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ISpetialItem;
import ru.bclib.util.BlocksHelper;
@SuppressWarnings("deprecation")
public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem {
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public static final BooleanProperty FLOOR = BooleanProperty.create("floor");

View file

@ -35,6 +35,7 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider {
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -37,6 +37,7 @@ public class BaseStairsBlock extends StairBlock implements BlockModelProvider {
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -20,13 +20,14 @@ public class BaseStripableLogBlock extends BaseRotatedPillarBlock {
private final Block striped;
public BaseStripableLogBlock(MaterialColor color, Block striped) {
super(FabricBlockSettings.copyOf(striped).materialColor(color));
super(FabricBlockSettings.copyOf(striped).mapColor(color));
this.striped = striped;
}
@Override
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (player.getMainHandItem().getItem().is(FabricToolTags.AXES)) {
if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);

View file

@ -67,7 +67,7 @@ public class BaseTerrainBlock extends BaseBlock {
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) {
if (pathBlock != null && FabricToolTags.SHOVELS.contains(player.getMainHandItem().getItem())) {
world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlockAndUpdate(pos, pathBlock.defaultBlockState());

View file

@ -34,6 +34,7 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -48,6 +48,7 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im
}
@Override
@SuppressWarnings("deprecation")
public FluidState getFluidState(BlockState state) {
return Fluids.WATER.getSource(false);
}

View file

@ -37,6 +37,7 @@ import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.util.BlocksHelper;
@SuppressWarnings("deprecation")
public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final VoxelShape VOXEL_SHAPE = Block.box(2, 0, 2, 14, 16, 14);
@ -106,7 +107,7 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -36,6 +36,7 @@ public class BaseWallBlock extends WallBlock implements BlockModelProvider {
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -113,11 +113,13 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock {
}
@Override
@SuppressWarnings("deprecation")
public BlockState rotate(BlockState state, Rotation rotation) {
return BlocksHelper.rotateHorizontal(state, rotation, FACING);
}
@Override
@SuppressWarnings("deprecation")
public BlockState mirror(BlockState state, Mirror mirror) {
return BlocksHelper.mirrorHorizontal(state, mirror, FACING);
}

View file

@ -33,6 +33,7 @@ public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implement
}
@Override
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}

View file

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Random;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.api.EnvType;
@ -36,6 +37,7 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
@SuppressWarnings("deprecation")
public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTyped, BlockModelProvider {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);

View file

@ -11,7 +11,7 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements IRenderTyped
public SimpleLeavesBlock(MaterialColor color) {
super(FabricBlockSettings.of(Material.LEAVES)
.strength(0.2F)
.materialColor(color)
.mapColor(color)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
@ -22,7 +22,7 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements IRenderTyped
public SimpleLeavesBlock(MaterialColor color, int light) {
super(FabricBlockSettings.of(Material.LEAVES)
.luminance(light)
.materialColor(color)
.mapColor(color)
.strength(0.2F)
.sound(SoundType.GRASS)
.noOcclusion()

View file

@ -43,6 +43,7 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
@SuppressWarnings("deprecation")
public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTyped {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;

View file

@ -20,13 +20,14 @@ public class StripableBarkBlock extends BaseBarkBlock {
private final Block striped;
public StripableBarkBlock(MaterialColor color, Block striped) {
super(FabricBlockSettings.copyOf(striped).materialColor(color));
super(FabricBlockSettings.copyOf(striped).mapColor(color));
this.striped = striped;
}
@Override
@SuppressWarnings("deprecation")
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (player.getMainHandItem().getItem().is(FabricToolTags.AXES)) {
if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);

View file

@ -37,6 +37,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
@SuppressWarnings("deprecation")
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock, LiquidBlockContainer {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
@ -95,7 +96,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements I
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -47,6 +47,7 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
}
@Override
@SuppressWarnings("deprecation")
public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
super.tick(state, world, pos, random);
if (isBonemealSuccess(world, random, pos, state)) {

View file

@ -29,6 +29,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
@SuppressWarnings("deprecation")
public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRenderTyped {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12);
@ -71,7 +72,7 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRend
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && tool.getItem().is(FabricToolTags.SHEARS) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -1,12 +1,9 @@
package ru.bclib.client.render;
import java.util.HashMap;
import com.google.common.collect.Maps;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Vector3f;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import net.fabricmc.api.EnvType;
@ -21,18 +18,15 @@ import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractChestBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.DoubleBlockCombiner.NeighborCombineResult;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.ChestType;
import ru.bclib.blockentities.BaseChestBlockEntity;
import java.util.HashMap;
@Environment(EnvType.CLIENT)
public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChestBlockEntity> {
private static final HashMap<Block, RenderType[]> LAYERS = Maps.newHashMap();
@ -87,8 +81,8 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
Level world = entity.getLevel();
boolean worldExists = world != null;
BlockState blockState = worldExists ? entity.getBlockState() : (BlockState) Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? (ChestType) blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
BlockState blockState = worldExists ? entity.getBlockState() : Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
Block block = blockState.getBlock();
if (block instanceof AbstractChestBlock) {
AbstractChestBlock<?> abstractChestBlock = (AbstractChestBlock<?>) block;
@ -107,7 +101,7 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
propertySource = DoubleBlockCombiner.Combiner::acceptNone;
}
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner((LidBlockEntity) entity))).get(tickDelta);
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner(entity))).get(tickDelta);
pitch = 1.0F - pitch;
pitch = 1.0F - pitch * pitch * pitch;
@SuppressWarnings({ "unchecked", "rawtypes" })
@ -138,15 +132,11 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
}
private static RenderType getChestTexture(ChestType type, RenderType[] layers) {
switch (type) {
case LEFT:
return layers[ID_LEFT];
case RIGHT:
return layers[ID_RIGHT];
case SINGLE:
default:
return layers[ID_NORMAL];
}
return switch (type) {
case LEFT -> layers[ID_LEFT];
case RIGHT -> layers[ID_RIGHT];
default -> layers[ID_NORMAL];
};
}
public static VertexConsumer getConsumer(MultiBufferSource provider, Block block, ChestType chestType) {

View file

@ -30,7 +30,7 @@ public class BaseDrinkItem extends ModelProviderItem {
@Override
public InteractionResultHolder<ItemStack> use(Level world, Player user, InteractionHand hand) {
return ItemUtils.useDrink(world, user, hand);
return ItemUtils.startUsingInstantly(world, user, hand);
}
@Override
@ -41,13 +41,12 @@ public class BaseDrinkItem extends ModelProviderItem {
stack.setCount(count);
}
if (user instanceof ServerPlayer) {
ServerPlayer serverPlayerEntity = (ServerPlayer) user;
if (user instanceof ServerPlayer serverPlayerEntity) {
CriteriaTriggers.CONSUME_ITEM.trigger(serverPlayerEntity, stack);
serverPlayerEntity.awardStat(Stats.ITEM_USED.get(this));
}
if (user instanceof Player && !((Player) user).abilities.instabuild) {
if (user instanceof Player && !((Player) user).getAbilities().instabuild) {
stack.shrink(1);
}

View file

@ -7,6 +7,7 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.item.SpawnEggItem;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ItemModelProvider;
@ -14,7 +15,7 @@ import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
public class BaseSpawnEggItem extends SpawnEggItem implements ItemModelProvider {
public BaseSpawnEggItem(EntityType<?> type, int primaryColor, int secondaryColor, Properties settings) {
public BaseSpawnEggItem(EntityType<? extends Mob> type, int primaryColor, int secondaryColor, Properties settings) {
super(type, primaryColor, secondaryColor, settings);
}

View file

@ -13,6 +13,7 @@ import ru.bclib.blockentities.BaseChestBlockEntity;
import ru.bclib.blockentities.BaseFurnaceBlockEntity;
import ru.bclib.blockentities.BaseSignBlockEntity;
import ru.bclib.blockentities.DynamicBlockEntityType;
import ru.bclib.blockentities.DynamicBlockEntityType.BlockEntitySupplier;
import ru.bclib.blocks.BaseBarrelBlock;
import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blocks.BaseFurnaceBlock;
@ -24,7 +25,7 @@ public class BaseBlockEntities {
public static final DynamicBlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(BCLib.makeID("sign"), BaseSignBlockEntity::new);
public static final DynamicBlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID("furnace"), BaseFurnaceBlockEntity::new);
public static <T extends BlockEntity> DynamicBlockEntityType<T> registerBlockEntityType(ResourceLocation typeId, Supplier<? extends T> supplier) {
public static <T extends BlockEntity> DynamicBlockEntityType<T> registerBlockEntityType(ResourceLocation typeId, BlockEntitySupplier<? extends T> supplier) {
return Registry.register(Registry.BLOCK_ENTITY_TYPE, typeId, new DynamicBlockEntityType<>(supplier));
}

View file

@ -9,6 +9,7 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.tags.Tag;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.CreativeModeTab;
@ -67,7 +68,7 @@ public abstract class ItemsRegistry extends BaseRegistry<Item> {
return item;
}
public Item registerEgg(String name, EntityType<?> type, int background, int dots) {
public Item registerEgg(String name, EntityType<? extends Mob> type, int background, int dots) {
SpawnEggItem item = new BaseSpawnEggItem(type, background, dots, makeItemSettings());
DefaultDispenseItemBehavior behavior = new DefaultDispenseItemBehavior() {
public ItemStack execute(BlockSource pointer, ItemStack stack) {

View file

@ -100,7 +100,7 @@ public class StructureWorld {
public BoundingBox getBounds() {
if (minX == Integer.MAX_VALUE || maxX == Integer.MIN_VALUE || minZ == Integer.MAX_VALUE || maxZ == Integer.MIN_VALUE) {
return BoundingBox.getUnknownBox();
return BoundingBox.infinite();
}
return new BoundingBox(minX << 4, minY, minZ << 4, (maxX << 4) | 15, maxY, (maxZ << 4) | 15);
}