diff options
| author | 2024-01-10 00:26:04 +0100 | |
|---|---|---|
| committer | 2024-01-10 00:26:04 +0100 | |
| commit | 982f0bbbd7564b6f292a0890dd862149d9f710a9 (patch) | |
| tree | 30875caa478390a6c30096e17b4e0c8133a3cf88 /src/main/java/lv/enes/mc/eris_alchemy/block | |
| parent | Make Alchemical Chest waterloggable. (diff) | |
| download | mc-eris-alchemy-982f0bbbd7564b6f292a0890dd862149d9f710a9.tar.gz mc-eris-alchemy-982f0bbbd7564b6f292a0890dd862149d9f710a9.tar.xz mc-eris-alchemy-982f0bbbd7564b6f292a0890dd862149d9f710a9.zip | |
Some refactoring
Diffstat (limited to 'src/main/java/lv/enes/mc/eris_alchemy/block')
4 files changed, 53 insertions, 76 deletions
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; | |||
| 2 | 2 | ||
| 3 | import jakarta.annotation.Nonnull; | 3 | import jakarta.annotation.Nonnull; |
| 4 | import jakarta.annotation.Nullable; | 4 | import jakarta.annotation.Nullable; |
| 5 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; | ||
| 5 | import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; | 6 | import lv.enes.mc.eris_alchemy.block.entity.AlchemicalChestBlockEntity; |
| 6 | import lv.enes.mc.eris_alchemy.block.entity.ErisAlchemyBlockEntities; | ||
| 7 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; | 7 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; |
| 8 | import net.minecraft.core.BlockPos; | 8 | import net.minecraft.core.BlockPos; |
| 9 | import net.minecraft.core.Direction; | 9 | import net.minecraft.core.Direction; |
| @@ -32,12 +32,18 @@ import net.minecraft.world.phys.BlockHitResult; | |||
| 32 | import net.minecraft.world.phys.shapes.CollisionContext; | 32 | import net.minecraft.world.phys.shapes.CollisionContext; |
| 33 | import net.minecraft.world.phys.shapes.VoxelShape; | 33 | import net.minecraft.world.phys.shapes.VoxelShape; |
| 34 | 34 | ||
| 35 | public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBlockEntity> implements SimpleWaterloggedBlock { | 35 | public class AlchemicalChestBlock |
| 36 | extends AbstractChestBlock<AlchemicalChestBlockEntity> | ||
| 37 | implements SimpleWaterloggedBlock | ||
| 38 | { | ||
| 36 | public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; | 39 | public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING; |
| 37 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; | 40 | public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; |
| 38 | 41 | ||
| 39 | public static final Component CONTAINER_TITLE = Component.translatable("container.eris_alchemy.alchemical_chest"); | 42 | public static final Component CONTAINER_TITLE = Component.translatable("container.eris_alchemy.alchemical_chest"); |
| 40 | public static final VoxelShape SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 14.0, 15.0); | 43 | public static final VoxelShape SHAPE = Block.box( |
| 44 | 1.0, 0.0, 1.0, | ||
| 45 | 15.0, 14.0, 15.0 | ||
| 46 | ); | ||
| 41 | 47 | ||
| 42 | public static Container getContainer(Level world, BlockPos pos) { | 48 | public static Container getContainer(Level world, BlockPos pos) { |
| 43 | if (world.getBlockEntity(pos) instanceof AlchemicalChestBlockEntity container) { | 49 | if (world.getBlockEntity(pos) instanceof AlchemicalChestBlockEntity container) { |
| @@ -47,7 +53,7 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 47 | } | 53 | } |
| 48 | 54 | ||
| 49 | public AlchemicalChestBlock(Properties properties) { | 55 | public AlchemicalChestBlock(Properties properties) { |
| 50 | super(properties, () -> ErisAlchemyBlockEntities.ALCHEMICAL_CHEST); | 56 | super(properties, () -> ErisAlchemyRegistry.BlockEntities.ALCHEMICAL_CHEST); |
| 51 | registerDefaultState(getStateDefinition().any() | 57 | registerDefaultState(getStateDefinition().any() |
| 52 | .setValue(FACING, Direction.NORTH) | 58 | .setValue(FACING, Direction.NORTH) |
| 53 | .setValue(WATERLOGGED, false) | 59 | .setValue(WATERLOGGED, false) |
| @@ -56,7 +62,12 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 56 | 62 | ||
| 57 | @Nonnull | 63 | @Nonnull |
| 58 | @Override | 64 | @Override |
| 59 | public DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combine(BlockState state, Level world, BlockPos pos, boolean ignoreBlocked) { | 65 | public DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> combine( |
| 66 | BlockState state, | ||
| 67 | Level world, | ||
| 68 | BlockPos pos, | ||
| 69 | boolean ignoreBlocked | ||
| 70 | ) { | ||
| 60 | return DoubleBlockCombiner.Combiner::acceptNone; | 71 | return DoubleBlockCombiner.Combiner::acceptNone; |
| 61 | } | 72 | } |
| 62 | 73 | ||
| @@ -102,8 +113,16 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 102 | } | 113 | } |
| 103 | 114 | ||
| 104 | @Override | 115 | @Override |
| 105 | public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level ignoredWorld, BlockState ignoredState, BlockEntityType<T> type) { | 116 | public <T extends BlockEntity> BlockEntityTicker<T> getTicker( |
| 106 | return createTickerHelper(type, blockEntityType.get(), (world, pos, state, entity) -> entity.tick(world, pos, state)); | 117 | Level ignoredWorld, |
| 118 | BlockState ignoredState, | ||
| 119 | BlockEntityType<T> type | ||
| 120 | ) { | ||
| 121 | return createTickerHelper( | ||
| 122 | type, | ||
| 123 | blockEntityType.get(), | ||
| 124 | (world, pos, state, entity) -> entity.tick(world, pos, state) | ||
| 125 | ); | ||
| 107 | } | 126 | } |
| 108 | 127 | ||
| 109 | @SuppressWarnings("deprecation") | 128 | @SuppressWarnings("deprecation") |
| @@ -155,7 +174,14 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 155 | @SuppressWarnings("deprecation") | 174 | @SuppressWarnings("deprecation") |
| 156 | @Nonnull | 175 | @Nonnull |
| 157 | @Override | 176 | @Override |
| 158 | public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { | 177 | public BlockState updateShape( |
| 178 | BlockState state, | ||
| 179 | Direction direction, | ||
| 180 | BlockState neighborState, | ||
| 181 | LevelAccessor world, | ||
| 182 | BlockPos pos, | ||
| 183 | BlockPos neighborPos | ||
| 184 | ) { | ||
| 159 | if (state.getValue(WATERLOGGED)) { | 185 | if (state.getValue(WATERLOGGED)) { |
| 160 | world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); | 186 | world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); |
| 161 | } | 187 | } |
| @@ -166,7 +192,14 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 166 | @SuppressWarnings("deprecation") | 192 | @SuppressWarnings("deprecation") |
| 167 | @Nonnull | 193 | @Nonnull |
| 168 | @Override | 194 | @Override |
| 169 | public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { | 195 | public InteractionResult use( |
| 196 | BlockState state, | ||
| 197 | Level world, | ||
| 198 | BlockPos pos, | ||
| 199 | Player player, | ||
| 200 | InteractionHand hand, | ||
| 201 | BlockHitResult hit | ||
| 202 | ) { | ||
| 170 | if (world.isClientSide) { | 203 | if (world.isClientSide) { |
| 171 | return InteractionResult.SUCCESS; | 204 | return InteractionResult.SUCCESS; |
| 172 | } | 205 | } |
| @@ -174,7 +207,7 @@ public class AlchemicalChestBlock extends AbstractChestBlock<AlchemicalChestBloc | |||
| 174 | var provider = getMenuProvider(state, world, pos); | 207 | var provider = getMenuProvider(state, world, pos); |
| 175 | if (provider != null) { | 208 | if (provider != null) { |
| 176 | player.openMenu(provider); | 209 | player.openMenu(provider); |
| 177 | // player.awardStat(getOpenChestStat); | 210 | // TODO: player.awardStat(getOpenChestStat); |
| 178 | PiglinAi.angerNearbyPiglins(player, true); | 211 | PiglinAi.angerNearbyPiglins(player, true); |
| 179 | } | 212 | } |
| 180 | 213 | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/ErisAlchemyBlocks.java b/src/main/java/lv/enes/mc/eris_alchemy/block/ErisAlchemyBlocks.java deleted file mode 100644 index 6966681..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/ErisAlchemyBlocks.java +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 4 | import net.minecraft.resources.ResourceLocation; | ||
| 5 | import net.minecraft.world.level.block.Block; | ||
| 6 | import net.minecraft.world.level.block.Blocks; | ||
| 7 | import org.quiltmc.qsl.block.extensions.api.QuiltBlockSettings; | ||
| 8 | |||
| 9 | import java.util.LinkedHashMap; | ||
| 10 | import java.util.Map; | ||
| 11 | import java.util.function.BiConsumer; | ||
| 12 | |||
| 13 | public final class ErisAlchemyBlocks { | ||
| 14 | private static final Map<ResourceLocation, Block> blocks = new LinkedHashMap<>(); | ||
| 15 | |||
| 16 | public static final AlchemicalChestBlock ALCHEMICAL_CHEST = register("alchemical_chest", new AlchemicalChestBlock(QuiltBlockSettings.copy(Blocks.ENDER_CHEST))); | ||
| 17 | |||
| 18 | public static void consumeBlocks(BiConsumer<? super ResourceLocation, ? super Block> consumer) { | ||
| 19 | blocks.forEach(consumer); | ||
| 20 | } | ||
| 21 | |||
| 22 | private static <T extends Block> T register(String id, T block) { | ||
| 23 | blocks.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), block); | ||
| 24 | return block; | ||
| 25 | } | ||
| 26 | |||
| 27 | private ErisAlchemyBlocks() {} | ||
| 28 | |||
| 29 | } | ||
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 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block.entity; | 1 | package lv.enes.mc.eris_alchemy.block.entity; |
| 2 | 2 | ||
| 3 | import jakarta.annotation.Nonnull; | 3 | import jakarta.annotation.Nonnull; |
| 4 | import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; | 4 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; |
| 5 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; | 5 | import lv.enes.mc.eris_alchemy.menu.AlchemicalChestMenu; |
| 6 | import net.minecraft.core.BlockPos; | 6 | import net.minecraft.core.BlockPos; |
| 7 | import net.minecraft.core.NonNullList; | 7 | import net.minecraft.core.NonNullList; |
| @@ -62,8 +62,14 @@ public class AlchemicalChestBlockEntity extends BaseContainerBlockEntity impleme | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | @Override | 64 | @Override |
| 65 | protected void openerCountChanged(Level world, BlockPos pos, BlockState state, int oldViewerCount, int newViewerCount) { | 65 | protected void openerCountChanged( |
| 66 | world.blockEvent(worldPosition, ErisAlchemyBlocks.ALCHEMICAL_CHEST, EVENT, newViewerCount); | 66 | Level world, |
| 67 | BlockPos pos, | ||
| 68 | BlockState state, | ||
| 69 | int oldViewerCount, | ||
| 70 | int newViewerCount | ||
| 71 | ) { | ||
| 72 | world.blockEvent(worldPosition, ErisAlchemyRegistry.Blocks.ALCHEMICAL_CHEST, EVENT, newViewerCount); | ||
| 67 | } | 73 | } |
| 68 | 74 | ||
| 69 | @Override | 75 | @Override |
| @@ -76,7 +82,7 @@ public class AlchemicalChestBlockEntity extends BaseContainerBlockEntity impleme | |||
| 76 | }; | 82 | }; |
| 77 | 83 | ||
| 78 | public AlchemicalChestBlockEntity(BlockPos pos, BlockState state) { | 84 | public AlchemicalChestBlockEntity(BlockPos pos, BlockState state) { |
| 79 | super(ErisAlchemyBlockEntities.ALCHEMICAL_CHEST, pos, state); | 85 | super(ErisAlchemyRegistry.BlockEntities.ALCHEMICAL_CHEST, pos, state); |
| 80 | } | 86 | } |
| 81 | 87 | ||
| 82 | @Override | 88 | @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 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block.entity; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 4 | import lv.enes.mc.eris_alchemy.block.ErisAlchemyBlocks; | ||
| 5 | import net.minecraft.resources.ResourceLocation; | ||
| 6 | import net.minecraft.world.level.block.entity.BlockEntity; | ||
| 7 | import net.minecraft.world.level.block.entity.BlockEntityType; | ||
| 8 | import org.quiltmc.qsl.block.entity.api.QuiltBlockEntityTypeBuilder; | ||
| 9 | |||
| 10 | import java.util.LinkedHashMap; | ||
| 11 | import java.util.Map; | ||
| 12 | import java.util.function.BiConsumer; | ||
| 13 | |||
| 14 | public final class ErisAlchemyBlockEntities { | ||
| 15 | private static final Map<ResourceLocation, BlockEntityType<?>> entities = new LinkedHashMap<>(); | ||
| 16 | |||
| 17 | public static final BlockEntityType<AlchemicalChestBlockEntity> ALCHEMICAL_CHEST = register( | ||
| 18 | "alchemical_chest", | ||
| 19 | QuiltBlockEntityTypeBuilder.create(AlchemicalChestBlockEntity::new, ErisAlchemyBlocks.ALCHEMICAL_CHEST) | ||
| 20 | .build() | ||
| 21 | ); | ||
| 22 | |||
| 23 | public static void consumeBlockEntities(BiConsumer<? super ResourceLocation, ? super BlockEntityType<?>> consumer) { | ||
| 24 | entities.forEach(consumer); | ||
| 25 | } | ||
| 26 | |||
| 27 | private static <T extends BlockEntity> BlockEntityType<T> register(String id, BlockEntityType<T> type) { | ||
| 28 | entities.putIfAbsent(new ResourceLocation(ErisAlchemy.ID, id), type); | ||
| 29 | return type; | ||
| 30 | } | ||
| 31 | |||
| 32 | private ErisAlchemyBlockEntities() {} | ||
| 33 | } | ||