38
38
import dev .galacticraft .machinelib .impl .block .entity .MachineBlockEntityTicker ;
39
39
import net .minecraft .client .gui .screens .Screen ;
40
40
import net .minecraft .core .BlockPos ;
41
+ import net .minecraft .core .component .DataComponentPatch ;
41
42
import net .minecraft .core .component .DataComponents ;
42
43
import net .minecraft .core .registries .BuiltInRegistries ;
43
- import net .minecraft .nbt .*;
44
+ import net .minecraft .nbt .ByteTag ;
45
+ import net .minecraft .nbt .CompoundTag ;
46
+ import net .minecraft .nbt .NbtOps ;
47
+ import net .minecraft .nbt .Tag ;
44
48
import net .minecraft .network .chat .Component ;
45
49
import net .minecraft .network .chat .MutableComponent ;
46
50
import net .minecraft .resources .ResourceLocation ;
47
51
import net .minecraft .server .level .ServerPlayer ;
48
- import net .minecraft .world .InteractionHand ;
49
52
import net .minecraft .world .InteractionResult ;
50
53
import net .minecraft .world .entity .LivingEntity ;
51
54
import net .minecraft .world .entity .item .ItemEntity ;
84
87
/**
85
88
* The base block for all machines.
86
89
*
87
- * @see MachineBlockEntity
90
+ * @param <Machine> The machine block entity attached to this block.
88
91
*/
89
92
public class MachineBlock <Machine extends MachineBlockEntity > extends BaseEntityBlock {
90
93
public static final MapCodec <MachineBlock <? extends MachineBlockEntity >> CODEC = RecordCodecBuilder .mapCodec (instance -> instance .group (
@@ -256,9 +259,9 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
256
259
}
257
260
258
261
@ Override
259
- public final @ NotNull InteractionResult useWithoutItem (BlockState state , @ NotNull Level world , BlockPos pos , Player player , BlockHitResult hit ) {
260
- if (!world .isClientSide ) {
261
- BlockEntity entity = world .getBlockEntity (pos );
262
+ public final @ NotNull InteractionResult useWithoutItem (BlockState state , @ NotNull Level level , BlockPos pos , Player player , BlockHitResult hit ) {
263
+ if (!level .isClientSide ) {
264
+ BlockEntity entity = level .getBlockEntity (pos );
262
265
if (entity instanceof MachineBlockEntity machine ) {
263
266
SecuritySettings security = machine .getSecurity ();
264
267
@@ -274,21 +277,21 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
274
277
}
275
278
276
279
@ Override
277
- public BlockState playerWillDestroy (Level world , BlockPos pos , BlockState state , Player player ) {
278
- super .playerWillDestroy (world , pos , state , player );
279
- BlockEntity entity = world .getBlockEntity (pos );
280
+ public BlockState playerWillDestroy (Level level , BlockPos pos , BlockState state , Player player ) {
281
+ super .playerWillDestroy (level , pos , state , player );
282
+ BlockEntity entity = level .getBlockEntity (pos );
280
283
if (entity instanceof MachineBlockEntity machine ) {
281
284
if (!machine .areDropsDisabled ()) {
282
285
MachineItemStorage inv = machine .itemStorage ();
283
286
List <ItemEntity > entities = new ArrayList <>();
284
287
for (ItemResourceSlot slot : inv .getSlots ()) {
285
288
if (!slot .isEmpty ()) {
286
- entities .add (new ItemEntity (world , pos .getX (), pos .getY () + 1 , pos .getZ (), ItemStackUtil .create (slot )));
287
- slot .set (null , null , 0 );
289
+ entities .add (new ItemEntity (level , pos .getX (), pos .getY () + 1 , pos .getZ (), ItemStackUtil .create (slot )));
290
+ slot .set (null , DataComponentPatch . EMPTY , 0 );
288
291
}
289
292
}
290
293
for (ItemEntity itemEntity : entities ) {
291
- world .addFreshEntity (itemEntity );
294
+ level .addFreshEntity (itemEntity );
292
295
}
293
296
}
294
297
}
@@ -310,7 +313,7 @@ public BlockState playerWillDestroy(Level world, BlockPos pos, BlockState state,
310
313
BlockEntity blockEntity = reader .getBlockEntity (pos );
311
314
if (blockEntity instanceof MachineBlockEntity machine ) {
312
315
CompoundTag config = new CompoundTag ();
313
- config .put (Constant .Nbt .CONFIGURATION , machine .getIOConfig ().createTag ());
316
+ config .put (Constant .Nbt .CONFIGURATION , machine .getIoConfig ().createTag ());
314
317
config .put (Constant .Nbt .SECURITY , machine .getSecurity ().createTag ());
315
318
config .put (Constant .Nbt .REDSTONE_MODE , machine .getRedstoneMode ().createTag ());
316
319
BlockItem .setBlockEntityData (stack , blockEntity .getType (), config );
@@ -321,17 +324,16 @@ public BlockState playerWillDestroy(Level world, BlockPos pos, BlockState state,
321
324
322
325
@ Nullable
323
326
@ Override
324
- public <B extends BlockEntity > BlockEntityTicker <B > getTicker (Level world , BlockState state , BlockEntityType <B > type ) {
325
- return !world .isClientSide ? MachineBlockEntityTicker .getInstance () : null ;
327
+ public <B extends BlockEntity > BlockEntityTicker <B > getTicker (Level level , BlockState state , BlockEntityType <B > type ) {
328
+ return !level .isClientSide ? MachineBlockEntityTicker .getInstance () : null ;
326
329
}
327
330
328
331
/**
329
- * Returns this machine's description for the tooltip when left shift is pressed.
332
+ * {@return this machine's detailed tooltip description} Shown when left shift is pressed.
330
333
*
331
334
* @param stack The item stack (the contained item is this block).
332
335
* @param context The context of the tooltip.
333
336
* @param flag Flags to determine if extra information should be added
334
- * @return This machine's description.
335
337
*/
336
338
public @ Nullable Component shiftDescription (ItemStack stack , TooltipContext context , TooltipFlag flag ) {
337
339
return Component .translatable (this .getDescriptionId () + ".description" );
0 commit comments