Skip to content

Commit

Permalink
fix: work on re-enabling spongeforge for 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gabizou committed Nov 12, 2024
1 parent b666fd3 commit a1950a2
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 33 deletions.
2 changes: 1 addition & 1 deletion forge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
Expand Down
Loading

0 comments on commit a1950a2

Please sign in to comment.