From b9e13fe3c7cbc75b6acfd7a4bce73e7b7bce79c7 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sun, 31 Mar 2024 13:27:34 +0800 Subject: [PATCH] Update modloader versions --- README.md | 10 +-- .../entity/player/PlayerEntityBridge.java | 5 +- .../core/world/item/ItemStackBridge.java | 2 + .../network/ServerPlayNetHandlerMixin.java | 13 ++- .../inventory/EnchantmentContainerMixin.java | 4 +- .../entity/player/PlayerMixin_NeoForge.java | 5 ++ .../world/item/ItemStackMixin_NeoForge.java | 6 ++ bootstrap/build.gradle | 4 +- .../application/ApplicationBootstrap.java | 83 +++++++++---------- build.gradle | 6 +- 10 files changed, 82 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 2cd070f4e..d1a5a0b04 100644 --- a/README.md +++ b/README.md @@ -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**: diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/player/PlayerEntityBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/player/PlayerEntityBridge.java index e42a6ce70..6c0a23064 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/player/PlayerEntityBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/entity/player/PlayerEntityBridge.java @@ -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; @@ -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; + } } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/item/ItemStackBridge.java b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/item/ItemStackBridge.java index d4f363d59..4353ef253 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/item/ItemStackBridge.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/bridge/core/world/item/ItemStackBridge.java @@ -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) {} } diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java index 2f49433ee..26c763e6c 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/network/ServerPlayNetHandlerMixin.java @@ -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; @@ -490,6 +491,7 @@ private void signBook(FilteredText text, List 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 { @@ -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()); @@ -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()) { diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/inventory/EnchantmentContainerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/inventory/EnchantmentContainerMixin.java index fda73bb5b..66cadf9f2 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/inventory/EnchantmentContainerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/core/world/inventory/EnchantmentContainerMixin.java @@ -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; @@ -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); } diff --git a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/player/PlayerMixin_NeoForge.java b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/player/PlayerMixin_NeoForge.java index 3c623b8d0..c9c25e349 100644 --- a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/player/PlayerMixin_NeoForge.java +++ b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/entity/player/PlayerMixin_NeoForge.java @@ -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(); + } } diff --git a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/ItemStackMixin_NeoForge.java b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/ItemStackMixin_NeoForge.java index 574b16d6d..227bcb14e 100644 --- a/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/ItemStackMixin_NeoForge.java +++ b/arclight-neoforge/src/main/java/io/izzel/arclight/neoforge/mixin/core/world/item/ItemStackMixin_NeoForge.java @@ -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; @@ -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); + } } diff --git a/bootstrap/build.gradle b/bootstrap/build.gradle index 599fc2ee8..c93cd2142 100644 --- a/bootstrap/build.gradle +++ b/bootstrap/build.gradle @@ -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' diff --git a/bootstrap/src/forge/java/io/izzel/arclight/boot/forge/application/ApplicationBootstrap.java b/bootstrap/src/forge/java/io/izzel/arclight/boot/forge/application/ApplicationBootstrap.java index ce3022070..423f1fb79 100644 --- a/bootstrap/src/forge/java/io/izzel/arclight/boot/forge/application/ApplicationBootstrap.java +++ b/bootstrap/src/forge/java/io/izzel/arclight/boot/forge/application/ApplicationBootstrap.java @@ -2,7 +2,6 @@ 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; @@ -10,6 +9,7 @@ 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; @@ -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 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 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())); @@ -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(); @@ -86,15 +96,4 @@ public void moduleMain(String... args) throws Exception { Thread.currentThread().setContextClassLoader(oldcl); } } - - @SuppressWarnings("unchecked") - private static List getClassPath() throws Exception { - Class cl = Class.forName("net.minecraftforge.bootstrap.ClassPathHelper"); - var method = cl.getDeclaredMethod("getCleanedClassPath"); - try { - return (List) Unsafe.lookup().unreflect(method).invoke(); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } } diff --git a/build.gradle b/build.gradle index 502bf22d9..4305dfef1 100644 --- a/build.gradle +++ b/build.gradle @@ -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'