Skip to content

Commit

Permalink
Updated to forge .98
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Aug 1, 2020
1 parent e73bbfb commit c290812
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ repositories {
}
}
dependencies {
minecraft 'net.minecraftforge:forge:1.16.1-32.0.70'
minecraft 'net.minecraftforge:forge:1.16.1-32.0.98'

compileOnly fg.deobf("mezz.jei:jei-1.16.1:7.0.0.2:api")
// at runtime, use the full JEI jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.GenericEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

Expand All @@ -19,7 +20,6 @@

public class EventManager {


public static <T extends Event> FilteredEventManager<T> forge(Class<T> clazz) {
return create(clazz, EventPriority.NORMAL, Bus.FORGE);
}
Expand Down Expand Up @@ -59,7 +59,37 @@ public IEventBus bus() {
}
}

public static class FilteredEventManager<T extends Event> {
public static <T extends GenericEvent<? extends F>, F> GenericEventManager<T, F> forgeGeneric(Class<T> clazz, Class<F> generic) {
return createGeneric(clazz, EventPriority.NORMAL, Bus.FORGE, generic);
}

public static <T extends GenericEvent<? extends F>, F> GenericEventManager<T, F> modGeneric(Class<T> clazz, Class<F> generic) {
return createGeneric(clazz, EventPriority.NORMAL, Bus.MOD, generic);
}

public static <T extends GenericEvent<? extends F>, F> GenericEventManager<T, F> modGeneric(Class<T> clazz, EventPriority priority, Class<F> generic) {
return createGeneric(clazz, priority, Bus.MOD, generic);
}

public static <T extends GenericEvent<? extends F>, F> GenericEventManager<T, F> forgeGeneric(Class<T> clazz, EventPriority priority, Class<F> generic) {
return createGeneric(clazz, priority, Bus.FORGE, generic);
}

public static <T extends GenericEvent<? extends F>, F> GenericEventManager<T, F> createGeneric(Class<T> clazz, Bus bus, Class<F> generic) {
return createGeneric(clazz, EventPriority.NORMAL, bus, generic);
}

public static <T extends GenericEvent<? extends F>, F> GenericEventManager<T, F> createGeneric(Class<T> clazz, EventPriority priority, Bus bus, Class<F> generic) {
return new GenericEventManager<>(clazz, bus, priority, generic);
}

public static interface ISubscribe {

void subscribe();

}

public static class FilteredEventManager<T extends Event> implements ISubscribe {
private Predicate<T> filter;
private Consumer<T> process;
private Class<T> event;
Expand Down Expand Up @@ -106,4 +136,54 @@ public FilteredEventManager<T> cancel() {
return this;
}
}

public static class GenericEventManager<T extends GenericEvent<? extends F>, F> implements ISubscribe {
private Predicate<T> filter;
private Consumer<T> process;
private Class<T> event;
private boolean cancel;
private Bus bus;
private EventPriority priority;
private Class<F> generic;

public GenericEventManager(Class<T> clazz, Bus bus, EventPriority priority, Class<F> generic) {
this.event = clazz;
this.filter = t -> true;
this.process = t -> {
};
this.bus = bus;
this.priority = priority;
this.generic = generic;
}

public void subscribe() {
bus.bus().addGenericListener(this.generic, priority, false, this.event, event -> {
if (event.getClass().isAssignableFrom(this.event)) {
if (this.filter.test(event)) {
if (this.cancel) {
if (event.isCancelable()) {
event.setCanceled(true);
}
}
this.process.accept(event);
}
}
});
}

public GenericEventManager<T, F> filter(Predicate<T> predicateFilter) {
this.filter = this.filter.and(predicateFilter);
return this;
}

public GenericEventManager<T, F> process(Consumer<T> process) {
this.process = this.process.andThen(process);
return this;
}

public GenericEventManager<T, F> cancel() {
this.cancel = true;
return this;
}
}
}
18 changes: 11 additions & 7 deletions src/main/java/com/hrznstudio/titanium/module/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
public class Feature {
private final String id;
private final Map<Class<? extends IForgeRegistryEntry<?>>, List<?>> content;
private final List<EventManager.FilteredEventManager<?>> events;
private final List<EventManager.ISubscribe> events;
private final boolean forced;
private final boolean enabledByDefault;
private final String description;
private Module module;

private Feature(String id, Map<Class<? extends IForgeRegistryEntry<?>>, List<?>> content,
List<EventManager.FilteredEventManager<?>> events, boolean forced, boolean enabledByDefault,
List<EventManager.ISubscribe> events, boolean forced, boolean enabledByDefault,
String description) {
this.id = id;
this.content = content;
Expand Down Expand Up @@ -62,6 +62,10 @@ Feature setModule(Module module) {
return this;
}

public Map<Class<? extends IForgeRegistryEntry<?>>, List<?>> getContent() {
return content;
}

public boolean isForced() {
return forced;
}
Expand All @@ -75,7 +79,7 @@ protected void initConfig(String prefix, CommentedFileConfig config) {
}

public void initEvents() {
events.forEach(EventManager.FilteredEventManager::subscribe);
events.forEach(EventManager.ISubscribe::subscribe);
}

public <T extends IForgeRegistryEntry<T>> List<? extends T> getEntries(Class<T> tClass) {
Expand All @@ -85,7 +89,7 @@ public <T extends IForgeRegistryEntry<T>> List<? extends T> getEntries(Class<T>
public final static class Builder implements RegistryManager<Builder> {
private final String id;
private final Map<Class<? extends IForgeRegistryEntry<?>>, List<?>> content = new LinkedHashMap<>();
private final List<EventManager.FilteredEventManager<?>> events = new LinkedList<>();
private final List<EventManager.ISubscribe> events = new LinkedList<>();
private boolean forced;
private boolean enabledByDefault = true;
private String description;
Expand All @@ -101,12 +105,12 @@ public <T extends IForgeRegistryEntry<T>> Builder content(Class<T> tClass, T t)
return this;
}

public Builder event(EventManager.FilteredEventManager<?> manager) {
public Builder event(EventManager.ISubscribe manager) {
events.add(manager);
return this;
}

public Builder eventClient(Supplier<Supplier<EventManager.FilteredEventManager<?>>> managerSupplier) {
public Builder eventClient(Supplier<Supplier<EventManager.ISubscribe>> managerSupplier) {
SidedHandler.runOn(Dist.CLIENT, () -> () -> events.add(managerSupplier.get().get()));
return this;
}
Expand Down Expand Up @@ -134,4 +138,4 @@ public Feature build() {
return new Feature(id, content, events, forced, enabledByDefault, description);
}
}
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/hrznstudio/titanium/module/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public <T extends IForgeRegistryEntry<T>> List<T> getEntries(Class<T> tClass) {
return l;
}

public Map<String, Feature> getFeatureMap() {
return featureMap;
}

public boolean isForced() {
return forced;
}
Expand Down Expand Up @@ -130,4 +134,4 @@ Module build() {
}
}

}
}
20 changes: 11 additions & 9 deletions src/main/java/com/hrznstudio/titanium/module/ModuleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraftforge.registries.IForgeRegistryEntry;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -96,14 +97,15 @@ public void onInit() {
config.save();
config.close();
}

EventManager.mod(RegistryEvent.Register.class).process(event -> {
moduleMap.values().forEach(m -> {
List<? extends IForgeRegistryEntry<?>> l = m.getEntries((Class) event.getGenericType());
if (!l.isEmpty())
l.forEach(event.getRegistry()::register);
});
}).subscribe();
moduleMap.values().stream().map(module -> module.getFeatureMap().values()).flatMap(Collection::stream).map(feature -> feature.getContent().keySet()).flatMap(Collection::stream).distinct().forEach(aClass -> {
EventManager.modGeneric(RegistryEvent.Register.class, aClass).process(register -> {
moduleMap.values().forEach(m -> {
List<? extends IForgeRegistryEntry<?>> l = m.getEntries((Class) aClass);
if (!l.isEmpty())
l.forEach(((RegistryEvent.Register) register).getRegistry()::register);
});
}).subscribe();
});
this.modPluginManager.execute(PluginPhase.INIT);
}

Expand Down Expand Up @@ -139,4 +141,4 @@ public void addModule(Module.Builder builder) {
public void addDataProvider(GatherDataEvent event) {

}
}
}
24 changes: 15 additions & 9 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
modLoader = "javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the minecraft version (without the 1.)
loaderVersion="[28,)" #mandatory
loaderVersion = "[32,)" #mandatory
license = "GNU LESSER GENERAL PUBLIC LICENSE"
# A URL to refer people to when problems occur with this mod

# A URL for the "homepage" for this mod, displayed in the mod UI

# A text field displayed in the mod UI
authors="TheCodedOne, Buuz135" #optional
authors = "TheCodedOne, Buuz135" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="titanium" #mandatory
modId = "titanium" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="Titanium" #mandatory
version = "${file.jarVersion}" #mandatory
# A display name for the mod
displayName = "Titanium" #mandatory
# The description text for the mod (multi line!) (#mandatory)
description='''
description = '''
A Lib
'''

[[dependencies.titanium]] #optional
modId = "forge" #mandatory
mandatory = true #mandatory
versionRange = "[32.0.98,)" #mandatory
ordering = "NONE"
side = "BOTH"

0 comments on commit c290812

Please sign in to comment.