77import com .mrh0 .createaddition .debug .IDebugDrawer ;
88import com .mrh0 .createaddition .energy .IMultiTileEnergyContainer ;
99import com .mrh0 .createaddition .energy .InternalEnergyStorage ;
10- import com .mrh0 .createaddition .network .EnergyNetworkPacket ;
1110import com .mrh0 .createaddition .network .IObserveTileEntity ;
12- import com .mrh0 .createaddition .network .ObservePacketLegacy ;
11+ import com .mrh0 .createaddition .network .ObservePacketPayload ;
1312import com .mrh0 .createaddition .sound .CASoundScapes ;
1413import com .mrh0 .createaddition .util .Util ;
1514import com .simibubi .create .Create ;
2221import net .minecraft .ChatFormatting ;
2322import net .minecraft .core .BlockPos ;
2423import net .minecraft .core .Direction ;
24+ import net .minecraft .core .HolderLookup ;
2525import net .minecraft .nbt .CompoundTag ;
2626import net .minecraft .nbt .NbtUtils ;
2727import net .minecraft .network .chat .Component ;
3333import net .minecraft .world .level .block .state .BlockState ;
3434import net .minecraft .world .phys .AABB ;
3535import net .minecraft .world .phys .shapes .VoxelShape ;
36- import net .minecraftforge .api .distmarker .Dist ;
37- import net .minecraftforge .common .capabilities .Capability ;
38- import net .minecraftforge .common .capabilities .ForgeCapabilities ;
39- import net .minecraftforge .common .util .LazyOptional ;
40- import net .minecraftforge .energy .IEnergyStorage ;
41- import net .minecraftforge .fml .DistExecutor ;
42-
43- import javax .annotation .Nonnull ;
44- import javax .annotation .Nullable ;
36+ import net .neoforged .neoforge .energy .IEnergyStorage ;
37+
4538import java .util .EnumMap ;
4639import java .util .EnumSet ;
4740import java .util .List ;
@@ -72,8 +65,7 @@ public ModularAccumulatorBlockEntity(BlockEntityType<?> type, BlockPos pos, Bloc
7265 width = 1 ;
7366 refreshCapability ();
7467
75- if (CreateAddition .CC_ACTIVE )
76- this .peripheral = LazyOptional .of (() -> Peripherals .createModularAccumulatorPeripheral (this ));
68+ // if (CreateAddition.CC_ACTIVE) this.peripheral = LazyOptional.of(() -> Peripherals.createModularAccumulatorPeripheral(this));
7769 }
7870
7971 @ Override
@@ -100,7 +92,7 @@ private void invalidCache(Direction side) {
10092 }
10193
10294 public void updateCache () {
103- if (level .isClientSide ()) return ;
95+ if (level .isClientSide ()) return ;
10496 for (Direction side : Direction .values ()) {
10597 updateCache (side );
10698 }
@@ -153,12 +145,10 @@ public void tick() {
153145
154146 if (syncCooldown > 0 ) {
155147 syncCooldown --;
156- if (syncCooldown == 0 && queuedSync )
157- sendData ();
148+ if (syncCooldown == 0 && queuedSync ) sendData ();
158149 }
159150
160- if (lastKnownPos == null )
161- lastKnownPos = getBlockPos ();
151+ if (lastKnownPos == null ) lastKnownPos = getBlockPos ();
162152 else if (!lastKnownPos .equals (worldPosition ) && worldPosition != null ) {
163153 onPositionChanged ();
164154 return ;
@@ -364,76 +354,64 @@ protected AABB createRenderBoundingBox() {
364354 }
365355
366356 @ Override
367- protected void read (CompoundTag compound , boolean clientPacket ) {
368- super .read (compound , clientPacket );
357+ protected void read (CompoundTag tag , HolderLookup . Provider registries , boolean clientPacket ) {
358+ super .read (tag , registries , clientPacket );
369359
370360 BlockPos controllerBefore = controller ;
371361 int prevSize = width ;
372362 int prevHeight = height ;
373363
374- updateConnectivity = compound .contains ("Uninitialized" );
364+ updateConnectivity = tag .contains ("Uninitialized" );
375365 controller = null ;
376366 lastKnownPos = null ;
377367
378- if (compound .contains ("LastKnownPos" ))
379- lastKnownPos = NbtUtils .readBlockPos (compound .getCompound ("LastKnownPos" ));
380- if (compound .contains ("Controller" ))
381- controller = NbtUtils .readBlockPos (compound .getCompound ("Controller" ));
368+ if (tag .contains ("LastKnownPos" )) lastKnownPos = NbtUtils .readBlockPos (tag , "LastKnownPos" ).orElse (BlockPos .ZERO );
369+ if (tag .contains ("Controller" )) controller = NbtUtils .readBlockPos (tag , "Controller" ).orElse (BlockPos .ZERO );
382370
383371 if (isController ()) {
384- width = compound .getInt ("Size" );
385- height = compound .getInt ("Height" );
372+ width = tag .getInt ("Size" );
373+ height = tag .getInt ("Height" );
386374 energyStorage .setCapacity (getTotalAccumulatorSize () * getCapacityMultiplier ());
387- energyStorage .read (compound .getCompound ("EnergyContent" ));
375+ energyStorage .read (tag .getCompound ("EnergyContent" ));
388376 if (energyStorage .getSpace () < 0 )
389377 energyStorage .extractEnergy (-energyStorage .getSpace (), true );
390378 }
391379
380+ if (!clientPacket ) return ;
392381
393- if (!clientPacket )
394- return ;
395-
396- boolean changeOfController =
397- controllerBefore == null ? controller != null : !controllerBefore .equals (controller );
382+ boolean changeOfController = controllerBefore == null ? controller != null : !controllerBefore .equals (controller );
398383 if (changeOfController || prevSize != width || prevHeight != height ) {
399- if (hasLevel ())
400- level .sendBlockUpdated (getBlockPos (), getBlockState (), getBlockState (), 16 );
401- if (isController ())
402- energyStorage .setCapacity (getCapacityMultiplier () * getTotalAccumulatorSize ());
384+ if (hasLevel ()) level .sendBlockUpdated (getBlockPos (), getBlockState (), getBlockState (), 16 );
385+ if (isController ()) energyStorage .setCapacity (getCapacityMultiplier () * getTotalAccumulatorSize ());
403386 invalidateRenderBoundingBox ();
404387 }
405388
406- if (isController ())
407- gauge .chase (getFillState (), 0.125f , LerpedFloat .Chaser .EXP );
389+ if (isController ()) gauge .chase (getFillState (), 0.125f , LerpedFloat .Chaser .EXP );
408390 }
409391
410392 public float getFillState () {
411393 return (float ) energyStorage .getEnergyStored () / energyStorage .getMaxEnergyStored ();
412394 }
413395
414396 @ Override
415- public void write (CompoundTag compound , boolean clientPacket ) {
416- if (updateConnectivity )
417- compound .putBoolean ("Uninitialized" , true );
418- if (lastKnownPos != null )
419- compound .put ("LastKnownPos" , NbtUtils .writeBlockPos (lastKnownPos ));
420- if (!isController ())
421- compound .put ("Controller" , NbtUtils .writeBlockPos (controller ));
397+ public void writeSafe (CompoundTag tag , HolderLookup .Provider registries ) {
398+ if (updateConnectivity ) tag .putBoolean ("Uninitialized" , true );
399+ if (lastKnownPos != null ) tag .put ("LastKnownPos" , NbtUtils .writeBlockPos (lastKnownPos ));
400+ if (!isController ()) tag .put ("Controller" , NbtUtils .writeBlockPos (controller ));
422401 if (isController ()) {
423- compound .put ("EnergyContent" , energyStorage .write (new CompoundTag ()));
402+ tag .put ("EnergyContent" , energyStorage .write (new CompoundTag ()));
424403 // Used by contraptions.
425- compound .putInt ("EnergyCapacity" , getTotalAccumulatorSize () * getCapacityMultiplier ());
426- compound .putInt ("Size" , width );
427- compound .putInt ("Height" , height );
404+ tag .putInt ("EnergyCapacity" , getTotalAccumulatorSize () * getCapacityMultiplier ());
405+ tag .putInt ("Size" , width );
406+ tag .putInt ("Height" , height );
428407 }
429- super .write ( compound , clientPacket );
408+ super .writeSafe ( tag , registries );
430409
431- if (!clientPacket )
432- return ;
433- if (queuedSync )
434- compound .putBoolean ("LazySync" , true );
410+ // if (!clientPacket) return;
411+ if (queuedSync ) tag .putBoolean ("LazySync" , true );
435412 }
436413
414+ /*
437415 @Nonnull
438416 @Override
439417 public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
@@ -442,10 +420,11 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
442420 if (CreateAddition.CC_ACTIVE && Peripherals.isPeripheral(cap)) return this.peripheral.cast();
443421 return super.getCapability(cap, side);
444422 }
423+ */
445424
446425 @ Override
447426 public void invalidate () {
448- energyCap .invalidate ();
427+ // energyCap.invalidate();
449428 super .invalidate ();
450429 }
451430
@@ -524,7 +503,7 @@ public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneak
524503 ModularAccumulatorBlockEntity controllerTE = getControllerBE ();
525504 if (controllerTE == null ) return false ;
526505
527- ObservePacketLegacy .send (worldPosition , 0 );
506+ ObservePacketPayload .send (worldPosition , 0 );
528507
529508 String spacing = " " ;
530509 tooltip .add (Component .literal (spacing )
@@ -544,7 +523,7 @@ public boolean addToGoggleTooltip(List<Component> tooltip, boolean isPlayerSneak
544523 public void observe () {}
545524
546525 @ Override
547- public void onObserved (ServerPlayer player , ObservePacketLegacy pack ) {
526+ public void onObserved (ServerPlayer player , ObservePacketPayload pack ) {
548527 ModularAccumulatorBlockEntity controllerTE = getControllerBE ();
549528 if (controllerTE == null ) return ;
550529
0 commit comments