Skip to content

Commit

Permalink
Update modloader versions
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 31, 2024
1 parent 55eb9ae commit b9e13fe
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 56 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 | NeoForge | Fabric | Status | Downloads |
|:---------------------|:--------|:---------|:-------|:------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Whisper (1.20.4) | 49.0.31 | 20.4.196 | 0.96.4 | ACTIVE | [![1.20.4 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Whisper&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3AWhisper) |
| Trials (1.20-1.20.1) | 47.2.20 | - | - | 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.7 | - | - | 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 | NeoForge | Fabric | Status | Downloads |
|:---------------------|:--------|:---------|:--------|:------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Whisper (1.20.4) | 49.0.38 | 20.4.215 | 0.96.11 | ACTIVE | [![1.20.4 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Whisper&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3AWhisper) |
| Trials (1.20-1.20.1) | 47.2.20 | - | - | 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.7 | - | - | 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
Expand Up @@ -4,7 +4,6 @@
import io.izzel.arclight.common.bridge.core.entity.LivingEntityBridge;
import io.izzel.tools.product.Product;
import io.izzel.tools.product.Product3;
import io.izzel.tools.product.Product5;
import io.izzel.tools.product.Product6;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -60,4 +59,8 @@ public interface PlayerEntityBridge extends LivingEntityBridge {
bridge$platform$onRightClickBlock(InteractionHand hand, BlockPos pos, BlockHitResult hitResult) {
return Product.of(false, false, false, false, false, InteractionResult.PASS);
}

default boolean bridge$platform$mayfly() {
return ((Player) this).getAbilities().mayfly;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ enum ToolAction {
default boolean bridge$forge$doesSneakBypassUse(LevelReader level, BlockPos pos, Player player) {
return false;
}

default void bridge$platform$copyAdditionalFrom(ItemStack from) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.izzel.arclight.common.bridge.core.server.MinecraftServerBridge;
import io.izzel.arclight.common.bridge.core.server.management.PlayerInteractionManagerBridge;
import io.izzel.arclight.common.bridge.core.server.management.PlayerListBridge;
import io.izzel.arclight.common.bridge.core.world.item.ItemStackBridge;
import io.izzel.arclight.common.mod.ArclightConstants;
import io.izzel.arclight.common.mod.server.ArclightServer;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
Expand Down Expand Up @@ -490,6 +491,7 @@ private void signBook(FilteredText text, List<FilteredText> list, int slot) {
}

itemStack.addTagElement("author", StringTag.valueOf(this.player.getName().getString()));
((ItemStackBridge) (Object) itemStack).bridge$platform$copyAdditionalFrom(old);
if (this.player.isTextFilteringEnabled()) {
itemStack.addTagElement("title", StringTag.valueOf(text.filteredOrEmpty()));
} else {
Expand Down Expand Up @@ -679,7 +681,14 @@ public void handleMovePlayer(ServerboundMovePlayerPacket packetplayinflying) {
}

this.player.absMoveTo(d0, d1, d2, f, f1); // Copied from above
this.clientIsFloating = d12 >= -0.03125D && this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR && !this.server.isFlightAllowed() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isFallFlying() && this.noBlocksAround((Entity) this.player) && !this.player.isAutoSpinAttack();
this.clientIsFloating = d12 >= -0.03125D
&& this.player.gameMode.getGameModeForPlayer() != GameType.SPECTATOR
&& !this.server.isFlightAllowed()
&& !(this.player.getAbilities().mayfly || ((ServerPlayerEntityBridge) this.player).bridge$platform$mayfly())
&& !this.player.hasEffect(MobEffects.LEVITATION)
&& !this.player.isFallFlying()
&& this.noBlocksAround(this.player)
&& !this.player.isAutoSpinAttack();
// CraftBukkit end
this.player.serverLevel().getChunkSource().move(this.player);
this.player.doCheckFallDamage(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5, packetplayinflying.isOnGround());
Expand Down Expand Up @@ -1724,7 +1733,7 @@ public void handleSetCreativeModeSlot(final ServerboundSetCreativeModeSlotPacket
@Overwrite
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, (ServerGamePacketListenerImpl) (Object) this, this.player.serverLevel());
if (this.player.getAbilities().mayfly && this.player.getAbilities().flying != packet.isFlying()) {
if ((this.player.getAbilities().mayfly || ((ServerPlayerEntityBridge) this.player).bridge$platform$mayfly()) && this.player.getAbilities().flying != packet.isFlying()) {
PlayerToggleFlightEvent event = new PlayerToggleFlightEvent(getCraftPlayer(), packet.isFlying());
this.cserver.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.izzel.arclight.common.bridge.core.inventory.EnchantmentMenuBridge;
import io.izzel.arclight.common.bridge.core.inventory.container.PosContainerBridge;
import io.izzel.arclight.common.bridge.core.util.IWorldPosCallableBridge;
import io.izzel.arclight.common.bridge.core.world.item.ItemStackBridge;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -207,10 +208,11 @@ public boolean clickMenuButton(net.minecraft.world.entity.player.Player playerIn
if (flag) {
itemstack2 = new ItemStack(Items.ENCHANTED_BOOK);

CompoundTag tag = itemstack2.getTag();
CompoundTag tag = itemstack.getTag();
if (tag != null) {
itemstack2.setTag(tag.copy());
}
((ItemStackBridge) (Object) itemstack2).bridge$platform$copyAdditionalFrom(itemstack);

this.enchantSlots.setItem(0, itemstack2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ public abstract class PlayerMixin_NeoForge extends LivingEntityMixin_NeoForge im
event.getUseBlock() == Event.Result.ALLOW, event.getUseBlock() == Event.Result.DENY,
event.getCancellationResult());
}

@Override
public boolean bridge$platform$mayfly() {
return this.mayFly();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.phys.AABB;
import net.neoforged.neoforge.attachment.AttachmentHolder;
import net.neoforged.neoforge.attachment.AttachmentUtils;
import net.neoforged.neoforge.common.extensions.IItemStackExtension;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Final;
Expand Down Expand Up @@ -76,4 +77,9 @@ public void setItem(Item item) {
public boolean bridge$forge$doesSneakBypassUse(LevelReader level, BlockPos pos, Player player) {
return doesSneakBypassUse(level, pos, player);
}

@Override
public void bridge$platform$copyAdditionalFrom(ItemStack from) {
AttachmentUtils.copyStackAttachments(from, (ItemStack) (Object) this);
}
}
4 changes: 2 additions & 2 deletions bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ dependencies {
forgeImplementation "net.minecraftforge:fmlloader:${minecraftVersion}-${forgeVersion}"
forgeImplementation 'net.minecraftforge:securemodules:2.2.7'
forgeImplementation 'net.minecraftforge:forgespi:7.1.0'
forgeImplementation 'net.minecraftforge:bootstrap:2.0.0'
forgeImplementation 'net.minecraftforge:bootstrap-api:2.0.0'
forgeImplementation 'net.minecraftforge:bootstrap:2.1.0'
forgeImplementation 'net.minecraftforge:bootstrap-api:2.1.0'

neoforgeImplementation 'net.neoforged.fancymodloader:spi:2.0.7'
neoforgeImplementation 'net.neoforged.fancymodloader:loader:2.0.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import cpw.mods.jarhandling.SecureJar;
import cpw.mods.jarhandling.impl.SimpleJarMetadata;
import io.izzel.arclight.api.Unsafe;
import net.minecraftforge.bootstrap.ForgeBootstrap;
import net.minecraftforge.bootstrap.api.BootstrapEntryPoint;
import net.minecraftforge.securemodules.SecureModuleClassLoader;
import net.minecraftforge.securemodules.SecureModuleFinder;

import java.lang.module.ModuleFinder;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.Set;
Expand All @@ -21,41 +21,49 @@ public static void main(String[] args) throws Exception {
new ApplicationBootstrap().start(args);
}

protected void start(String... args) throws Exception {
var classPath = getClassPath();
var boot = selectBootModules(classPath);
var arclight = classPath.stream().filter(it -> it.moduleDataProvider().name().equals("arclight.boot")).findAny().orElseThrow();
var jar = SecureJar.from(it -> new SimpleJarMetadata("arclight.launch", "1.0", Set.of("io.izzel.arclight.boot.forge.application"), List.of()), arclight.getPrimaryPath());
boot.add(jar);

// First we need to get ourselves onto a module layer, so that we can be the parent of the actual runtime layer
var finder = SecureModuleFinder.of(boot.toArray(SecureJar[]::new));
var targets = boot.stream().map(SecureJar::name).toList();
var cfg = ModuleLayer.boot().configuration().resolve(finder, ModuleFinder.ofSystem(), targets);
var cl = Thread.currentThread().getContextClassLoader(); //BaseBootstrap.class.getClassLoader();
var layer = ModuleLayer.boot().defineModulesWithOneLoader(cfg, cl);

// Find ourselves in the new fancy module environment.
var bootstrap = layer.findModule("arclight.launch").get();
var moduleCl = bootstrap.getClassLoader();
var self = Class.forName(this.getClass().getName(), false, moduleCl);
var inst = self.getDeclaredConstructor().newInstance();

// And now invoke main as if we had done all the command line arguments to specify modules!
var moduleMain = self.getDeclaredMethod("moduleMain", String[].class);
moduleMain.invoke(inst, (Object) args);
protected void bootstrapMain(String[] args, List<Path[]> classpath) {
try {
// Default parent class loader
var cl = Thread.currentThread().getContextClassLoader();
// This should be the AppClassloader but doesn't quite work right, can't remember why off hand but I had it commented out for a reason
// cl == BaseBootstrap.class.getClassLoader();
var boot = selectBootModules(classpath);
var arclight = classpath.stream().map(SecureJar::from).filter(it -> it.moduleDataProvider().name().equals("arclight.boot")).findAny().orElseThrow();
var jar = SecureJar.from(it -> new SimpleJarMetadata("arclight.launch", "1.0", Set.of("io.izzel.arclight.boot.forge.application"), List.of()), arclight.getPrimaryPath());
boot.add(jar);

// First we need to get ourselves onto a module layer, so that we can be the parent of the actual runtime layer
var finder = SecureModuleFinder.of(boot.toArray(SecureJar[]::new));
var targets = boot.stream().map(SecureJar::name).toList();
var cfg = ModuleLayer.boot().configuration().resolve(finder, ModuleFinder.ofSystem(), targets);
var layer = ModuleLayer.boot().defineModulesWithOneLoader(cfg, cl);

// Find ourselves in the new fancy module environment.
var bootstrap = layer.findModule("arclight.launch").orElseThrow();
var moduleCl = bootstrap.getClassLoader();
var self = Class.forName(this.getClass().getName(), false, moduleCl);
var inst = self.getDeclaredConstructor().newInstance();

// And now invoke main as if we had done all the command line arguments to specify modules!
var moduleMain = self.getDeclaredMethod("moduleMain", String[].class, List.class);
moduleMain.invoke(inst, args, classpath);
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public void moduleMain(String... args) throws Exception {
public void moduleMain(String[] args, List<Path[]> classpath) throws Exception {
var bootlayer = getClass().getModule().getLayer();
var classPath = getClassPath();

var mergedModules = Set.of("maven.model", "maven.model.builder", "maven.repository.metadata", "maven.artifact");
var secure = selectRuntimeModules(classPath.stream().filter(it -> !mergedModules.contains(it.moduleDataProvider().name()) && !it.moduleDataProvider().name().equals("arclight.boot")).toList());
var mavenMerged = SecureJar.from(classPath.stream().filter(it -> mergedModules.contains(it.moduleDataProvider().name()))
var secure = selectRuntimeModules(classpath).stream().filter(it -> !mergedModules.contains(it.moduleDataProvider().name()) && !it.moduleDataProvider().name().equals("arclight.boot"))
.collect(Collectors.toCollection(ArrayList::new));

var mavenMerged = SecureJar.from(classpath.stream().map(SecureJar::from).filter(it -> mergedModules.contains(it.moduleDataProvider().name()))
.map(SecureJar::getPrimaryPath).toArray(Path[]::new));
secure.add(mavenMerged);
var arclight = classPath.stream().filter(it -> it.moduleDataProvider().name().equals("arclight.boot")).findAny().orElseThrow();
var arclight = classpath.stream().map(SecureJar::from).filter(it -> it.moduleDataProvider().name().equals("arclight.boot")).findAny().orElseThrow();
secure.add(SecureJar.from(it -> new SimpleJarMetadata(arclight.name(), arclight.moduleDataProvider().descriptor().rawVersion().orElse("1.0"),
arclight.getPackages().stream().filter(p -> !p.equals("io.izzel.arclight.boot.forge.application")).collect(Collectors.toSet()), arclight.getProviders()), arclight.getPrimaryPath()));

Expand All @@ -64,10 +72,12 @@ public void moduleMain(String... args) throws Exception {
var targets = secure.stream().map(SecureJar::name).toList();
var cfg = bootlayer.configuration().resolveAndBind(finder, ModuleFinder.ofSystem(), targets);
var parent = List.of(ModuleLayer.boot(), bootlayer);
var cl = new SecureModuleClassLoader("SECURE-BOOTSTRAP", null, cfg, parent);
var layer = bootlayer.defineModules(cfg, module -> cl);

// Use the current classloader as the parent, if set, so that we don't get things from the bootstrap loader.
var oldcl = Thread.currentThread().getContextClassLoader();
var cl = new SecureModuleClassLoader("SECURE-BOOTSTRAP", null, cfg, parent, oldcl == null ? List.of() : List.of(oldcl));
var layer = bootlayer.defineModules(cfg, module -> cl);

try {
Thread.currentThread().setContextClassLoader(cl);
var services = ServiceLoader.load(layer, BootstrapEntryPoint.class).stream().filter(it -> it.type().getName().contains("arclight")).toList();
Expand All @@ -86,15 +96,4 @@ public void moduleMain(String... args) throws Exception {
Thread.currentThread().setContextClassLoader(oldcl);
}
}

@SuppressWarnings("unchecked")
private static List<SecureJar> getClassPath() throws Exception {
Class<?> cl = Class.forName("net.minecraftforge.bootstrap.ClassPathHelper");
var method = cl.getDeclaredMethod("getCleanedClassPath");
try {
return (List<SecureJar>) Unsafe.lookup().unreflect(method).invoke();
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ allprojects {
minecraftVersion = '1.20.4'
supportedPlatforms = ['forge', 'neoforge', 'fabric']
fabricLoaderVersion = '0.15.6'
fabricApiVersion = '0.96.4+1.20.4'
forgeVersion = '49.0.31'
neoForgeVersion = '20.4.196'
fabricApiVersion = '0.96.11+1.20.4'
forgeVersion = '49.0.38'
neoForgeVersion = '20.4.215'
apiVersion = '1.6.3'
toolsVersion = '1.3.0'
mixinVersion = '0.8.5'
Expand Down

0 comments on commit b9e13fe

Please sign in to comment.