Skip to content

Commit

Permalink
Update to forge 48.0.40
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Nov 19, 2023
1 parent 14c59f6 commit 2f10bd4
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 87 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ A Bukkit server implementation utilizing Mixin.

![Downloads](https://img.shields.io/github/downloads/IzzelAliz/Arclight/total?style=flat-square) ![GitHub](https://img.shields.io/github/license/IzzelAliz/Arclight?style=flat-square)

| Release | Forge | Status | Build |
|:--------------------:|:------:|:------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Net (1.20.2) | 48.0.4 | ACTIVE | [![1.20.2 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Net&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ANet) |
| Trials (1.20-1.20.1) | 47.2.0 | LTS | [![1.20.1 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Trials&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ATrials) |
| Horn (1.19-1.19.2) | 43.3.2 | LTS | [![Horn Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-19?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-19) |
| Release | Forge | Status | Build |
|:--------------------:|:-------:|:------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Net (1.20.2) | 48.0.40 | ACTIVE | [![1.20.2 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Net&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ANet) |
| Trials (1.20-1.20.1) | 47.2.0 | LTS | [![1.20.1 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Trials&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ATrials) |
| Horn (1.19-1.19.2) | 43.3.2 | LTS | [![Horn Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-19?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-19) |

**Legacy versions**:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.izzel.arclight.common.mixin.bukkit;

import io.izzel.arclight.common.mod.server.entity.ArclightFakePlayer;
import io.izzel.arclight.common.mod.server.entity.ArclightModChestedHorse;
import io.izzel.arclight.common.mod.server.entity.ArclightModEntity;
import io.izzel.arclight.common.mod.server.entity.ArclightModHorse;
Expand All @@ -22,7 +21,6 @@
import net.minecraft.world.entity.raid.Raider;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.AbstractMinecartContainer;
import net.minecraftforge.common.util.FakePlayer;
import org.bukkit.craftbukkit.v.CraftServer;
import org.bukkit.craftbukkit.v.entity.CraftAgeable;
import org.bukkit.craftbukkit.v.entity.CraftEntity;
Expand All @@ -43,12 +41,12 @@ public abstract class CraftEntityMixin implements org.bukkit.entity.Entity {
@Shadow protected Entity entity;
@Shadow @Final protected CraftServer server;

@Inject(method = "getEntity", cancellable = true, at = @At("HEAD"))
private static void arclight$fakePlayer(CraftServer server, Entity entity, CallbackInfoReturnable<CraftEntity> cir) {
if (entity instanceof FakePlayer) {
cir.setReturnValue(new ArclightFakePlayer(server, (FakePlayer) entity));
}
}
// @Inject(method = "getEntity", cancellable = true, at = @At("HEAD"))
// private static void arclight$fakePlayer(CraftServer server, Entity entity, CallbackInfoReturnable<CraftEntity> cir) {
// if (entity instanceof FakePlayer) {
// cir.setReturnValue(new ArclightFakePlayer(server, (FakePlayer) entity));
// }
// }

@Inject(method = "getEntity", cancellable = true, at = @At(value = "NEW", target = "java/lang/AssertionError"))
private static void arclight$modEntity(CraftServer server, Entity entity, CallbackInfoReturnable<CraftEntity> cir) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ public ServerPlayer respawn(ServerPlayer entityplayer, boolean flag, PlayerRespa
}

public ServerPlayer respawn(ServerPlayer playerIn, ServerLevel worldIn, boolean flag, Location location, boolean avoidSuffocation, PlayerRespawnEvent.RespawnReason respawnReason) {
if (respawnReason == null && location != null) {
if (ForgeEventFactory.onTravelToDimension((ServerPlayer) (Object) this, worldIn.dimension())) {
return null;
}
}
playerIn.stopRiding();
this.players.remove(playerIn);
playerIn.serverLevel().removePlayerImmediately(playerIn, Entity.RemovalReason.DISCARDED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double
@Overwrite(remap = false)
@Nullable
public Entity changeDimension(ServerLevel server, net.minecraftforge.common.util.ITeleporter teleporter) {
if (!ForgeEventFactory.onTravelToDimension((Entity) (Object) this, server.dimension()))
if (ForgeEventFactory.onTravelToDimension((Entity) (Object) this, server.dimension()))
return null;
if (this.level() instanceof ServerLevel && !this.isRemoved()) {
this.level().getProfiler().push("changeDimension");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public Entity changeDimension(ServerLevel server, ITeleporter teleporter) {
if (this.isSleeping()) {
return (ServerPlayer) (Object) this;
}
if (!ForgeEventFactory.onTravelToDimension((ServerPlayer) (Object) this, server.dimension())) return null;
if (ForgeEventFactory.onTravelToDimension((ServerPlayer) (Object) this, server.dimension())) return null;

PlayerTeleportEvent.TeleportCause cause = arclight$cause == null ? PlayerTeleportEvent.TeleportCause.UNKNOWN : arclight$cause;
arclight$cause = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, In
if (playerIn.fishing != null) {
if (!worldIn.isClientSide) {
int i = playerIn.fishing.retrieve(itemstack);
ItemStack original = itemstack.copy();
itemstack.hurtAndBreak(i, playerIn, (player) -> {
player.broadcastBreakEvent(handIn);
});
if(itemstack.isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(playerIn, original, handIn);
}
}

playerIn.swing(handIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@
import org.bukkit.event.server.MapInitializeEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import org.spongepowered.asm.mixin.Shadow;

import javax.annotation.Nullable;

@Mixin(MapItem.class)
public abstract class MapItemMixin {

@Inject(method = "createNewSavedData", locals = LocalCapture.CAPTURE_FAILHARD, at = @At("RETURN"))
private static void arclight$mapInit(Level p_151121_, int p_151122_, int p_151123_, int p_151124_, boolean p_151125_, boolean p_151126_, ResourceKey<Level> p_151127_, CallbackInfoReturnable<Integer> cir, MapItemSavedData mapData) {
MapInitializeEvent event = new MapInitializeEvent(((MapDataBridge) mapData).bridge$getMapView());
// @formatter:off
@Shadow public static String makeKey(int p_42849_) { return null; }
// @formatter:on

/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static int createNewSavedData(Level p_151121_, int p_151122_, int p_151123_, int p_151124_, boolean p_151125_, boolean p_151126_, ResourceKey<Level> p_151127_) {
MapItemSavedData mapitemsaveddata = MapItemSavedData.createFresh((double) p_151122_, (double) p_151123_, (byte) p_151124_, p_151125_, p_151126_, p_151127_);
MapInitializeEvent event = new MapInitializeEvent(((MapDataBridge) mapitemsaveddata).bridge$getMapView());
Bukkit.getPluginManager().callEvent(event);
int i = p_151121_.getFreeMapId();
p_151121_.setMapData(makeKey(i), mapitemsaveddata);
return i;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void apply(Map<ResourceLocation, JsonElement> objectIn, ResourceManage
continue; //Forge: filter anything beginning with "_" as it's used for metadata.

try {
if (entry.getValue().isJsonObject() && !CraftingHelper.processConditions(entry.getValue().getAsJsonObject(), "conditions", this.context)) {
if (entry.getValue().isJsonObject() && !net.minecraftforge.common.ForgeHooks.readAndTestCondition(this.context, entry.getValue().getAsJsonObject())) {
LOGGER.debug("Skipping loading recipe {} as it's conditions were not met", resourcelocation);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"CraftLegacyUtilMixin",
"CraftMetaItemMixin",
"CraftPlayerMixin",
"CraftPotionUtilMixin",
"CraftRecipeMixin",
"CraftRegionAccessorMixin",
"CraftSchedulerMixin",
Expand Down
6 changes: 3 additions & 3 deletions arclight-forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ dependencies {
implementation 'com.google.guava:guava:31.1-jre'
implementation 'org.ow2.asm:asm:9.5'
implementation 'org.ow2.asm:asm-tree:9.5'
implementation 'cpw.mods:modlauncher:9.0.24'
implementation 'cpw.mods:securejarhandler:2.1.4'
implementation 'net.minecraftforge:forgespi:6.0.0'
implementation 'net.minecraftforge:modlauncher:10.1.1'
implementation 'net.minecraftforge:securemodules:2.2.3'
implementation 'net.minecraftforge:forgespi:7.1.0'
gson 'com.google.code.gson:gson:2.9.0'
implementation 'org.apache.logging.log4j:log4j-api:2.17.2'
implementation 'org.apache.logging.log4j:log4j-core:2.17.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void accept(String[] args) {
this.dirtyHacks();
int targetIndex = Arrays.asList(args).indexOf("--launchTarget");
if (targetIndex >= 0 && targetIndex < args.length - 1) {
args[targetIndex + 1] = "arclightserver";
args[targetIndex + 1] = "arclight_server";
}
ServiceLoader.load(getClass().getModule().getLayer(), Consumer.class).stream()
.filter(it -> !it.type().getName().contains("arclight"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,87 @@
package io.izzel.arclight.boot.application;

import net.minecraftforge.fml.loading.targets.ForgeServerLaunchHandler;
import cpw.mods.jarhandling.SecureJar;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.LibraryFinder;
import net.minecraftforge.fml.loading.VersionInfo;
import net.minecraftforge.fml.loading.targets.CommonLaunchHandler;

public class ArclightLaunchHandler extends ForgeServerLaunchHandler {
import java.nio.file.Path;
import java.util.List;
import java.util.function.BiPredicate;

// duplicate of ForgeProdLaunchHandler, change on update
public class ArclightLaunchHandler extends CommonLaunchHandler {

public ArclightLaunchHandler() {
super(SERVER, "arclight_");
}

@Override
public String getNaming() {
return "srg";
}

@Override
public String name() {
return "arclightserver";
public boolean isProduction() {
return true;
}

protected Path mvn(VersionInfo info, String artifact) {
return mvn(info, artifact, "");
}

protected Path mvn(VersionInfo info, String artifact, String classifier) {
return mvn(info.forgeGroup(), artifact, classifier, info.mcAndForgeVersion());
}

protected Path mvn(String group, String artifact, String classifier, String version) {
return LibraryFinder.findPathForMaven(group, artifact, "", classifier, version);
}

@Override
public CommonLaunchHandler.LocatedPaths getMinecraftPaths() {
var vers = FMLLoader.versionInfo();

// Minecraft
var mc = getMCPaths(vers);

// mods (Forge)
var forgejar = mvn(vers, "forge", "universal");

// Libraries
var fmlcore = mvn(vers, "fmlcore");
var javafmllang = mvn(vers, "javafmllanguage");
var lowcodelang = mvn(vers, "lowcodelanguage");
var mclang = mvn(vers, "mclanguage");

return new CommonLaunchHandler.LocatedPaths(
mc,
null,
List.of(List.of(forgejar)),
List.of(fmlcore, javafmllang, lowcodelang, mclang)
);
}

@Override
protected String[] preLaunch(String[] arguments, ModuleLayer layer) {
// skip the log4j configuration reloading
return arguments;
}

protected List<Path> getMCPaths(VersionInfo vers) {
var mc = mvn("net.minecraft", "server", "srg", vers.mcAndMCPVersion());
var mcextra = mvn("net.minecraft", "server", "extra", vers.mcAndMCPVersion());
var patches = mvn(vers, "forge", "server");

// TODO: Get rid of this by filtering the file at install time.
// We only want it for it's resources. So filter everything else out.
BiPredicate<String, String> filter = (path, base) -> {
return path.equals("META-INF/versions/") || // This is required because it bypasses our filter for the manifest, and it's a multi-release jar.
(!path.endsWith(".class") && !path.startsWith("META-INF/"));
};
mcextra = SecureJar.from(filter, mcextra).getRootPath();

return List.of(mc, mcextra, patches);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.izzel.arclight.boot.mod;

import cpw.mods.cl.JarModuleFinder;
import cpw.mods.cl.ModuleClassLoader;
import cpw.mods.jarhandling.SecureJar;
import cpw.mods.jarhandling.impl.Jar;
import cpw.mods.modlauncher.LaunchPluginHandler;
Expand All @@ -12,6 +10,8 @@
import io.izzel.arclight.boot.AbstractBootstrap;
import io.izzel.arclight.boot.asm.ArclightImplementer;
import io.izzel.arclight.forgeinstaller.ForgeInstaller;
import net.minecraftforge.securemodules.SecureModuleClassLoader;
import net.minecraftforge.securemodules.SecureModuleFinder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.MarkerManager;

Expand All @@ -35,7 +35,7 @@

public class ModBootstrap extends AbstractBootstrap {

public static record ModBoot(Configuration configuration, ClassLoader parent) {}
public record ModBoot(Configuration configuration, ClassLoader parent) {}

private static ModBoot modBoot;

Expand All @@ -60,8 +60,8 @@ public static void postRun() {
try {
var conf = modBoot.configuration();
var parent = modBoot.parent();
var classLoader = (ModuleClassLoader) Thread.currentThread().getContextClassLoader();
var parentField = ModuleClassLoader.class.getDeclaredField("parentLoaders");
var classLoader = (SecureModuleClassLoader) Thread.currentThread().getContextClassLoader();
var parentField = SecureModuleClassLoader.class.getDeclaredField("packageToParentLoader");
var parentLoaders = (Map<String, ClassLoader>) Unsafe.getObject(classLoader, Unsafe.objectFieldOffset(parentField));
for (var mod : conf.modules()) {
for (var pk : mod.reference().descriptor().packages()) {
Expand Down Expand Up @@ -115,19 +115,19 @@ private void injectLaunchPlugin() throws Exception {

@SuppressWarnings("unchecked")
private static void load(Path[] file) throws Throwable {
var classLoader = (ModuleClassLoader) ModBootstrap.class.getClassLoader();
var classLoader = (SecureModuleClassLoader) ModBootstrap.class.getClassLoader();
var secureJar = SecureJar.from((path, base) -> EXCLUDES.stream().noneMatch(path::startsWith), file);
var configurationField = ModuleClassLoader.class.getDeclaredField("configuration");
var configurationField = SecureModuleClassLoader.class.getDeclaredField("configuration");
var confOffset = Unsafe.objectFieldOffset(configurationField);
var oldConf = (Configuration) Unsafe.getObject(classLoader, confOffset);
var conf = oldConf.resolveAndBind(JarModuleFinder.of(secureJar), ModuleFinder.of(), List.of(secureJar.name()));
var conf = oldConf.resolveAndBind(SecureModuleFinder.of(secureJar), ModuleFinder.of(), List.of(secureJar.name()));
modBoot = new ModBoot(conf, classLoader);
Unsafe.putObjectVolatile(classLoader, confOffset, conf);
var pkgField = ModuleClassLoader.class.getDeclaredField("packageLookup");
var pkgField = SecureModuleClassLoader.class.getDeclaredField("packageToOurModules");
var packageLookup = (Map<String, ResolvedModule>) Unsafe.getObject(classLoader, Unsafe.objectFieldOffset(pkgField));
var rootField = ModuleClassLoader.class.getDeclaredField("resolvedRoots");
var rootField = SecureModuleClassLoader.class.getDeclaredField("ourModulesSecure");
var resolvedRoots = (Map<String, Object>) Unsafe.getObject(classLoader, Unsafe.objectFieldOffset(rootField));
var moduleRefCtor = Unsafe.lookup().findConstructor(Class.forName("cpw.mods.cl.JarModuleFinder$JarModuleReference"),
var moduleRefCtor = Unsafe.lookup().findConstructor(Class.forName("net.minecraftforge.securemodules.SecureModuleFinder$Reference"),
MethodType.methodType(void.class, SecureJar.ModuleDataProvider.class));
for (var mod : conf.modules()) {
for (var pk : mod.reference().descriptor().packages()) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ allprojects {
ext {
agpVersion = '1.23'
minecraftVersion = '1.20.2'
forgeVersion = '48.0.4'
forgeVersion = '48.0.40'
apiVersion = '1.5.5'
toolsVersion = '1.3.0'
mixinVersion = '0.8.5'
Expand Down

0 comments on commit 2f10bd4

Please sign in to comment.