Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 98210b8

Browse files
committed
use fabric api lookup for ModList + checkstyle fixes
1 parent c00b7c6 commit 98210b8

5 files changed

Lines changed: 24 additions & 33 deletions

File tree

patchwork-dispatcher/src/main/java/com/patchworkmc/impl/Patchwork.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import net.minecraftforge.event.RegistryEvent;
2929
import net.minecraftforge.eventbus.api.Event;
3030
import net.minecraftforge.fml.ModContainer;
31-
import net.minecraftforge.fml.ModList;
3231
import net.minecraftforge.fml.ModLoadingContext;
3332
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
3433
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
@@ -118,10 +117,7 @@ public void onInitialize() {
118117
modIds.add(initializer.getModId());
119118
}
120119

121-
// Init ModList
122-
ModList.create(modIds);
123120
// Send initialization events
124-
125121
dispatchRegistryEvents(mods);
126122
// TODO: One per modcontainer
127123
dispatch(mods, new FMLCommonSetupEvent(new ModContainer("minecraft")));

patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/event/lifecycle/InterModEnqueueEvent.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
/**
2525
* This is the third of four commonly called events during mod lifecycle startup.
2626
*
27-
* Called before {@link InterModProcessEvent}
28-
* Called after {@link FMLClientSetupEvent} or {@link FMLDedicatedServerSetupEvent}
27+
* <p>Called before {@link InterModProcessEvent}
2928
*
29+
* <p></p>Called after {@link FMLClientSetupEvent} or {@link FMLDedicatedServerSetupEvent}
3030
*
31-
* Enqueue {@link net.minecraftforge.fml.InterModComms} messages to other mods with this event.
31+
* <p>Enqueue {@link net.minecraftforge.fml.InterModComms} messages to other mods with this event.
3232
*
33-
* This is a parallel dispatch event.
33+
* <p>This is a parallel dispatch event.
3434
*/
3535
public class InterModEnqueueEvent extends ModLifecycleEvent {
3636
// For EventBus

patchwork-events-lifecycle/src/main/java/net/minecraftforge/fml/event/lifecycle/InterModProcessEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
/**
2727
* This is the fourth of four commonly called events during mod lifecycle startup.
2828
*
29-
* Called after {@link InterModEnqueueEvent}
29+
* <p>Called after {@link InterModEnqueueEvent}
3030
*
31-
* Retrieve {@link net.minecraftforge.fml.InterModComms} {@link net.minecraftforge.fml.InterModComms.IMCMessage} suppliers
31+
* <p>Retrieve {@link net.minecraftforge.fml.InterModComms} {@link net.minecraftforge.fml.InterModComms.IMCMessage} suppliers
3232
* and process them as you wish with this event.
3333
*
34-
* This is a parallel dispatch event.
34+
* <p>This is a parallel dispatch event.
3535
*
3636
* @see #getIMCStream()
3737
* @see #getIMCStream(Predicate)

patchwork-fml/src/main/java/net/minecraftforge/fml/InterModComms.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ public static final class IMCMessage {
4848
* @return The modid of the sender. This is supplied by the caller, or by the active mod container context.
4949
* Consider it unreliable.
5050
*/
51-
public final String getSenderModId() {
51+
public String getSenderModId() {
5252
return this.senderModId;
5353
}
5454

5555
/**
5656
* @return The modid being sent to.
5757
*/
58-
public final String getModId() {
58+
public String getModId() {
5959
return this.modId;
6060
}
6161

6262
/**
6363
* @return The method being sent to.
6464
*/
65-
public final String getMethod() {
65+
public String getMethod() {
6666
return this.method;
6767
}
6868

@@ -71,7 +71,7 @@ public final String getMethod() {
7171
* @return A {@link Supplier} of the message.
7272
*/
7373
@SuppressWarnings("unchecked")
74-
public final <T> Supplier<T> getMessageSupplier() {
74+
public <T> Supplier<T> getMessageSupplier() {
7575
return (Supplier<T>) this.thing;
7676
}
7777
}
@@ -90,6 +90,7 @@ public static boolean sendTo(final String modId, final String method, final Supp
9090
if (!ModList.get().isLoaded(modId)) {
9191
return false;
9292
}
93+
9394
containerQueues.computeIfAbsent(modId, k -> new ConcurrentLinkedQueue<>()).add(new IMCMessage(ModLoadingContext.get().getActiveContainer().getModId(), modId, method, thing));
9495
return true;
9596
}
@@ -107,6 +108,7 @@ public static boolean sendTo(final String senderModId, final String modId, final
107108
if (!ModList.get().isLoaded(modId)) {
108109
return false;
109110
}
111+
110112
containerQueues.computeIfAbsent(modId, k -> new ConcurrentLinkedQueue<>()).add(new IMCMessage(senderModId, modId, method, thing));
111113
return true;
112114
}
@@ -120,9 +122,11 @@ public static boolean sendTo(final String senderModId, final String modId, final
120122
*/
121123
public static Stream<IMCMessage> getMessages(final String modId, final Predicate<String> methodMatcher) {
122124
ConcurrentLinkedQueue<IMCMessage> queue = containerQueues.get(modId);
125+
123126
if (queue == null) {
124127
return Stream.empty();
125128
}
129+
126130
return StreamSupport.stream(new QueueFilteringSpliterator(queue, methodMatcher), false);
127131
}
128132

@@ -141,7 +145,7 @@ private static class QueueFilteringSpliterator implements Spliterator<IMCMessage
141145
private final Predicate<String> methodFilter;
142146
private final Iterator<IMCMessage> iterator;
143147

144-
public QueueFilteringSpliterator(final ConcurrentLinkedQueue<IMCMessage> queue, final Predicate<String> methodFilter) {
148+
private QueueFilteringSpliterator(final ConcurrentLinkedQueue<IMCMessage> queue, final Predicate<String> methodFilter) {
145149
this.queue = queue;
146150
this.iterator = queue.iterator();
147151
this.methodFilter = methodFilter;
@@ -160,13 +164,17 @@ public long estimateSize() {
160164
@Override
161165
public boolean tryAdvance(final Consumer<? super IMCMessage> action) {
162166
IMCMessage next;
167+
163168
do {
164169
if (!iterator.hasNext()) {
165170
return false;
166171
}
172+
167173
next = this.iterator.next();
168174
}
175+
169176
while (!methodFilter.test(next.method));
177+
170178
action.accept(next);
171179
this.iterator.remove();
172180
return true;
@@ -176,6 +184,5 @@ public boolean tryAdvance(final Consumer<? super IMCMessage> action) {
176184
public Spliterator<IMCMessage> trySplit() {
177185
return null;
178186
}
179-
180187
}
181188
}

patchwork-fml/src/main/java/net/minecraftforge/fml/ModList.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,17 @@
1919

2020
package net.minecraftforge.fml;
2121

22-
import java.util.List;
22+
import net.fabricmc.loader.FabricLoader;
2323

2424
public class ModList {
25-
private static ModList INSTANCE;
26-
private List<String> mods;
27-
28-
//Patchwork: signature changed to just have a list of modids
29-
private ModList(List<String> mods) {
30-
this.mods = mods;
31-
}
25+
//Patchwork: initalize directly because there's no args
26+
private static ModList INSTANCE = new ModList();
3227

3328
public static ModList get() {
3429
return INSTANCE;
3530
}
3631

37-
//Patchwork: method does not exist in Forge
38-
public static ModList create(List<String> mods) {
39-
INSTANCE = new ModList(mods);
40-
return INSTANCE;
41-
}
42-
4332
public boolean isLoaded(String modId) {
44-
return this.mods.contains(modId);
33+
return FabricLoader.INSTANCE.isModLoaded(modId);
4534
}
46-
4735
}

0 commit comments

Comments
 (0)