|
4 | 4 | import me.jddev0.ep.block.entity.AdvancedAutoCrafterBlockEntity; |
5 | 5 | import me.jddev0.ep.block.entity.EPBlockEntities; |
6 | 6 | import me.jddev0.ep.util.EnergyUtils; |
7 | | -import net.minecraft.block.*; |
8 | | -import net.minecraft.block.entity.BlockEntity; |
9 | | -import net.minecraft.block.entity.BlockEntityTicker; |
10 | | -import net.minecraft.block.entity.BlockEntityType; |
11 | | -import net.minecraft.client.MinecraftClient; |
12 | | -import net.minecraft.client.MinecraftClient; |
13 | | -import net.minecraft.component.type.TooltipDisplayComponent; |
14 | | -import net.minecraft.entity.player.PlayerEntity; |
15 | | -import net.minecraft.item.BlockItem; |
16 | | -import net.minecraft.item.ItemPlacementContext; |
17 | | -import net.minecraft.item.ItemStack; |
18 | | -import net.minecraft.item.tooltip.TooltipType; |
19 | | -import net.minecraft.server.world.ServerWorld; |
20 | | -import net.minecraft.state.StateManager; |
21 | | -import net.minecraft.state.property.BooleanProperty; |
22 | | -import net.minecraft.state.property.Properties; |
23 | | -import net.minecraft.text.Text; |
24 | | -import net.minecraft.util.ActionResult; |
25 | | -import net.minecraft.util.Formatting; |
26 | | -import net.minecraft.util.ItemScatterer; |
27 | | -import net.minecraft.util.hit.BlockHitResult; |
28 | | -import net.minecraft.util.math.BlockPos; |
29 | | -import net.minecraft.util.math.Direction; |
30 | | -import net.minecraft.world.World; |
31 | | -import net.minecraft.world.block.WireOrientation; |
| 7 | +import net.minecraft.ChatFormatting; |
| 8 | +import net.minecraft.client.Minecraft; |
| 9 | +import net.minecraft.core.BlockPos; |
| 10 | +import net.minecraft.core.Direction; |
| 11 | +import net.minecraft.network.chat.Component; |
| 12 | +import net.minecraft.server.level.ServerLevel; |
| 13 | +import net.minecraft.world.Containers; |
| 14 | +import net.minecraft.world.InteractionResult; |
| 15 | +import net.minecraft.world.entity.player.Player; |
| 16 | +import net.minecraft.world.item.BlockItem; |
| 17 | +import net.minecraft.world.item.ItemStack; |
| 18 | +import net.minecraft.world.item.TooltipFlag; |
| 19 | +import net.minecraft.world.item.component.TooltipDisplay; |
| 20 | +import net.minecraft.world.item.context.BlockPlaceContext; |
| 21 | +import net.minecraft.world.level.Level; |
| 22 | +import net.minecraft.world.level.block.BaseEntityBlock; |
| 23 | +import net.minecraft.world.level.block.Block; |
| 24 | +import net.minecraft.world.level.block.RenderShape; |
| 25 | +import net.minecraft.world.level.block.entity.BlockEntity; |
| 26 | +import net.minecraft.world.level.block.entity.BlockEntityTicker; |
| 27 | +import net.minecraft.world.level.block.entity.BlockEntityType; |
| 28 | +import net.minecraft.world.level.block.state.BlockBehaviour; |
| 29 | +import net.minecraft.world.level.block.state.BlockState; |
| 30 | +import net.minecraft.world.level.block.state.StateDefinition; |
| 31 | +import net.minecraft.world.level.block.state.properties.BlockStateProperties; |
| 32 | +import net.minecraft.world.level.block.state.properties.BooleanProperty; |
| 33 | +import net.minecraft.world.level.redstone.Orientation; |
| 34 | +import net.minecraft.world.phys.BlockHitResult; |
32 | 35 | import org.jetbrains.annotations.Nullable; |
33 | 36 |
|
34 | 37 | import java.util.List; |
35 | 38 | import java.util.function.Consumer; |
36 | 39 |
|
37 | | -public class AdvancedAutoCrafterBlock extends BlockWithEntity { |
38 | | - public static final MapCodec<AdvancedAutoCrafterBlock> CODEC = createCodec(AdvancedAutoCrafterBlock::new); |
| 40 | +public class AdvancedAutoCrafterBlock extends BaseEntityBlock { |
| 41 | + public static final MapCodec<AdvancedAutoCrafterBlock> CODEC = simpleCodec(AdvancedAutoCrafterBlock::new); |
39 | 42 |
|
40 | | - public static final BooleanProperty POWERED = Properties.POWERED; |
| 43 | + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; |
41 | 44 |
|
42 | | - public AdvancedAutoCrafterBlock(AbstractBlock.Settings props) { |
| 45 | + public AdvancedAutoCrafterBlock(BlockBehaviour.Properties props) { |
43 | 46 | super(props); |
44 | 47 |
|
45 | | - this.setDefaultState(this.getStateManager().getDefaultState().with(POWERED, false)); |
| 48 | + this.registerDefaultState(this.getStateDefinition().any().setValue(POWERED, false)); |
46 | 49 | } |
47 | 50 |
|
48 | 51 | @Override |
49 | | - protected MapCodec<? extends BlockWithEntity> getCodec() { |
| 52 | + protected MapCodec<? extends BaseEntityBlock> codec() { |
50 | 53 | return CODEC; |
51 | 54 | } |
52 | 55 |
|
53 | 56 | @Nullable |
54 | 57 | @Override |
55 | | - public BlockEntity createBlockEntity(BlockPos blockPos, BlockState state) { |
| 58 | + public BlockEntity newBlockEntity(BlockPos blockPos, BlockState state) { |
56 | 59 | return new AdvancedAutoCrafterBlockEntity(blockPos, state); |
57 | 60 | } |
58 | 61 |
|
59 | 62 | @Override |
60 | | - public BlockRenderType getRenderType(BlockState state) { |
61 | | - return BlockRenderType.MODEL; |
| 63 | + public RenderShape getRenderShape(BlockState state) { |
| 64 | + return RenderShape.MODEL; |
62 | 65 | } |
63 | 66 |
|
64 | 67 | @Override |
65 | | - public boolean hasComparatorOutput(BlockState state) { |
| 68 | + public boolean hasAnalogOutputSignal(BlockState state) { |
66 | 69 | return true; |
67 | 70 | } |
68 | 71 |
|
69 | 72 | @Override |
70 | | - protected int getComparatorOutput(BlockState state, World level, BlockPos blockPos, Direction direction) { |
| 73 | + protected int getAnalogOutputSignal(BlockState state, Level level, BlockPos blockPos, Direction direction) { |
71 | 74 | BlockEntity blockEntity = level.getBlockEntity(blockPos); |
72 | 75 | if(!(blockEntity instanceof AdvancedAutoCrafterBlockEntity advancedAutoCrafterBlockEntity)) |
73 | | - return super.getComparatorOutput(state, level, blockPos, direction); |
| 76 | + return super.getAnalogOutputSignal(state, level, blockPos, direction); |
74 | 77 |
|
75 | 78 | return advancedAutoCrafterBlockEntity.getRedstoneOutput(); |
76 | 79 | } |
77 | 80 |
|
78 | 81 | @Override |
79 | | - protected void onStateReplaced(BlockState state, ServerWorld level, BlockPos blockPos, boolean moved) { |
80 | | - ItemScatterer.onStateReplaced(state, level, blockPos); |
| 82 | + protected void affectNeighborsAfterRemoval(BlockState state, ServerLevel level, BlockPos blockPos, boolean moved) { |
| 83 | + Containers.updateNeighboursAfterDestroy(state, level, blockPos); |
81 | 84 | } |
82 | 85 |
|
83 | 86 | @Override |
84 | | - public ActionResult onUse(BlockState state, World level, BlockPos blockPos, PlayerEntity player, BlockHitResult hit) { |
85 | | - if(level.isClient()) |
86 | | - return ActionResult.SUCCESS; |
| 87 | + public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos blockPos, Player player, BlockHitResult hit) { |
| 88 | + if(level.isClientSide()) |
| 89 | + return InteractionResult.SUCCESS; |
87 | 90 |
|
88 | 91 | BlockEntity blockEntity = level.getBlockEntity(blockPos); |
89 | 92 | if(!(blockEntity instanceof AdvancedAutoCrafterBlockEntity)) |
90 | 93 | throw new IllegalStateException("Container is invalid"); |
91 | 94 |
|
92 | | - player.openHandledScreen((AdvancedAutoCrafterBlockEntity)blockEntity); |
| 95 | + player.openMenu((AdvancedAutoCrafterBlockEntity)blockEntity); |
93 | 96 |
|
94 | | - return ActionResult.SUCCESS; |
| 97 | + return InteractionResult.SUCCESS; |
95 | 98 | } |
96 | 99 |
|
97 | 100 | @Override |
98 | | - public void neighborUpdate(BlockState selfState, World level, BlockPos selfPos, Block fromBlock, @Nullable WireOrientation wireOrientation, boolean isMoving) { |
99 | | - super.neighborUpdate(selfState, level, selfPos, fromBlock, wireOrientation, isMoving); |
| 101 | + public void neighborChanged(BlockState selfState, Level level, BlockPos selfPos, Block fromBlock, @Nullable Orientation wireOrientation, boolean isMoving) { |
| 102 | + super.neighborChanged(selfState, level, selfPos, fromBlock, wireOrientation, isMoving); |
100 | 103 |
|
101 | | - if(level.isClient()) |
| 104 | + if(level.isClientSide()) |
102 | 105 | return; |
103 | 106 |
|
104 | | - boolean isPowered = level.isReceivingRedstonePower(selfPos); |
105 | | - if(isPowered != selfState.get(POWERED)) |
106 | | - level.setBlockState(selfPos, selfState.with(POWERED, isPowered), 3); |
| 107 | + boolean isPowered = level.hasNeighborSignal(selfPos); |
| 108 | + if(isPowered != selfState.getValue(POWERED)) |
| 109 | + level.setBlock(selfPos, selfState.setValue(POWERED, isPowered), 3); |
107 | 110 | } |
108 | 111 |
|
109 | 112 | @Override |
110 | | - public BlockState getPlacementState(ItemPlacementContext context) { |
111 | | - return this.getDefaultState().with(POWERED, context.getWorld().isReceivingRedstonePower(context.getBlockPos())); |
| 113 | + public BlockState getStateForPlacement(BlockPlaceContext context) { |
| 114 | + return this.defaultBlockState().setValue(POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos())); |
112 | 115 | } |
113 | 116 |
|
114 | 117 | @Override |
115 | | - protected void appendProperties(StateManager.Builder<Block, BlockState> stateBuilder) { |
| 118 | + protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> stateBuilder) { |
116 | 119 | stateBuilder.add(POWERED); |
117 | 120 | } |
118 | 121 |
|
119 | 122 | @Nullable |
120 | 123 | @Override |
121 | | - public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World level, BlockState state, BlockEntityType<T> type) { |
122 | | - return validateTicker(type, EPBlockEntities.ADVANCED_AUTO_CRAFTER_ENTITY, AdvancedAutoCrafterBlockEntity::tick); |
| 124 | + public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) { |
| 125 | + return createTickerHelper(type, EPBlockEntities.ADVANCED_AUTO_CRAFTER_ENTITY, AdvancedAutoCrafterBlockEntity::tick); |
123 | 126 | } |
124 | 127 |
|
125 | 128 | public static class Item extends BlockItem { |
126 | | - public Item(Block block, Item.Settings props) { |
| 129 | + public Item(Block block, Properties props) { |
127 | 130 | super(block, props); |
128 | 131 | } |
129 | 132 |
|
130 | 133 | @Override |
131 | | - public void appendTooltip(ItemStack stack, TooltipContext context, TooltipDisplayComponent displayComponent, Consumer<Text> tooltip, TooltipType type) { |
132 | | - if(MinecraftClient.getInstance().isShiftPressed()) { |
133 | | - tooltip.accept(Text.translatable("tooltip.energizedpower.auto_crafter.txt.shift.1", |
134 | | - EnergyUtils.getEnergyWithPrefix(AdvancedAutoCrafterBlockEntity.ENERGY_CONSUMPTION_PER_TICK_PER_INGREDIENT)).formatted(Formatting.GRAY)); |
| 134 | + public void appendHoverText(ItemStack stack, TooltipContext context, TooltipDisplay displayComponent, Consumer<Component> tooltip, TooltipFlag type) { |
| 135 | + if(Minecraft.getInstance().hasShiftDown()) { |
| 136 | + tooltip.accept(Component.translatable("tooltip.energizedpower.auto_crafter.txt.shift.1", |
| 137 | + EnergyUtils.getEnergyWithPrefix(AdvancedAutoCrafterBlockEntity.ENERGY_CONSUMPTION_PER_TICK_PER_INGREDIENT)).withStyle(ChatFormatting.GRAY)); |
135 | 138 | }else { |
136 | | - tooltip.accept(Text.translatable("tooltip.energizedpower.shift_details.txt").formatted(Formatting.YELLOW)); |
| 139 | + tooltip.accept(Component.translatable("tooltip.energizedpower.shift_details.txt").withStyle(ChatFormatting.YELLOW)); |
137 | 140 | } |
138 | 141 | } |
139 | 142 | } |
|
0 commit comments