1 | package net.gamelog.suntrot.block.custom;
|
2 |
|
3 | import net.gamelog.suntrot.screen.SewingScreenHandler;
|
4 | import net.minecraft.block.*;
|
5 | import net.minecraft.entity.ai.pathing.NavigationType;
|
6 | import net.minecraft.entity.player.PlayerEntity;
|
7 | import net.minecraft.item.ItemPlacementContext;
|
8 | import net.minecraft.screen.NamedScreenHandlerFactory;
|
9 | import net.minecraft.screen.ScreenHandlerContext;
|
10 | import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
11 | import net.minecraft.state.StateManager;
|
12 | import net.minecraft.state.property.DirectionProperty;
|
13 | import net.minecraft.text.Text;
|
14 | import net.minecraft.util.*;
|
15 | import net.minecraft.util.hit.BlockHitResult;
|
16 | import net.minecraft.util.math.BlockPos;
|
17 | import net.minecraft.util.math.Direction;
|
18 | import net.minecraft.util.shape.VoxelShape;
|
19 | import net.minecraft.world.BlockView;
|
20 | import net.minecraft.world.World;
|
21 | import org.jetbrains.annotations.Nullable;
|
22 |
|
23 | public class SewingStationBlock extends Block {
|
24 | private static final Text TITLE = Text.translatable("container.suntrot.sewing");
|
25 | public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
|
26 | protected static final VoxelShape SHAPE = Block.createCuboidShape(0.0, 0.0, 0.0, 16.0, 9.0, 16.0);
|
27 |
|
28 | public SewingStationBlock(AbstractBlock.Settings settings) {
|
29 | super(settings);
|
30 | this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
|
31 | }
|
32 |
|
33 | @Override
|
34 | public BlockState getPlacementState(ItemPlacementContext ctx) {
|
35 | return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
36 | }
|
37 |
|
38 | @Override
|
39 | public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
40 | if (world.isClient) {
|
41 | return ActionResult.SUCCESS;
|
42 | } else {
|
43 | player.openHandledScreen(state.createScreenHandlerFactory(world, pos));
|
44 | return ActionResult.CONSUME;
|
45 | }
|
46 | }
|
47 |
|
48 | @Nullable
|
49 | @Override
|
50 | public NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) {
|
51 | return new SimpleNamedScreenHandlerFactory(
|
52 | (syncId, playerInventory, player) -> new SewingScreenHandler(syncId, playerInventory, ScreenHandlerContext.create(world, pos)), TITLE
|
53 | );
|
54 | }
|
55 |
|
56 | @Override
|
57 | public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
58 | return SHAPE;
|
59 | }
|
60 |
|
61 | @Override
|
62 | public boolean hasSidedTransparency(BlockState state) {
|
63 | return true;
|
64 | }
|
65 |
|
66 | @Override
|
67 | public BlockRenderType getRenderType(BlockState state) {
|
68 | return BlockRenderType.MODEL;
|
69 | }
|
70 |
|
71 | @Override
|
72 | public BlockState rotate(BlockState state, BlockRotation rotation) {
|
73 | return state.with(FACING, rotation.rotate(state.get(FACING)));
|
74 | }
|
75 |
|
76 | @Override
|
77 | public BlockState mirror(BlockState state, BlockMirror mirror) {
|
78 | return state.rotate(mirror.getRotation(state.get(FACING)));
|
79 | }
|
80 |
|
81 | @Override
|
82 | protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
83 | builder.add(FACING);
|
84 | }
|
85 |
|
86 | @Override
|
87 | public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
88 | return false;
|
89 | }
|
90 | }
|