From cb6c6337a82adf7cffaf931b6d76cb534c63d542 Mon Sep 17 00:00:00 2001 From: drcrazy Date: Mon, 19 Jul 2021 16:15:49 +0300 Subject: [PATCH] Fix some warnings. --- .../multiblock/MultiblockControllerBase.java | 27 +++++++++---------- .../multiblock/MultiblockWorldRegistry.java | 5 ++-- .../network/ClientBoundPacketHandlers.java | 1 + .../reborncore/common/util/WorldUtils.java | 13 +++++++-- src/main/java/techreborn/init/TRContent.java | 8 +++--- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockControllerBase.java b/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockControllerBase.java index e0e935937..ea96e7184 100644 --- a/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockControllerBase.java +++ b/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockControllerBase.java @@ -56,7 +56,6 @@ public abstract class MultiblockControllerBase { Disassembled, Assembled, Paused } - ; protected AssemblyState assemblyState; public HashSet connectedParts; @@ -398,7 +397,6 @@ public abstract class MultiblockControllerBase { * now is, assemble the machine. If the machine was whole, but no longer is, * disassemble the machine. * - * @return */ public void checkIfMachineIsWhole() { AssemblyState oldState = this.assemblyState; @@ -494,15 +492,16 @@ public abstract class MultiblockControllerBase { * @param otherController The controller consuming this controller. */ private void _onAssimilated(MultiblockControllerBase otherController) { - if (referenceCoord != null) { - if (this.worldObj.isChunkLoaded(this.referenceCoord)) { - BlockEntity te = this.worldObj.getBlockEntity(referenceCoord); - if (te instanceof IMultiblockPart) { - ((IMultiblockPart) te).forfeitMultiblockSaveDelegate(); - } + if (referenceCoord == null) { return; } + + if (WorldUtils.isChunkLoaded(worldObj, referenceCoord)) { + BlockEntity te = this.worldObj.getBlockEntity(referenceCoord); + if (te instanceof IMultiblockPart) { + ((IMultiblockPart) te).forfeitMultiblockSaveDelegate(); } - this.referenceCoord = null; } + this.referenceCoord = null; + connectedParts.clear(); } @@ -862,7 +861,7 @@ public abstract class MultiblockControllerBase { * Called when this machine may need to check for blocks that are no longer * physically connected to the reference coordinate. * - * @return + * @return Set with removed parts */ public Set checkForDisconnections() { if (!this.shouldCheckForDisconnections) { @@ -886,7 +885,7 @@ public abstract class MultiblockControllerBase { for (IMultiblockPart part : connectedParts) { pos = part.getWorldLocation(); - if (!this.worldObj.isChunkLoaded(pos) || part.isInvalid()) { + if (!WorldUtils.isChunkLoaded(worldObj, pos) || part.isInvalid()) { deadParts.add(part); onDetachBlock(part); continue; @@ -927,7 +926,7 @@ public abstract class MultiblockControllerBase { // coord's part IMultiblockPart part; LinkedList partsToCheck = new LinkedList<>(); - IMultiblockPart[] nearbyParts = null; + IMultiblockPart[] nearbyParts; int visitedParts = 0; partsToCheck.add(referencePart); @@ -992,7 +991,7 @@ public abstract class MultiblockControllerBase { } for (IMultiblockPart part : connectedParts) { - if (this.worldObj.isChunkLoaded(part.getWorldLocation())) { + if (WorldUtils.isChunkLoaded(worldObj, part.getWorldLocation())) { onDetachBlock(part); } } @@ -1017,7 +1016,7 @@ public abstract class MultiblockControllerBase { for (IMultiblockPart part : connectedParts) { pos = part.getWorldLocation(); - if (part.isInvalid() || !this.worldObj.isChunkLoaded(pos)) { + if (part.isInvalid() || !WorldUtils.isChunkLoaded(worldObj, pos)) { // Chunk is unloading, skip this coord to prevent chunk thrashing continue; } diff --git a/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockWorldRegistry.java b/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockWorldRegistry.java index f008fa25c..3037b70d3 100644 --- a/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockWorldRegistry.java +++ b/RebornCore/src/main/java/reborncore/common/multiblock/MultiblockWorldRegistry.java @@ -29,6 +29,7 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import reborncore.RebornCore; +import reborncore.common.util.WorldUtils; import java.util.*; @@ -140,7 +141,7 @@ public class MultiblockWorldRegistry { // controller for (IMultiblockPart orphan : orphansToProcess) { coord = orphan.getWorldLocation(); - if (!this.worldObj.isChunkLoaded(coord)) { + if (!WorldUtils.isChunkLoaded(worldObj, coord)) { continue; } @@ -318,7 +319,7 @@ public class MultiblockWorldRegistry { public void onPartAdded(IMultiblockPart part) { BlockPos pos = part.getWorldLocation(); - if (!this.worldObj.isChunkLoaded(pos)) { + if (!WorldUtils.isChunkLoaded(worldObj, pos)) { // Part goes into the waiting-for-chunk-load list Set partSet; int chunkHash = new ChunkPos(pos).hashCode(); diff --git a/RebornCore/src/main/java/reborncore/common/network/ClientBoundPacketHandlers.java b/RebornCore/src/main/java/reborncore/common/network/ClientBoundPacketHandlers.java index 7b9b52f4f..385799aa6 100644 --- a/RebornCore/src/main/java/reborncore/common/network/ClientBoundPacketHandlers.java +++ b/RebornCore/src/main/java/reborncore/common/network/ClientBoundPacketHandlers.java @@ -46,6 +46,7 @@ import reborncore.common.blockentity.FluidConfiguration; import reborncore.common.blockentity.MachineBaseBlockEntity; import reborncore.common.blockentity.SlotConfiguration; import reborncore.common.chunkloading.ChunkLoaderManager; +import reborncore.common.util.WorldUtils; import java.util.List; diff --git a/RebornCore/src/main/java/reborncore/common/util/WorldUtils.java b/RebornCore/src/main/java/reborncore/common/util/WorldUtils.java index d09052dbf..891a24661 100644 --- a/RebornCore/src/main/java/reborncore/common/util/WorldUtils.java +++ b/RebornCore/src/main/java/reborncore/common/util/WorldUtils.java @@ -29,6 +29,7 @@ import net.minecraft.entity.ItemEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkSectionPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -45,10 +46,18 @@ public class WorldUtils { world.updateListeners(pos, state, state, 3); } - public static boolean chunkExists(World world, int x, int z) { - return world.isChunkLoaded(new BlockPos(x << 4, 64, z << 4)); + /** + * Checks if chunk is loaded using proper chunk manager + * + * @param world World object + * @param pos BlockPos X and Z coordinates to check + * @return boolean True if chunk is loaded + */ + public static boolean isChunkLoaded(World world, BlockPos pos){ + return world.getChunkManager().isChunkLoaded(ChunkSectionPos.getSectionCoord(pos.getX()), ChunkSectionPos.getSectionCoord(pos.getZ())); } + public static void dropItem(ItemStack itemStack, World world, BlockPos pos) { Random rand = new Random(); diff --git a/src/main/java/techreborn/init/TRContent.java b/src/main/java/techreborn/init/TRContent.java index 4752c0f74..4d109025d 100644 --- a/src/main/java/techreborn/init/TRContent.java +++ b/src/main/java/techreborn/init/TRContent.java @@ -498,7 +498,7 @@ public class TRContent { public static ItemConvertible[] getCasings() { return Arrays.stream(MachineBlocks.values()) - .map((Function) machineBlocks -> () -> machineBlocks.casing.asItem()) + .map((Function) machineBlocks -> machineBlocks.casing::asItem) .toArray(ItemConvertible[]::new); } } @@ -855,8 +855,10 @@ public class TRContent { if (blockEntity instanceof PowerAcceptorBlockEntity) { powerAcceptor = (PowerAcceptorBlockEntity) blockEntity; } - handler.addSpeedMulti(TechRebornConfig.overclockerSpeed); - handler.addPowerMulti(TechRebornConfig.overclockerPower); + if (handler != null) { + handler.addSpeedMulti(TechRebornConfig.overclockerSpeed); + handler.addPowerMulti(TechRebornConfig.overclockerPower); + } if (powerAcceptor != null) { powerAcceptor.extraPowerInput += powerAcceptor.getMaxInput(EnergySide.UNKNOWN); powerAcceptor.extraPowerStorage += powerAcceptor.getBaseMaxPower();