Skip to content

Commit

Permalink
fix: omit jackson-core from neoforge jar
Browse files Browse the repository at this point in the history
Also fixes a newer NeoForge compatibility with ServerExplosionMixin.

Fixes #4153
  • Loading branch information
gabizou committed Dec 26, 2024
1 parent cd3f230 commit 2934e15
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* This file is part of Sponge, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.forge.mixin.core.world.level;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.ServerExplosion;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.api.event.Cause;
import org.spongepowered.api.event.SpongeEventFactory;
import org.spongepowered.api.event.world.ExplosionEvent;
import org.spongepowered.api.world.explosion.Explosion;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.api.world.server.ServerWorld;
import org.spongepowered.asm.mixin.Final;
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;
import org.spongepowered.common.event.ShouldFire;
import org.spongepowered.common.event.tracking.PhaseTracker;
import org.spongepowered.common.util.VecHelper;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Mixin(ServerExplosion.class)
public abstract class ServerExplosionMixin_Forge {

// @formatter:off
@Shadow @Final private ServerLevel level;

@Shadow protected abstract boolean shadow$interactsWithBlocks();
// @formatter:on

/**
* These two fields are used in the mixin below, but require a redirect specific for SpongeVanilla
* and SpongeForge as NeoForge makes a change to the method being used here.
*
* @see org.spongepowered.common.mixin.core.world.level.ServerExplosionMixin
*/
private boolean impl$shouldDamageEntities;
private double impl$knockbackMultiplier;
private List<BlockPos> impl$affectedBlocks;

@Redirect(method = "hurtEntities", at = @At(value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerLevel;getEntities(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;)Ljava/util/List;"))
private List<Entity> forge$throwEventToFilterEntitiesOnHurt(final ServerLevel instance, final Entity sourceEntity, final AABB aabb) {
final List<Entity> entities;
if (this.impl$shouldDamageEntities) {
// filter out invulnerable entities before event
entities = instance.getEntities(sourceEntity, aabb).stream()
.filter(e -> !e.ignoreExplosion((net.minecraft.world.level.Explosion) this))
.toList();
} else {
entities = Collections.emptyList();
}

if (ShouldFire.EXPLOSION_EVENT_DETONATE) {
final var apiWorld = (ServerWorld) this.level;
final var apiEntities = entities.stream().map(org.spongepowered.api.entity.Entity.class::cast).toList();
final var apiBlockPositions = this.impl$affectedBlocks.stream().map(bp -> ServerLocation.of(apiWorld, VecHelper.toVector3i(bp))).toList();
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ExplosionEvent.Detonate event = SpongeEventFactory.createExplosionEventDetonate(cause, apiBlockPositions, apiEntities, (Explosion) this, apiWorld);
if (SpongeCommon.post(event)) {
this.impl$affectedBlocks.clear(); // no blocks affected
return Collections.emptyList(); // no entities affected
}
if (this.shadow$interactsWithBlocks()) {
this.impl$affectedBlocks = event.affectedLocations().stream().map(VecHelper::toBlockPos).collect(Collectors.toList());
}
if (this.impl$shouldDamageEntities) {
return event.entities().stream().map(Entity.class::cast).toList();
}
}
return entities;
}


@Redirect(method = "hurtEntities", at = @At(value = "NEW", target = "(DDD)Lnet/minecraft/world/phys/Vec3;"))
private Vec3 forge$useKnockbackMultiplier(final double $$0, final double $$1, final double $$2) {
// Honor our knockback value from event
return new Vec3($$0 * this.impl$knockbackMultiplier,
$$1 * this.impl$knockbackMultiplier,
$$2 * this.impl$knockbackMultiplier);
}

}
83 changes: 42 additions & 41 deletions forge/src/mixins/resources/mixins.spongeforge.core.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
{
"required": true,
"parent": "mixins.sponge.parent.json",
"package": "org.spongepowered.forge.mixin.core",
"priority": 1301,
"mixins": [
"api.event.EventMixin_Forge",
"api.event.block.ChangeBlockEvent_AllMixin_Forge",
"api.event.entity.ChangeEntityWorldEvent_PreMixin_Forge",
"api.event.entity.ChangeEventWorldEvent_PostMixin_Forge",
"commands.CommandsMixin_Forge",
"minecraftforge.MinecraftForgeMixin_Forge",
"minecraftforge.event.entity.EntityTravelToDimensionEventMixin_Forge",
"minecraftforge.event.entity.player.PlayerEvent_PlayerChangedDimensionEventMixin_Forge",
"minecraftforge.event.world.BlockEvent_BreakEventMixin_Forge",
"minecraftforge.event.world.BlockEventMixin_Forge",
"minecraftforge.internal.BrandingControlMixin_Forge",
"minecraftforge.registries.ForgeRegistryMixin_Forge",
"minecraftforge.registries.RegistryManagerMixin_Forge",
"network.ConnectionMixin_Forge",
"network.protocol.common.ClientboundCustomPayloadPacketMixin_Forge",
"network.protocol.common.ServerboundCustomPayloadPacketMixin_Forge",
"server.BootstrapMixin_Forge",
"server.MinecraftServerMixin_Forge",
"server.commands.SpreadPlayersCommandMixin_Forge",
"server.level.ServerPlayerMixin_Forge",
"server.network.ServerGamePacketListenerImplMixin_Forge",
"world.entity.LivingEntityMixin_Forge",
"world.entity.LivingEntityMixin_Forge_Attack_Impl",
"world.entity.item.ItemEntityMixin_Forge",
"world.entity.player.PlayerMixin_Forge_Attack_Impl",
"world.entity.vehicle.BoatMixin_Forge",
"world.level.block.FireBlockMixin_Forge",
"world.level.block.entity.AbstractFurnaceBlockEntityMixin_Forge"
],
"client": [
"client.MinecraftMixin_Forge",
"client.main.MainMixin_Forge"
],
"server": [
"server.MainMixin_Forge"
]
"required": true,
"parent": "mixins.sponge.parent.json",
"package": "org.spongepowered.forge.mixin.core",
"priority": 1301,
"mixins": [
"api.event.EventMixin_Forge",
"api.event.block.ChangeBlockEvent_AllMixin_Forge",
"api.event.entity.ChangeEntityWorldEvent_PreMixin_Forge",
"api.event.entity.ChangeEventWorldEvent_PostMixin_Forge",
"commands.CommandsMixin_Forge",
"minecraftforge.MinecraftForgeMixin_Forge",
"minecraftforge.event.entity.EntityTravelToDimensionEventMixin_Forge",
"minecraftforge.event.entity.player.PlayerEvent_PlayerChangedDimensionEventMixin_Forge",
"minecraftforge.event.world.BlockEvent_BreakEventMixin_Forge",
"minecraftforge.event.world.BlockEventMixin_Forge",
"minecraftforge.internal.BrandingControlMixin_Forge",
"minecraftforge.registries.ForgeRegistryMixin_Forge",
"minecraftforge.registries.RegistryManagerMixin_Forge",
"network.ConnectionMixin_Forge",
"network.protocol.common.ClientboundCustomPayloadPacketMixin_Forge",
"network.protocol.common.ServerboundCustomPayloadPacketMixin_Forge",
"server.BootstrapMixin_Forge",
"server.MinecraftServerMixin_Forge",
"server.commands.SpreadPlayersCommandMixin_Forge",
"server.level.ServerPlayerMixin_Forge",
"server.network.ServerGamePacketListenerImplMixin_Forge",
"world.entity.LivingEntityMixin_Forge",
"world.entity.LivingEntityMixin_Forge_Attack_Impl",
"world.entity.item.ItemEntityMixin_Forge",
"world.entity.player.PlayerMixin_Forge_Attack_Impl",
"world.entity.vehicle.BoatMixin_Forge",
"world.level.ServerExplosionMixin_Forge",
"world.level.block.FireBlockMixin_Forge",
"world.level.block.entity.AbstractFurnaceBlockEntityMixin_Forge"
],
"client": [
"client.MinecraftMixin_Forge",
"client.main.MainMixin_Forge"
],
"server": [
"server.MainMixin_Forge"
]
}
54 changes: 54 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3911,6 +3911,14 @@
<sha256 value="849395aae6f3db840aae543f2407901e589b5b2b2b1aefaa2ecefef04f84f2c1" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged" name="accesstransformers" version="11.0.1">
<artifact name="accesstransformers-11.0.1.jar">
<sha256 value="db59934c1a355e8af08443857c25eed66958b70ba3323485b1eb3dd807efa312" origin="Generated by Gradle"/>
</artifact>
<artifact name="accesstransformers-11.0.1.module">
<sha256 value="6eae5ebf7b69fad34c206bd8c6c04c1569d80febcd055f860113d0361417d689" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged" name="bus" version="8.0.1">
<artifact name="bus-8.0.1.jar">
<sha256 value="569cb2776a2179a464a00373a1a4cbfead409567e7d02d4006f46dbbbd043767" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -3988,6 +3996,20 @@
<sha256 value="c89a15d695df791f03d814c04f3a63c0fd65fe5f688933cfd8f3b989d4beb143" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged" name="neoforge" version="21.3.35-beta">
<artifact name="neoforge-21.3.35-beta-installer.jar">
<sha256 value="c26a23d54c623f6493787e2b7aa5eb2864d6a86fac425b322ad4ec9283aa3d91" origin="Generated by Gradle"/>
</artifact>
<artifact name="neoforge-21.3.35-beta-universal.jar">
<sha256 value="a4a942ef8915d2464540a632df16f7cdf06eefecbd67bcdf1dc87fad51c6b4e5" origin="Generated by Gradle"/>
</artifact>
<artifact name="neoforge-21.3.35-beta-userdev.jar">
<sha256 value="da7402ac1256a96413e2a8d8eb7f75c86bff2f6dfd547dc69487b713d4033f2f" origin="Generated by Gradle"/>
</artifact>
<artifact name="neoforge-21.3.35-beta.module">
<sha256 value="f29c86be720f8ec62e2e64043c0aabe9e06313a61f34e97a673e149b9e61bbc8" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged" name="neoform" version="1.21.1-20240808.144430">
<artifact name="neoform-1.21.1-20240808.144430.module">
<sha256 value="c697a0da4423ac17b9a5f891782a4bfd65143a39a3773de43cb54c67ba7d5747" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -4028,6 +4050,22 @@
<sha256 value="c7fa624126b4adccdc3f15429a883e4b8a9ecb429e48068c411ae30740f16405" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged.accesstransformers" name="at-modlauncher" version="11.0.1">
<artifact name="at-modlauncher-11.0.1.jar">
<sha256 value="8db72ca9f53d537edeca91438e7b815eed1abbc0dd7fca054d3fd47ab5d39d4a" origin="Generated by Gradle"/>
</artifact>
<artifact name="at-modlauncher-11.0.1.module">
<sha256 value="b002c8065c43f412d6847b042dc3d7ff1bcdfc06e261cbcea1b815982a358fe9" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged.accesstransformers" name="at-parser" version="11.0.1">
<artifact name="at-parser-11.0.1.jar">
<sha256 value="22945fd13ab88ba9f565401f7de769992dfa22101ede41a62be6fcd5e439aeaa" origin="Generated by Gradle"/>
</artifact>
<artifact name="at-parser-11.0.1.module">
<sha256 value="fb6beb80d0797f17e9afb55955ddb01853c73ac868883d329a775f6ff57f6cdc" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged.fancymodloader" name="earlydisplay" version="4.0.24">
<artifact name="earlydisplay-4.0.24.jar">
<sha256 value="147a2da4102ebe5629b88fa9b95ce78be397936641a7f09302dc08ee92f93326" origin="Generated by Gradle"/>
Expand All @@ -4044,6 +4082,14 @@
<sha256 value="a22a2c0a12489ef39bd6737c6b95b489f1827eb0785b70a07e1d570d8d4392a4" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged.fancymodloader" name="earlydisplay" version="5.0.1">
<artifact name="earlydisplay-5.0.1.jar">
<sha256 value="7ff8b368bedf6dddb2e43276da22f32f0f1ee7c169e62aa5474de5d1c3f23d65" origin="Generated by Gradle"/>
</artifact>
<artifact name="earlydisplay-5.0.1.module">
<sha256 value="e9efd7b4a93fc187271c107f8b4d77e185ef27831b3380fd40a2537e5f218e5c" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged.fancymodloader" name="loader" version="4.0.24">
<artifact name="loader-4.0.24.jar">
<sha256 value="c76d1e7c27b40dcb4ba9f376766a95845647dff21f5e3a77d32858461f109ca1" origin="Generated by Gradle"/>
Expand All @@ -4060,6 +4106,14 @@
<sha256 value="20fab1d5a8b01feb153807cbaaee73a3d7cb43f582ec976e56e7ce9d28ad4c07" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged.fancymodloader" name="loader" version="5.0.1">
<artifact name="loader-5.0.1.jar">
<sha256 value="065a834d856f5df0d2fe97f906ab16a3e2618183377195b1afa11550fb9384e4" origin="Generated by Gradle"/>
</artifact>
<artifact name="loader-5.0.1.module">
<sha256 value="d2738674aa09a2f5711b2dc2af9ba261d251e47525da2706a8607f08df7e3888" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.neoforged.installertools" name="installertools" version="2.1.2">
<artifact name="installertools-2.1.2-fatjar.jar">
<sha256 value="9fe7c6df17299f661b9cd07fc1c4e85493b63efae6bb9da0255a97d9d0a87c60" origin="Generated by Gradle"/>
Expand Down
3 changes: 3 additions & 0 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ tasks {

from(commonProject.sourceSets.named("applaunch").map { it.output })
from(forgeAppLaunch.output)
// We need to exclude this as NeoForge ships jackson-core as a library
// and we would be violating the packages
dependencyFilter.exclude(dependencyFilter.dependency("com.fasterxml.jackson.core:jackson-core"))

// Make sure to relocate access widener so that we don't conflict with other coremods
relocate("net.fabricmc.accesswidener", "org.spongepowered.neoforge.libs.accesswidener")
Expand Down
2 changes: 1 addition & 1 deletion neoforge/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name=SpongeNeo
implementation=NeoForge
description=The SpongeAPI implementation for NeoForge

neoForgeVersion=21.3.0-beta
neoForgeVersion=21.3.35-beta
loom.platform=neoforge
fabric.loom.dontRemap=true
mixinConfigs=mixins.spongeneo.accessors.json,mixins.spongeneo.api.json,mixins.spongeneo.inventory.json,mixins.spongeneo.core.json,mixins.spongeneo.tracker.json
Loading

0 comments on commit 2934e15

Please sign in to comment.