From 982f0bbbd7564b6f292a0890dd862149d9f710a9 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Wed, 10 Jan 2024 00:26:04 +0100 Subject: Some refactoring --- .../eris_alchemy/block/AlchemicalChestBlock.java | 53 ++++++++++++++++++---- .../mc/eris_alchemy/block/ErisAlchemyBlocks.java | 29 ------------ .../block/entity/AlchemicalChestBlockEntity.java | 14 ++++-- .../block/entity/ErisAlchemyBlockEntities.java | 33 -------------- 4 files changed, 53 insertions(+), 76 deletions(-) delete mode 100644 src/main/java/lv/enes/mc/eris_alchemy/block/ErisAlchemyBlocks.java delete mode 100644 src/main/java/lv/enes/mc/eris_alchemy/block/entity/ErisAlchemyBlockEntities.java (limited to 'src/main/java/lv/enes/mc/eris_alchemy/block') diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java b/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java index 9a3b413..1d8698a 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/AlchemicalChestBlock.java @@ -2,8 +2,8 @@ package lv.enes.mc.eris_alchemy.block; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; +import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; -import lv.enes.mc.eris_alchemy.block.entity.ErisAlchemyBlockEntities; import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -32,12 +32,18 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -public class AlchemicalChestBlock extends AbstractChestBlock implements SimpleWaterloggedBlock { +public class AlchemicalChestBlock + extends AbstractChestBlock + implements SimpleWaterloggedBlock +{ public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final Component CONTAINER_TITLE = Component.translatable("container.eris_alchemy.alchemical_chest"); - public static final VoxelShape SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0); + public static final VoxelShape SHAPE = Block.box( + 1.0, 0.0, 1.0, + 15.0, 14.0, 15.0 + ); public static Container getContainer(Level world, BlockPos pos) { if (world.getBlockEntity(pos) instanceof AlchemicalChestBlockEntity container) { @@ -47,7 +53,7 @@ public class AlchemicalChestBlock extends AbstractChestBlock ErisAlchemyBlockEntities.ALCHEMICAL_CHEST); + super(properties, () -> ErisAlchemyRegistry.BlockEntities.ALCHEMICAL_CHEST); registerDefaultState(getStateDefinition().any() .setValue(FACING, Direction.NORTH) .setValue(WATERLOGGED, false) @@ -56,7 +62,12 @@ public class AlchemicalChestBlock extends AbstractChestBlock combine(BlockState state, Level world, BlockPos pos, boolean ignoreBlocked) { + public DoubleBlockCombiner.NeighborCombineResult combine( + BlockState state, + Level world, + BlockPos pos, + boolean ignoreBlocked + ) { return DoubleBlockCombiner.Combiner::acceptNone; } @@ -102,8 +113,16 @@ public class AlchemicalChestBlock extends AbstractChestBlock BlockEntityTicker getTicker(Level ignoredWorld, BlockState ignoredState, BlockEntityType type) { - return createTickerHelper(type, blockEntityType.get(), (world, pos, state, entity) -> entity.tick(world, pos, state)); + public BlockEntityTicker getTicker( + Level ignoredWorld, + BlockState ignoredState, + BlockEntityType type + ) { + return createTickerHelper( + type, + blockEntityType.get(), + (world, pos, state, entity) -> entity.tick(world, pos, state) + ); } @SuppressWarnings("deprecation") @@ -155,7 +174,14 @@ public class AlchemicalChestBlock extends AbstractChestBlock blocks = new LinkedHashMap<>(); - - public static final AlchemicalChestBlock ALCHEMICAL_CHEST = register("alchemical_chest", new AlchemicalChestBlock(QuiltBlockSettings.copy(Blocks.ENDER_CHEST))); - - public static void consumeBlocks(BiConsumer consumer) { - blocks.forEach(consumer); - } - - private static T register(String id, T block) { - blocks.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), block); - return block; - } - - private ErisAlchemyBlocks() {} - -} diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java index 9c9942f..1e881f8 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/AlchemicalChestBlockEntity.java @@ -1,7 +1,7 @@ package lv.enes.mc.eris_alchemy.block.entity; import jakarta.annotation.Nonnull; -import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; +import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; @@ -62,8 +62,14 @@ public class AlchemicalChestBlockEntity extends BaseContainerBlockEntity impleme } @Override - protected void openerCountChanged(Level world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) { - world.blockEvent(worldPosition, ErisAlchemyBlocks.ALCHEMICAL_CHEST, EVENT, newViewerCount); + protected void openerCountChanged( + Level world, + BlockPos pos, + BlockState state, + int oldViewerCount, + int newViewerCount + ) { + world.blockEvent(worldPosition, ErisAlchemyRegistry.Blocks.ALCHEMICAL_CHEST, EVENT, newViewerCount); } @Override @@ -76,7 +82,7 @@ public class AlchemicalChestBlockEntity extends BaseContainerBlockEntity impleme }; public AlchemicalChestBlockEntity(BlockPos pos, BlockState state) { - super(ErisAlchemyBlockEntities.ALCHEMICAL_CHEST, pos, state); + super(ErisAlchemyRegistry.BlockEntities.ALCHEMICAL_CHEST, pos, state); } @Override diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/ErisAlchemyBlockEntities.java b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/ErisAlchemyBlockEntities.java deleted file mode 100644 index a95ac58..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/ErisAlchemyBlockEntities.java +++ /dev/null @@ -1,33 +0,0 @@ -package lv.enes.mc.eris_alchemy.block.entity; - -import lv.enes.mc.eris_alchemy.ErisAlchemy; -import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import org.quiltmc.qsl.block.entity.api.QuiltBlockEntityTypeBuilder; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.BiConsumer; - -public final class ErisAlchemyBlockEntities { - private static final Map> entities = new LinkedHashMap<>(); - - public static final BlockEntityType ALCHEMICAL_CHEST = register( - "alchemical_chest", - QuiltBlockEntityTypeBuilder.create(AlchemicalChestBlockEntity::new, ErisAlchemyBlocks.ALCHEMICAL_CHEST) - .build() - ); - - public static void consumeBlockEntities(BiConsumer> consumer) { - entities.forEach(consumer); - } - - private static BlockEntityType register(String id, BlockEntityType type) { - entities.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), type); - return type; - } - - private ErisAlchemyBlockEntities() {} -} -- cgit v1.2.3