diff --git a/src/main/java/mekanism/client/MekanismClient.java b/src/main/java/mekanism/client/MekanismClient.java index 5149dab0a94..2a1d5ab94c0 100644 --- a/src/main/java/mekanism/client/MekanismClient.java +++ b/src/main/java/mekanism/client/MekanismClient.java @@ -60,7 +60,7 @@ public static void resetDimensionChange() { Mekanism.activeVibrators.clear(); RadiationManager.get().resetClient(); RenderSPS.clearBoltRenderers(); - TransmitterNetworkRegistry.getInstance().clearClientNetworks(); + TransmitterNetworkRegistry.clearClientNetworks(); RenderTickHandler.clearQueued(); for (IModModule module : Mekanism.modulesLoaded) { diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 3574aabf2a3..5cbf5d67f25 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -368,9 +368,6 @@ private void commonSetup(FMLCommonSetupEvent event) { NeoForge.EVENT_BUS.register(RadiationManager.get()); - //Register with TransmitterNetworkRegistry - TransmitterNetworkRegistry.initiate(); - //Fake player info logger.info("Fake player readout: UUID = {}, name = {}", gameProfile.getId(), gameProfile.getName()); logger.info("Mod loaded."); diff --git a/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java b/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java index 27a5bf4d85b..460257f7cbb 100644 --- a/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java +++ b/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java @@ -456,7 +456,7 @@ public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Prov //Nothing needs to be done return; } - DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getInstance().getClientNetwork(networkID); + DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getClientNetwork(networkID); if (clientNetwork == null) { NETWORK network = createEmptyNetworkWithID(networkID); network.register(); diff --git a/src/main/java/mekanism/common/item/ItemNetworkReader.java b/src/main/java/mekanism/common/item/ItemNetworkReader.java index becbb2a75d0..d4df23f77c5 100644 --- a/src/main/java/mekanism/common/item/ItemNetworkReader.java +++ b/src/main/java/mekanism/common/item/ItemNetworkReader.java @@ -81,7 +81,7 @@ public InteractionResult useOn(UseOnContext context) { return InteractionResult.CONSUME; } else if (player.isShiftKeyDown() && MekanismAPI.debug) { displayBorder(player, MekanismLang.DEBUG_TITLE, true); - for (Component component : TransmitterNetworkRegistry.getInstance().toComponents()) { + for (Component component : TransmitterNetworkRegistry.toComponents()) { player.sendSystemMessage(TextComponentUtil.build(EnumColor.DARK_GRAY, component)); } displayEndBorder(player); diff --git a/src/main/java/mekanism/common/lib/transmitter/DynamicNetwork.java b/src/main/java/mekanism/common/lib/transmitter/DynamicNetwork.java index d518883786d..a5d8656cca5 100644 --- a/src/main/java/mekanism/common/lib/transmitter/DynamicNetwork.java +++ b/src/main/java/mekanism/common/lib/transmitter/DynamicNetwork.java @@ -172,9 +172,9 @@ protected void adoptAllAndRegister(Collection networks) { public void register() { if (isRemote()) { - TransmitterNetworkRegistry.getInstance().addClientNetwork(getUUID(), this); + TransmitterNetworkRegistry.addClientNetwork(getUUID(), this); } else { - TransmitterNetworkRegistry.getInstance().registerNetwork(this); + TransmitterNetworkRegistry.registerNetwork(this); } } @@ -184,9 +184,9 @@ public void deregister() { acceptorCache.deregister(); transmitterValidator = null; if (isRemote()) { - TransmitterNetworkRegistry.getInstance().removeClientNetwork(this); + TransmitterNetworkRegistry.removeClientNetwork(this); } else { - TransmitterNetworkRegistry.getInstance().removeNetwork(this); + TransmitterNetworkRegistry.removeNetwork(this); } } diff --git a/src/main/java/mekanism/common/lib/transmitter/TransmitterNetworkRegistry.java b/src/main/java/mekanism/common/lib/transmitter/TransmitterNetworkRegistry.java index b6b8d1f0dfd..247f75f6269 100644 --- a/src/main/java/mekanism/common/lib/transmitter/TransmitterNetworkRegistry.java +++ b/src/main/java/mekanism/common/lib/transmitter/TransmitterNetworkRegistry.java @@ -29,84 +29,75 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.ChunkAccess; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.event.level.ChunkTicketLevelUpdatedEvent; import net.neoforged.neoforge.event.tick.ServerTickEvent; import org.jetbrains.annotations.Nullable; +@EventBusSubscriber(modid = Mekanism.MODID) public class TransmitterNetworkRegistry { - private static final TransmitterNetworkRegistry INSTANCE = new TransmitterNetworkRegistry(); - private static boolean loaderRegistered = false; - private final Multimap> transmitters = HashMultimap.create(); - private Object2BooleanMap changedTicketChunks = new Object2BooleanOpenHashMap<>(); - private final Set> networks = new ObjectOpenHashSet<>(); - private final Map> clientNetworks = new Object2ObjectOpenHashMap<>(); - private Map> newOrphanTransmitters = new Object2ObjectOpenHashMap<>(); - private Set> invalidTransmitters = new ObjectOpenHashSet<>(); - private Set> networksToChange = new ObjectOpenHashSet<>(); + private static final Multimap> transmitters = HashMultimap.create(); + private static Object2BooleanMap changedTicketChunks = new Object2BooleanOpenHashMap<>(); + private static final Set> networks = new ObjectOpenHashSet<>(); + private static final Map> clientNetworks = new Object2ObjectOpenHashMap<>(); + private static Map> newOrphanTransmitters = new Object2ObjectOpenHashMap<>(); + private static Set> invalidTransmitters = new ObjectOpenHashSet<>(); + private static Set> networksToChange = new ObjectOpenHashSet<>(); - public void addClientNetwork(UUID networkID, DynamicNetwork network) { + public static void addClientNetwork(UUID networkID, DynamicNetwork network) { if (!clientNetworks.containsKey(networkID)) { clientNetworks.put(networkID, network); } } @Nullable - public DynamicNetwork getClientNetwork(UUID networkID) { + public static DynamicNetwork getClientNetwork(UUID networkID) { return clientNetworks.get(networkID); } - public void removeClientNetwork(DynamicNetwork network) { + public static void removeClientNetwork(DynamicNetwork network) { clientNetworks.remove(network.getUUID()); } - public void clearClientNetworks() { + public static void clearClientNetworks() { clientNetworks.clear(); } - public static void initiate() { - if (!loaderRegistered) { - loaderRegistered = true; - NeoForge.EVENT_BUS.register(INSTANCE); - } - } - public static void reset() { - getInstance().networks.clear(); - getInstance().networksToChange.clear(); - getInstance().invalidTransmitters.clear(); - getInstance().newOrphanTransmitters.clear(); - getInstance().transmitters.clear(); - getInstance().changedTicketChunks.clear(); + networks.clear(); + networksToChange.clear(); + invalidTransmitters.clear(); + newOrphanTransmitters.clear(); + transmitters.clear(); + changedTicketChunks.clear(); } public static void trackTransmitter(Transmitter transmitter) { - getInstance().transmitters.put(transmitter.getTileChunk(), transmitter); + transmitters.put(transmitter.getTileChunk(), transmitter); } public static void untrackTransmitter(Transmitter transmitter) { - getInstance().transmitters.remove(transmitter.getTileChunk(), transmitter); + transmitters.remove(transmitter.getTileChunk(), transmitter); } public static void invalidateTransmitter(Transmitter transmitter) { - TransmitterNetworkRegistry registry = getInstance(); - registry.invalidTransmitters.add(transmitter); + invalidTransmitters.add(transmitter); GlobalPos coord = transmitter.getTileGlobalPos(); - Transmitter removed = registry.newOrphanTransmitters.remove(coord); + Transmitter removed = newOrphanTransmitters.remove(coord); if (removed != null && removed != transmitter) { Mekanism.logger.error("Different orphan transmitter was registered at location during removal! {}", coord); - registry.newOrphanTransmitters.put(coord, transmitter);//put it back? + newOrphanTransmitters.put(coord, transmitter);//put it back? } } public static void registerOrphanTransmitter(Transmitter transmitter) { - if (!getInstance().invalidTransmitters.remove(transmitter)) { + if (!invalidTransmitters.remove(transmitter)) { //If we weren't an invalid transmitter, then we need to add it as a new orphan, otherwise removing it is good enough // as if it was an orphan before it still will be one, and if it wasn't then it still will be part of the network it // was in. GlobalPos pos = transmitter.getTileGlobalPos(); - Transmitter previous = getInstance().newOrphanTransmitters.put(pos, transmitter); + Transmitter previous = newOrphanTransmitters.put(pos, transmitter); if (previous != null && previous != transmitter && previous.isValid()) { Mekanism.logger.error("Different orphan transmitter was already registered at location! {}", pos); } @@ -114,24 +105,20 @@ public static void registerOrphanTransmitter(Transmitter transmitter) { } public static void registerChangedNetwork(DynamicNetwork network) { - getInstance().networksToChange.add(network); + networksToChange.add(network); } - public static TransmitterNetworkRegistry getInstance() { - return INSTANCE; - } - - public void registerNetwork(DynamicNetwork network) { + public static void registerNetwork(DynamicNetwork network) { networks.add(network); } - public void removeNetwork(DynamicNetwork network) { + public static void removeNetwork(DynamicNetwork network) { networks.remove(network); networksToChange.remove(network); } @SubscribeEvent - public void onTick(ServerTickEvent.Post event) { + public static void onTick(ServerTickEvent.Post event) { handleChangedChunks(); removeInvalidTransmitters(); assignOrphans(); @@ -144,7 +131,7 @@ public void onTick(ServerTickEvent.Post event) { } @SubscribeEvent - public void onTicketLevelChange(ChunkTicketLevelUpdatedEvent event) { + public static void onTicketLevelChange(ChunkTicketLevelUpdatedEvent event) { int newTicketLevel = event.getNewTicketLevel(); int oldTicketLevel = event.getOldTicketLevel(); boolean loaded; @@ -174,7 +161,7 @@ public void onTicketLevelChange(ChunkTicketLevelUpdatedEvent event) { } } - private void handleChangedChunks() { + private static void handleChangedChunks() { if (!changedTicketChunks.isEmpty()) { Object2BooleanMap changed = changedTicketChunks; changedTicketChunks = new Object2BooleanOpenHashMap<>(); @@ -195,7 +182,7 @@ private void handleChangedChunks() { } } - private void removeInvalidTransmitters() { + private static void removeInvalidTransmitters() { if (!invalidTransmitters.isEmpty()) { //Ensure we copy the invalid transmitters, so that when we iterate and remove invalid ones // and add still valid ones as orphans, we actually add them as orphans rather than try @@ -211,7 +198,7 @@ private void removeInvalidTransmitters() { } } - private , TRANSMITTER extends Transmitter> + private static , TRANSMITTER extends Transmitter> void removeInvalidTransmitter(Transmitter invalid) { if (!invalid.isOrphan() || !invalid.isValid()) { NETWORK n = invalid.getTransmitterNetwork(); @@ -227,7 +214,7 @@ void removeInvalidTransmitter(Transmitter invalid) { } } - private void assignOrphans() { + private static void assignOrphans() { if (!newOrphanTransmitters.isEmpty()) { Map> orphanTransmitters = newOrphanTransmitters; newOrphanTransmitters = new Object2ObjectOpenHashMap<>(); @@ -244,7 +231,7 @@ private void assignOrphans() { } } - private void commitChanges() { + private static void commitChanges() { if (!networksToChange.isEmpty()) { Set> networks = networksToChange; networksToChange = new ObjectOpenHashSet<>(); @@ -259,7 +246,7 @@ public String toString() { return "Network Registry:\n" + networks; } - public Component[] toComponents() { + public static Component[] toComponents() { Component[] components = new Component[networks.size()]; int i = 0; for (DynamicNetwork network : networks) { @@ -351,4 +338,7 @@ private void iterate(Map> orphanTransmitters, Bl } } } + + private TransmitterNetworkRegistry() { + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/network/to_client/transmitter/PacketChemicalNetworkContents.java b/src/main/java/mekanism/common/network/to_client/transmitter/PacketChemicalNetworkContents.java index 791e5fb68d0..2beea6d0557 100644 --- a/src/main/java/mekanism/common/network/to_client/transmitter/PacketChemicalNetworkContents.java +++ b/src/main/java/mekanism/common/network/to_client/transmitter/PacketChemicalNetworkContents.java @@ -33,7 +33,7 @@ public CustomPacketPayload.Type type() { public void handle(IPayloadContext context) { //Note: We set the information even if opaque transmitters is true in case the client turns the config setting off // so that they will have the proper information to then render - DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getInstance().getClientNetwork(networkID); + DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getClientNetwork(networkID); if (clientNetwork instanceof ChemicalNetwork network) { network.setLastChemical(chemical); } diff --git a/src/main/java/mekanism/common/network/to_client/transmitter/PacketFluidNetworkContents.java b/src/main/java/mekanism/common/network/to_client/transmitter/PacketFluidNetworkContents.java index e59803f45a2..5a6cac000c6 100644 --- a/src/main/java/mekanism/common/network/to_client/transmitter/PacketFluidNetworkContents.java +++ b/src/main/java/mekanism/common/network/to_client/transmitter/PacketFluidNetworkContents.java @@ -33,7 +33,7 @@ public CustomPacketPayload.Type type() { public void handle(IPayloadContext context) { //Note: We set the information even if opaque transmitters is true in case the client turns the config setting off // so that they will have the proper information to then render - DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getInstance().getClientNetwork(networkID); + DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getClientNetwork(networkID); if (clientNetwork instanceof FluidNetwork network) { network.setLastFluid(fluid); } diff --git a/src/main/java/mekanism/common/network/to_client/transmitter/PacketNetworkScale.java b/src/main/java/mekanism/common/network/to_client/transmitter/PacketNetworkScale.java index 51698536741..63a8884ed8b 100644 --- a/src/main/java/mekanism/common/network/to_client/transmitter/PacketNetworkScale.java +++ b/src/main/java/mekanism/common/network/to_client/transmitter/PacketNetworkScale.java @@ -37,7 +37,7 @@ public CustomPacketPayload.Type type() { public void handle(IPayloadContext context) { //Note: We set the information even if opaque transmitters is true in case the client turns the config setting off // so that they will have the proper information to then render - DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getInstance().getClientNetwork(networkID); + DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getClientNetwork(networkID); if (clientNetwork instanceof DynamicBufferedNetwork network) { network.currentScale = scale; }