Skip to content

Commit

Permalink
NeoForge 1.20.2 Port
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Nov 17, 2023
1 parent cc2b8c7 commit d309d26
Show file tree
Hide file tree
Showing 55 changed files with 1,348 additions and 227 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ subprojects {
minecraft "com.mojang:minecraft:${rootProject.architectury.minecraft}"
mappings loom.officialMojangMappings()
}

repositories {
maven { url "https://maven.neoforged.net/releases/" }
}
}

allprojects {
Expand Down
4 changes: 3 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ dependencies {
}

architectury {
common(rootProject.platforms.split(","))
common(rootProject.platforms.split(",")) {
it.platformPackage "neoforge", "forge"
}
}

/**
Expand Down
15 changes: 15 additions & 0 deletions common/src/main/java/dev/architectury/platform/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,25 @@ public static boolean isFabric() {
return simpleLoaderCache == 0;
}

@Deprecated(forRemoval = true)
public static boolean isForge() {
return isForgeLike();
}

public static boolean isForgeLike() {
return isMinecraftForge() || isNeoForge();
}

public static boolean isMinecraftForge() {
updateLoaderCache();
return simpleLoaderCache == 1;
}

public static boolean isNeoForge() {
updateLoaderCache();
return simpleLoaderCache == 2;
}

private static void updateLoaderCache() {
if (simpleLoaderCache != -1) {
return;
Expand All @@ -54,6 +68,7 @@ private static void updateLoaderCache() {
switch (ArchitecturyTarget.getCurrentTarget()) {
case "fabric" -> simpleLoaderCache = 0;
case "forge" -> simpleLoaderCache = 1;
case "neoforge" -> simpleLoaderCache = 2;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package dev.architectury.utils;

public class ArchitecturyConstants {
public static final String MOD_ID = "architectury";
}
131 changes: 10 additions & 121 deletions forge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,109 +1,28 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "me.shedaniel.unified-publishing"
}

loom {
accessWidenerPath = project(":common").loom.accessWidenerPath

forge {
mixinConfig "architectury.mixins.json"
mixinConfig "architectury-common.mixins.json"

convertAccessWideners = true
extraAccessWideners.add loom.accessWidenerPath.get().asFile.name
}
}

architectury {
platformSetupLoomIde()
forge()
}

configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
forgeLike(["forge", "neoforge"]) {
it.platformPackage "neoforge", "forge"
it.remapForgeLike "net/minecraftforge/common/extensions/IForgeItem", "net/neoforged/neoforge/common/extensions/IItemExtension"
it.remapForgeLike "net/minecraftforge/client/event/TextureStitchEvent\$Post", "net/neoforged/neoforge/client/event/TextureAtlasStitchedEvent"
it.remapForgeLike "net/minecraftforge/fluids/ForgeFlowingFluid", "net/neoforged/neoforge/fluids/BaseFlowingFluid"
it.remapForgeLike "net/minecraftforge/fluids/ForgeFlowingFluid\$Properties", "net/neoforged/neoforge/fluids/BaseFlowingFluid\$Properties"
it.remapForgeLike "net/minecraftforge/common/ForgeHooks", "net/neoforged/neoforge/common/CommonHooks"
}
}

dependencies {
forge "net.minecraftforge:forge:${rootProject.architectury.minecraft}-${rootProject.forge_version}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive false }
}

processResources {
filesMatching("META-INF/mods.toml") {
expand "version": project.version
}
inputs.property "META-INF/mods.toml", project.version
}

shadowJar {
exclude "fabric.mod.json"
exclude "architectury-common.accessWidener"
exclude "architectury.common.json"

configurations = [project.configurations.shadowCommon]
archiveClassifier = "dev-shadow"

// Replace classes with forge's version
exclude "dev/architectury/core/block/ArchitecturyLiquidBlock.class"
exclude "dev/architectury/core/fluid/ArchitecturyFlowingFluid.class"
exclude 'dev/architectury/core/fluid/ArchitecturyFlowingFluid$Source.class'
exclude 'dev/architectury/core/fluid/ArchitecturyFlowingFluid$Flowing.class'
exclude 'dev/architectury/core/item/ArchitecturyBucketItem.class'
exclude 'dev/architectury/core/item/ArchitecturyMobBucketItem.class'
relocate "dev.architectury.core.block.forge.imitator", "dev.architectury.core.block"
relocate "dev.architectury.core.fluid.forge.imitator", "dev.architectury.core.fluid"
relocate "dev.architectury.core.item.forge.imitator", "dev.architectury.core.item"
}

remapJar {
input.set shadowJar.archiveFile
dependsOn shadowJar
archiveClassifier = null
}

task renameJarForPublication(type: Zip, dependsOn: remapJar) {
from remapJar.archiveFile.map { zipTree(it) }
archiveExtension = "jar"
metadataCharset "UTF-8"
destinationDirectory = base.libsDirectory
archiveClassifier = project.name
}

assemble.dependsOn renameJarForPublication

jar {
archiveClassifier = "dev"
}

sourcesJar {
afterEvaluate {
[":common"].forEach {
def depSources = project(it).sourcesJar
dependsOn depSources
from(depSources.archiveFile.map { zipTree(it) }) {
exclude "architectury.accessWidener"
}
}
}
}

components.java {
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
compileOnly(project(path: ":common", configuration: "namedElements")) { transitive false }
}

publishing {
publications {
mavenForge(MavenPublication) {
artifactId = rootProject.archivesBaseName + "-forge"
artifactId = rootProject.archivesBaseName + "-forge-like"
from components.java
}
}
Expand All @@ -120,33 +39,3 @@ publishing {
}
}
}

unifiedPublishing {
project {
displayName = "[MinecraftForge $rootProject.supported_version] v$project.version"
releaseType = "$rootProject.artifact_type"
changelog = releaseChangelog()
gameVersions = ["1.20.2"]
gameLoaders = ["forge"]
mainPublication renameJarForPublication

var CURSE_API_KEY = project.findProperty("CURSE_API_KEY") ?: System.getenv("CURSE_API_KEY")
if (CURSE_API_KEY != null) {
curseforge {
token = CURSE_API_KEY
id = rootProject.curseforge_id
gameVersions.addAll "Java 17"
}
}

var MODRINTH_TOKEN = project.findProperty("MODRINTH_TOKEN") ?: System.getenv("MODRINTH_TOKEN")
if (MODRINTH_TOKEN != null) {
modrinth {
token = MODRINTH_TOKEN
id = rootProject.modrinth_id
version = "$project.version+$project.name"
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package dev.architectury.event.forge;

import dev.architectury.forge.ArchitecturyForge;
import dev.architectury.platform.forge.EventBuses;
import dev.architectury.platform.hooks.EventBusesHooks;
import dev.architectury.utils.ArchitecturyConstants;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -29,23 +29,23 @@ public class EventHandlerImpl {
@OnlyIn(Dist.CLIENT)
public static void registerClient() {
MinecraftForge.EVENT_BUS.register(EventHandlerImplClient.class);
EventBuses.onRegistered(ArchitecturyForge.MOD_ID, bus -> {
EventBusesHooks.whenAvailable(ArchitecturyConstants.MOD_ID, bus -> {
bus.register(EventHandlerImplClient.ModBasedEventHandler.class);
});
}

public static void registerCommon() {
MinecraftForge.EVENT_BUS.register(EventHandlerImplCommon.class);
EventBuses.onRegistered(ArchitecturyForge.MOD_ID, bus -> {
EventBusesHooks.whenAvailable(ArchitecturyConstants.MOD_ID, bus -> {
bus.register(EventHandlerImplCommon.ModBasedEventHandler.class);
});
}

@OnlyIn(Dist.DEDICATED_SERVER)
public static void registerServer() {
MinecraftForge.EVENT_BUS.register(EventHandlerImplServer.class);
EventBuses.onRegistered(ArchitecturyForge.MOD_ID, bus -> {
bus.register(EventHandlerImplServer.ModBasedEventHandler.class);
});
// MinecraftForge.EVENT_BUS.register(EventHandlerImplServer.class);
// EventBusesHooks.whenAvailable(ArchitecturyConstants.MOD_ID, bus -> {
// bus.register(EventHandlerImplServer.ModBasedEventHandler.class);
// });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import dev.architectury.impl.ScreenAccessImpl;
import dev.architectury.impl.TooltipEventColorContextImpl;
import dev.architectury.impl.TooltipEventPositionContextImpl;
import dev.architectury.platform.Platform;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
Expand All @@ -42,6 +43,8 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;

import java.lang.reflect.InvocationTargetException;

@OnlyIn(Dist.CLIENT)
public class EventHandlerImplClient {
@SubscribeEvent(priority = EventPriority.HIGH)
Expand Down Expand Up @@ -217,14 +220,40 @@ public static void eventRenderTooltipEvent(RenderTooltipEvent.Color event) {

@SubscribeEvent(priority = EventPriority.HIGH)
public static void eventMouseScrollEvent(ScreenEvent.MouseScrolled.Pre event) {
if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getDeltaX(), event.getDeltaY()).isFalse()) {
double deltaX, deltaY;
if (Platform.isNeoForge()) {
try {
deltaX = (double) event.getClass().getMethod("getScrollDeltaX").invoke(event);
deltaY = (double) event.getClass().getMethod("getScrollDeltaY").invoke(event);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
} else {
deltaX = event.getDeltaX();
deltaY = event.getDeltaY();
}

if (ClientScreenInputEvent.MOUSE_SCROLLED_PRE.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), deltaX, deltaY).isFalse()) {
event.setCanceled(true);
}
}

@SubscribeEvent(priority = EventPriority.HIGH)
public static void eventMouseScrollEvent(ScreenEvent.MouseScrolled.Post event) {
ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), event.getDeltaX(), event.getDeltaY());
double deltaX, deltaY;
if (Platform.isNeoForge()) {
try {
deltaX = (double) event.getClass().getMethod("getScrollDeltaX").invoke(event);
deltaY = (double) event.getClass().getMethod("getScrollDeltaY").invoke(event);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
} else {
deltaX = event.getDeltaX();
deltaY = event.getDeltaY();
}

ClientScreenInputEvent.MOUSE_SCROLLED_POST.invoker().mouseScrolled(Minecraft.getInstance(), event.getScreen(), event.getMouseX(), event.getMouseY(), deltaX, deltaY);
}

@SubscribeEvent(priority = EventPriority.HIGH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,30 @@ final class LootTableModificationContextImpl implements LootEvent.LootTableModif
throw new RuntimeException(e);
}
} catch (NoSuchFieldException ignored2) {
for (Field field : LootTable.class.getDeclaredFields()) {
if (field.getType().equals(List.class)) {
// This is probably the field
field.setAccessible(true);
try {
pools = (List<LootPool>) field.get(table);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
try {
Field field = LootTable.class.getDeclaredField("pools");
field.setAccessible(true);
try {
pools = (List<LootPool>) field.get(table);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
} catch (NoSuchFieldException ignored3) {
for (Field field : LootTable.class.getDeclaredFields()) {
if (field.getType().equals(List.class)) {
// This is probably the field
field.setAccessible(true);
try {
pools = (List<LootPool>) field.get(table);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}

if (pools == null) {
throw new RuntimeException("Unable to find pools field in LootTable!");
if (pools == null) {
throw new RuntimeException("Unable to find pools field in LootTable!");
}
}
}
}
Expand Down
Loading

0 comments on commit d309d26

Please sign in to comment.