Unknown Log

#EzESGRE
90 lines
Raw
1package net.gamelog.suntrot.block.custom;
2
3import net.gamelog.suntrot.screen.SewingScreenHandler;
4import net.minecraft.block.*;
5import net.minecraft.entity.ai.pathing.NavigationType;
6import net.minecraft.entity.player.PlayerEntity;
7import net.minecraft.item.ItemPlacementContext;
8import net.minecraft.screen.NamedScreenHandlerFactory;
9import net.minecraft.screen.ScreenHandlerContext;
10import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
11import net.minecraft.state.StateManager;
12import net.minecraft.state.property.DirectionProperty;
13import net.minecraft.text.Text;
14import net.minecraft.util.*;
15import net.minecraft.util.hit.BlockHitResult;
16import net.minecraft.util.math.BlockPos;
17import net.minecraft.util.math.Direction;
18import net.minecraft.util.shape.VoxelShape;
19import net.minecraft.world.BlockView;
20import net.minecraft.world.World;
21import org.jetbrains.annotations.Nullable;
22
23public 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}
This log will be saved for 90 days from their last view.
Report abuse