Skip to content

Commit fb76cfc

Browse files
committed
feat(forge): update MinecraftForge to 1.21.5
- Updated MinecraftForge version to 1.21.5-55.0.6 - Introduced a mixin for NamespacedWrapper to address registry hierarchy changes from MinecraftForge - Refined scope of damage steps in LivingEntity for Forge
1 parent 2dd685e commit fb76cfc

8 files changed

Lines changed: 203 additions & 13 deletions

File tree

forge/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ AWToAT.convert(awFiles, atFile)
220220
val mixinConfigs: MutableSet<String> = spongeImpl.mixinConfigurations
221221

222222
extensions.configure(UserDevExtension::class) {
223-
mappings("official", "1.21.4")
223+
mappings("official", "1.21.5")
224224
accessTransformers.from(atFile)
225225
reobf = false
226226

forge/gradle.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ name=SpongeForge
22
implementation=Forge
33
description=The SpongeAPI implementation for MinecraftForge
44

5-
forgeVersion=54.0.12
6-
loom.platform=forge
7-
fabric.loom.dontRemap=true
5+
forgeVersion=55.0.6
86
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
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of Sponge, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.forge.mixin.core.minecraftforge.registries;
26+
27+
import org.spongepowered.asm.mixin.Mixin;
28+
import org.spongepowered.asm.mixin.Shadow;
29+
import org.spongepowered.common.accessor.core.MappedRegistryAccessor;
30+
31+
/**
32+
* Due to the Accessor being intrinsically implemented on top of MappedRegistry, the
33+
* extended NamespacedWrapper class redefines frozen as a private field, leaving the
34+
* original accessor to be useless. To fix registry issues, we therefore re-implement
35+
* our accessor interface explicitly for registry purposes.
36+
*
37+
* @author gabizou - Minecraft 1.21.5 MinecraftForge 55.0.6
38+
* @param <T>
39+
*/
40+
@Mixin(targets = "net/minecraftforge/registries/NamespacedWrapper")
41+
public abstract class NamespacedWrapperMixin_Forge<T> implements MappedRegistryAccessor<T> {
42+
43+
@Shadow private boolean frozen;
44+
45+
@Override
46+
public boolean accessor$frozen() {
47+
return this.frozen;
48+
}
49+
}

forge/src/mixins/java/org/spongepowered/forge/mixin/core/world/entity/LivingEntityMixin_Forge_Damage.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626

2727
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2828
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
29+
import net.minecraft.server.level.ServerLevel;
2930
import net.minecraft.world.damagesource.DamageSource;
3031
import net.minecraft.world.entity.LivingEntity;
32+
import net.minecraft.world.item.ItemStack;
3133
import net.minecraftforge.event.entity.living.ShieldBlockEvent;
3234
import org.spongepowered.api.event.cause.entity.damage.DamageStepTypes;
3335
import org.spongepowered.asm.mixin.Mixin;
36+
import org.spongepowered.asm.mixin.Shadow;
3437
import org.spongepowered.asm.mixin.injection.At;
3538
import org.spongepowered.asm.mixin.injection.Constant;
3639
import org.spongepowered.asm.mixin.injection.ModifyArg;
@@ -44,28 +47,55 @@
4447
@Mixin(LivingEntity.class)
4548
public abstract class LivingEntityMixin_Forge_Damage implements TrackedDamageBridge {
4649

50+
//@formatter:off
51+
@Shadow public abstract ItemStack shadow$getUseItem();
52+
//@formatter:on
53+
4754
@ModifyConstant(method = "actuallyHurt", constant = @Constant(floatValue = 0), slice = @Slice(
4855
from = @At(value = "INVOKE", target = "Lnet/minecraftforge/common/ForgeHooks;onLivingHurt(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/damagesource/DamageSource;F)F"),
4956
to = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;getDamageAfterArmorAbsorb(Lnet/minecraft/world/damagesource/DamageSource;F)F")))
5057
private float damage$doNotReturnEarly(final float constant) {
5158
return Float.NaN;
5259
}
5360

54-
@WrapOperation(method = "hurtServer", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onShieldBlock(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/damagesource/DamageSource;F)Lnet/minecraftforge/event/entity/living/ShieldBlockEvent;"))
55-
private ShieldBlockEvent damage$modifyBeforeAndAfterShield(final LivingEntity self, final DamageSource source, final float originalDamage, final Operation<ShieldBlockEvent> operation) {
61+
@WrapOperation(method = "hurtServer",
62+
at = @At(value = "INVOKE",
63+
target = "Lnet/minecraft/world/entity/LivingEntity;applyItemBlocking(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/damagesource/DamageSource;F)F"
64+
))
65+
private float damage$initiateBlockingStep(
66+
final LivingEntity self, final ServerLevel level, final DamageSource source, final float originalDamage,
67+
final Operation<Float> original) {
5668
final SpongeDamageTracker tracker = this.damage$tracker();
5769
if (tracker == null) {
58-
return operation.call(self, source, originalDamage);
70+
return original.call(self, level, source, originalDamage);
5971
}
6072

61-
final SpongeDamageStep step = tracker.newStep(DamageStepTypes.SHIELD, ItemStackUtil.snapshotOf(self.getUseItem()));
73+
final SpongeDamageStep step = tracker.newStep(DamageStepTypes.SHIELD, ItemStackUtil.snapshotOf(this.shadow$getUseItem()));
6274
float damage = (float) step.applyChildrenBefore(originalDamage);
75+
return original.call(self, level, source, damage);
76+
}
77+
78+
79+
@WrapOperation(method = "applyItemBlocking", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onShieldBlock(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/damagesource/DamageSource;FLnet/minecraft/world/item/ItemStack;)Lnet/minecraftforge/event/entity/living/ShieldBlockEvent;"))
80+
private ShieldBlockEvent damage$modifyBeforeAndAfterShield(
81+
final LivingEntity self, final DamageSource source, final float originalDamage, final ItemStack stack,
82+
final Operation<ShieldBlockEvent> operation
83+
) {
84+
final SpongeDamageTracker tracker = this.damage$tracker();
85+
if (tracker == null) {
86+
return operation.call(self, source, originalDamage, stack);
87+
}
88+
final var step = tracker.currentStep(DamageStepTypes.SHIELD);
89+
if (step == null) {
90+
return operation.call(self, source, originalDamage, stack);
91+
}
92+
float damage = (float) step.damageBeforeSelf().getAsDouble();
6393
final ShieldBlockEvent event;
6494
if (step.isSkipped()) {
65-
event = new ShieldBlockEvent(self, source, damage);
95+
event = new ShieldBlockEvent(self, source, damage, stack);
6696
event.setCanceled(true);
6797
} else {
68-
event = operation.call(self, source, damage);
98+
event = operation.call(self, source, damage, stack);
6999
if (!event.isCanceled()) {
70100
damage -= event.getBlockedDamage();
71101
}

forge/src/mixins/resources/mixins.spongeforge.core.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"minecraftforge.internal.BrandingControlMixin_Forge",
1919
"minecraftforge.registries.ForgeRegistryMixin_Forge",
2020
"minecraftforge.registries.GameDataMixin_Forge",
21+
"minecraftforge.registries.NamespacedWrapperMixin_Forge",
2122
"minecraftforge.registries.RegistryManagerMixin_Forge",
2223
"network.ConnectionMixin_Forge",
2324
"network.protocol.common.ClientboundCustomPayloadPacketMixin_Forge",

0 commit comments

Comments
 (0)