Skip to content

Commit

Permalink
Fix crash with latest FAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed May 1, 2021
1 parent 99c5126 commit d697aed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,9 @@ dependencies {
include fabricApi.module("fabric-api-base", fabric_api_version)
include fabricApi.module("fabric-networking-v0", fabric_api_version)

afterEvaluate {
subprojects.each {
compile project(path: ":${it.name}", configuration: "dev")
include project(":${it.name}")
}
subprojects.each {
compile project(path: ":${it.name}", configuration: "dev")
include project(":${it.name}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
public final class ComponentsInternals {
public static final Logger LOGGER = LogManager.getLogger("Cardinal Components API");

private static final Field EVENT$TYPE;
private static final Field EVENT$HANDLERS;
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final Map<Event<? extends ComponentCallback<?, ?>>, MethodHandle> FACTORY_CACHE = new HashMap<>();
private static final MethodHandle IMPL_HANDLE;

static {
try {
EVENT$TYPE = Class.forName("net.fabricmc.fabric.impl.base.event.ArrayBackedEvent").getDeclaredField("type");
EVENT$TYPE.setAccessible(true);
EVENT$HANDLERS = Class.forName("net.fabricmc.fabric.impl.base.event.ArrayBackedEvent").getDeclaredField("handlers");
EVENT$HANDLERS.setAccessible(true);
IMPL_HANDLE = LOOKUP.findStatic(ComponentsInternals.class, "initComponents", MethodType.methodType(void.class, ComponentType.class, Function.class, Object.class, ComponentContainer.class));
} catch (NoSuchFieldException | ClassNotFoundException e) {
throw new RuntimeException("Failed to hack fabric API", e);
Expand All @@ -75,7 +75,7 @@ private static <T extends Component, P, C extends T> void initComponents(Compone
@SuppressWarnings("unchecked")
private static MethodHandle createCallbackFactory(Event<?> event) {
try {
Class<? extends ComponentCallback<?, ?>> eventType = (Class<? extends ComponentCallback<?, ?>>) EVENT$TYPE.get(event);
Class<? extends ComponentCallback<?, ?>> eventType = (Class<? extends ComponentCallback<?, ?>>) EVENT$HANDLERS.get(event).getClass().getComponentType();
MethodType eventSamType = findSam(eventType);
return LambdaMetafactory.metafactory(
LOOKUP,
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------
Version 2.8.1
------------------------------------------------------
Fixes
- Fixed a crash at launch with Fabric API 0.34.0 and up (1.17 versions are unaffected)

------------------------------------------------------
Version 2.8.0
------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ yarn_mappings=5
loader_version=0.10.6+build.214

#Fabric api
fabric_api_version=0.32.5+1.16
fabric_api_version=0.34.0+1.16

#Publishing
mod_version = 2.8.0
mod_version = 2.8.1
curseforge_id = 318449
curseforge_versions = 1.16.2; 1.16.3; 1.16.4; 1.16.5
changelog_url = https://github.com/OnyxStudios/Cardinal-Components-API/blob/master/changelog.md
Expand Down

0 comments on commit d697aed

Please sign in to comment.