From a1950a2be03c9c0282524de9c9c01029aebf33df Mon Sep 17 00:00:00 2001 From: Gabriel Harris-Rouquette Date: Mon, 11 Nov 2024 16:48:47 -0800 Subject: [PATCH] fix: work on re-enabling spongeforge for 1.21.3 --- forge/gradle.properties | 2 +- .../spongepowered/forge/SpongeForgeMod.java | 8 +- .../server/level/ServerPlayerMixin_Forge.java | 7 +- ...rverGamePacketListenerImplMixin_Forge.java | 25 +++-- .../world/entity/LivingEntityMixin_Forge.java | 12 +-- .../world/entity/vehicle/BoatMixin_Forge.java | 22 ++--- ...rverPlayerGameModeMixin_Forge_Tracker.java | 2 +- .../BlockBehaviorMixin_Forge_Tracker.java | 2 +- gradle/verification-metadata.xml | 97 +++++++++++++++++++ 9 files changed, 144 insertions(+), 33 deletions(-) diff --git a/forge/gradle.properties b/forge/gradle.properties index acc83580cf4..a3d8006e3a1 100644 --- a/forge/gradle.properties +++ b/forge/gradle.properties @@ -2,7 +2,7 @@ name=SpongeForge implementation=Forge description=The SpongeAPI implementation for MinecraftForge -forgeVersion=52.0.3 +forgeVersion=53.0.12 loom.platform=forge fabric.loom.dontRemap=true mixinConfigs=mixins.spongeforge.accessors.json,mixins.spongeforge.api.json,mixins.spongeforge.inventory.json,mixins.spongeforge.inventory.shared.json,mixins.spongeforge.core.json,mixins.spongeforge.core.shared.json,mixins.spongeforge.tracker.json \ No newline at end of file diff --git a/forge/src/main/java/org/spongepowered/forge/SpongeForgeMod.java b/forge/src/main/java/org/spongepowered/forge/SpongeForgeMod.java index 200740664e5..3cccd1d9797 100644 --- a/forge/src/main/java/org/spongepowered/forge/SpongeForgeMod.java +++ b/forge/src/main/java/org/spongepowered/forge/SpongeForgeMod.java @@ -25,6 +25,8 @@ package org.spongepowered.forge; import net.minecraft.client.Minecraft; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; import net.minecraftforge.common.MinecraftForge; @@ -64,10 +66,10 @@ public final class SpongeForgeMod { private final Logger logger = LogManager.getLogger("spongeforge"); - public SpongeForgeMod() { + public SpongeForgeMod(FMLJavaModLoadingContext ctx) { // WorldPersistenceHooks.addHook(SpongeLevelDataPersistence.INSTANCE); // TODO SF 1.19.4 - final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); + final IEventBus modBus = ctx.getModEventBus(); // modBus: add all FML events with it modBus.addListener(this::onCommonSetup); @@ -144,7 +146,7 @@ public void onRegister(RegisterEvent event) { .sized(0.6F, 1.8F) .clientTrackingRange(org.spongepowered.common.util.Constants.Entity.Player.TRACKING_RANGE) .updateInterval(2) - .build("sponge:human") + .build(ResourceKey.create(ForgeRegistries.Keys.ENTITY_TYPES, ResourceLocation.parse("sponge:human"))) ; event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> helper.register(HumanEntity.KEY, SpongeEntityTypes.HUMAN)); diff --git a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/level/ServerPlayerMixin_Forge.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/level/ServerPlayerMixin_Forge.java index b06f9cb2cce..25f11215d82 100644 --- a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/level/ServerPlayerMixin_Forge.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/level/ServerPlayerMixin_Forge.java @@ -24,8 +24,10 @@ */ package org.spongepowered.forge.mixin.core.server.level; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.common.event.tracking.PhaseContext; import org.spongepowered.common.event.tracking.PhaseTracker; @@ -37,10 +39,13 @@ @Mixin(ServerPlayer.class) public abstract class ServerPlayerMixin_Forge extends LivingEntityMixin_Forge { + @Shadow public abstract ServerLevel shadow$serverLevel(); + // override from LivingEntityMixin_Forge @Override protected void forge$onElytraUse(final CallbackInfo ci) { - final PhaseContext context = PhaseTracker.SERVER.getPhaseContext(); + final ServerLevel level = this.shadow$serverLevel(); + final PhaseContext context = PhaseTracker.getWorldInstance(level).getPhaseContext(); final TransactionalCaptureSupplier transactor = context.getTransactor(); final net.minecraft.server.level.ServerPlayer player = (net.minecraft.server.level.ServerPlayer) (Object) this; try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.STANDARD)) { diff --git a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/network/ServerGamePacketListenerImplMixin_Forge.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/network/ServerGamePacketListenerImplMixin_Forge.java index f8e9a9a30af..f3c363bcbec 100644 --- a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/network/ServerGamePacketListenerImplMixin_Forge.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/server/network/ServerGamePacketListenerImplMixin_Forge.java @@ -25,6 +25,8 @@ package org.spongepowered.forge.mixin.core.server.network; import net.minecraft.network.protocol.game.ServerGamePacketListener; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.world.inventory.RecipeBookMenu; import net.minecraft.world.item.crafting.RecipeHolder; @@ -33,6 +35,7 @@ import org.spongepowered.api.item.inventory.crafting.CraftingInventory; import org.spongepowered.api.item.inventory.query.QueryTypes; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.common.SpongeCommon; @@ -44,23 +47,29 @@ @Mixin(ServerGamePacketListenerImpl.class) public abstract class ServerGamePacketListenerImplMixin_Forge implements ServerGamePacketListener { - @SuppressWarnings({"unchecked", "rawtypes"}) - @Redirect(method = "lambda$handlePlaceRecipe$10", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/RecipeBookMenu;handlePlacement(ZLnet/minecraft/world/item/crafting/RecipeHolder;Lnet/minecraft/server/level/ServerPlayer;)V")) - private void forge$onPlaceRecipe(final RecipeBookMenu recipeBookMenu, final boolean shift, final RecipeHolder recipe, final net.minecraft.server.level.ServerPlayer player) { - final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext(); + @Shadow public ServerPlayer player; + + @Redirect(method = "handlePlaceRecipe", + at = @At(value = "INVOKE", target = "net/minecraft/world/inventory/RecipeBookMenu.handlePlacement(ZZLnet/minecraft/world/item/crafting/RecipeHolder;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/player/Inventory;)Lnet/minecraft/world/inventory/RecipeBookMenu$PostPlaceAction;")) + private RecipeBookMenu.PostPlaceAction forge$onPlaceRecipe( + final RecipeBookMenu recipeBookMenu, final boolean shift, final boolean isCreative, final RecipeHolder recipe, + final ServerLevel serverLevel, final net.minecraft.world.entity.player.Inventory inventory) { + final PhaseContext<@NonNull ?> context = PhaseTracker.getWorldInstance(this.player.serverLevel()).getPhaseContext(); final TransactionalCaptureSupplier transactor = context.getTransactor(); + final var player = this.player; final Inventory craftInv = ((Inventory) player.containerMenu).query(QueryTypes.INVENTORY_TYPE.get().of(CraftingInventory.class)); + final RecipeBookMenu.PostPlaceAction result; if (!(craftInv instanceof CraftingInventory)) { - recipeBookMenu.handlePlacement(shift, recipe, player); + result = recipeBookMenu.handlePlacement(shift,isCreative, recipe, serverLevel, inventory); SpongeCommon.logger().warn("Detected crafting without a InventoryCrafting!? Crafting Event will not fire."); - return; + return result; } try (final EffectTransactor ignored = transactor.logPlaceRecipe(shift, recipe, player, (CraftingInventory) craftInv)) { - recipeBookMenu.handlePlacement(shift, recipe, player); + result = recipeBookMenu.handlePlacement(shift,isCreative, recipe, serverLevel, inventory); player.containerMenu.broadcastChanges(); } + return result; } } diff --git a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/LivingEntityMixin_Forge.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/LivingEntityMixin_Forge.java index 050c899e5cc..a91a34fa01e 100644 --- a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/LivingEntityMixin_Forge.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/LivingEntityMixin_Forge.java @@ -34,12 +34,12 @@ public abstract class LivingEntityMixin_Forge { @Inject( - method = "updateFallFlying", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/item/ItemStack;elytraFlightTick(Lnet/minecraft/world/entity/LivingEntity;I)Z", - shift = At.Shift.AFTER - ) + method = "updateFallFlying", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/item/ItemStack;hurtAndBreak(ILnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;)V", + shift = At.Shift.AFTER + ) ) protected void forge$onElytraUse(final CallbackInfo ci) { } diff --git a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/vehicle/BoatMixin_Forge.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/vehicle/BoatMixin_Forge.java index f00eb8a1c45..a293a3eb716 100644 --- a/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/vehicle/BoatMixin_Forge.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/vehicle/BoatMixin_Forge.java @@ -24,29 +24,27 @@ */ package org.spongepowered.forge.mixin.core.world.entity.vehicle; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.vehicle.Boat; -import net.minecraft.world.level.LevelReader; +import net.minecraft.world.entity.vehicle.AbstractBoat; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.common.bridge.world.entity.vehicle.BoatBridge; +import org.spongepowered.common.bridge.world.entity.vehicle.AbstractBoatBridge; -@Mixin(Boat.class) -public abstract class BoatMixin_Forge implements BoatBridge { +@Mixin(AbstractBoat.class) +public abstract class BoatMixin_Forge implements AbstractBoatBridge { + // TODO - Confirm that forge's patch is no longer necessary @Redirect(method = "getGroundFriction", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/level/block/state/BlockState;getFriction(Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/Entity;)F") + target = "Lnet/minecraft/world/level/block/Block;getFriction()F") ) - private float forge$getBlockFrictionIfBoatIsNotOverridingMovingOnLand(BlockState caller, LevelReader level, BlockPos pos, Entity entity) { + private float forge$fixGetFriction(Block block) { final boolean movesOnLand = this.bridge$getMoveOnLand(); - final float friction = caller.getFriction(level, pos, entity); + final float friction = block.getFriction(); if (movesOnLand && friction == 0.6f) { - return Blocks.ICE.getFriction(caller, level, pos, entity); + return Blocks.ICE.getFriction(); } return friction; } diff --git a/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/server/level/ServerPlayerGameModeMixin_Forge_Tracker.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/server/level/ServerPlayerGameModeMixin_Forge_Tracker.java index b3f8c60f891..0b0b2dd3e13 100644 --- a/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/server/level/ServerPlayerGameModeMixin_Forge_Tracker.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/server/level/ServerPlayerGameModeMixin_Forge_Tracker.java @@ -63,7 +63,7 @@ public abstract class ServerPlayerGameModeMixin_Forge_Tracker { final ItemStack itemStack, final Level level, final BlockState state, final BlockPos pos, final Player player ) { - final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext(); + final PhaseContext<@NonNull ?> context = PhaseTracker.getWorldInstance(player.level()).getPhaseContext(); final TransactionalCaptureSupplier transactor = context.getTransactor(); // Log the prepare drops here because Forge rewrites // this method to call mine block before calling destroy block diff --git a/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/world/level/block/state/BlockBehaviorMixin_Forge_Tracker.java b/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/world/level/block/state/BlockBehaviorMixin_Forge_Tracker.java index 8784263a379..973df0af53f 100644 --- a/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/world/level/block/state/BlockBehaviorMixin_Forge_Tracker.java +++ b/forge/src/mixins/java/org/spongepowered/forge/mixin/tracker/world/level/block/state/BlockBehaviorMixin_Forge_Tracker.java @@ -42,7 +42,7 @@ public abstract class BlockBehaviorMixin_Forge_Tracker { method = "getLootTable", at = @At( value = "FIELD", - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour;lootTableSupplier:Ljava/util/function/Supplier;", + target = "Lnet/minecraft/world/level/block/state/BlockBehaviour;drops:Ljava/util/Optional;", remap = false ) ) diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 4046353e1be..d3a19fd91c9 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1699,6 +1699,14 @@ + + + + + + + + @@ -2964,6 +2972,14 @@ + + + + + + + + @@ -3036,6 +3052,14 @@ + + + + + + + + @@ -3084,6 +3108,14 @@ + + + + + + + + @@ -3132,6 +3164,14 @@ + + + + + + + + @@ -3216,6 +3256,20 @@ + + + + + + + + + + + + + + @@ -3232,6 +3286,14 @@ + + + + + + + + @@ -3288,6 +3350,14 @@ + + + + + + + + @@ -3336,6 +3406,14 @@ + + + + + + + + @@ -3384,6 +3462,14 @@ + + + + + + + + @@ -3430,6 +3516,14 @@ + + + + + + + + @@ -3461,6 +3555,9 @@ + + +