Skip to content

Commit 79bb460

Browse files
committed
Update fabric mixins
1 parent eb50e02 commit 79bb460

File tree

8 files changed

+107
-33
lines changed

8 files changed

+107
-33
lines changed

loofah/src/mixins/java/dk/nelind/loofah/mixin/core/commands/CommandsMixin_Fabric.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public abstract class CommandsMixin_Fabric {
7878
final Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> p_197052_4_,
7979
final ServerPlayer playerEntity
8080
) {
81-
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
81+
try (final CauseStackManager.StackFrame frame = PhaseTracker.getInstance().pushCauseFrame()) {
8282
frame.pushCause(playerEntity);
8383
frame.addContext(EventContextKeys.SUBJECT, (Subject) playerEntity);
8484
final CommandCause sourceToUse = ((CommandSourceStackBridge) p_197052_3_).bridge$withCurrentCause();

loofah/src/mixins/java/dk/nelind/loofah/mixin/core/server/commands/SpreadPlayersCommandMixin_Fabric.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public abstract class SpreadPlayersCommandMixin_Fabric {
5858
final float yRot,
5959
final float xRot
6060
) {
61-
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
61+
try (final CauseStackManager.StackFrame frame = PhaseTracker.getInstance().pushCauseFrame()) {
6262
frame.addContext(EventContextKeys.MOVEMENT_TYPE, MovementTypes.COMMAND);
6363

6464
return instance.teleportTo(level, x, y, z, relativeMovements, yRot, xRot);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* This file is part of Loofah, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Nelind <https://www.nelind.dk>
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 dk.nelind.loofah.mixin.core.tags;
26+
27+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
28+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
29+
import com.llamalad7.mixinextras.sugar.Local;
30+
import net.minecraft.resources.ResourceLocation;
31+
import net.minecraft.tags.TagEntry;
32+
import net.minecraft.tags.TagLoader;
33+
import org.spongepowered.asm.mixin.Mixin;
34+
import org.spongepowered.asm.mixin.injection.At;
35+
import org.spongepowered.asm.mixin.injection.Coerce;
36+
import org.spongepowered.asm.mixin.injection.Inject;
37+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
38+
import org.spongepowered.common.bridge.tags.TagLoaderBridge;
39+
40+
import java.util.Collection;
41+
import java.util.List;
42+
import java.util.Map;
43+
import java.util.function.Consumer;
44+
45+
/** Copied from {@link org.spongepowered.vanilla.mixin.core.tags.TagLoaderMixin_Vanilla} */
46+
@Mixin(TagLoader.class)
47+
public abstract class TagLoaderMixin_Fabric<T> implements TagLoaderBridge<T> {
48+
49+
@WrapOperation(
50+
method = "build(Lnet/minecraft/tags/TagEntry$Lookup;Ljava/util/List;)Lcom/mojang/datafixers/util/Either;",
51+
at = @At(
52+
value = "INVOKE",
53+
target = "Lnet/minecraft/tags/TagEntry;build(Lnet/minecraft/tags/TagEntry$Lookup;Ljava/util/function/Consumer;)Z"
54+
)
55+
)
56+
protected boolean fabric$onBuildTag(
57+
final TagEntry instance,
58+
final TagEntry.Lookup<T> lookup,
59+
final Consumer<T> consumer,
60+
final Operation<Boolean> original,
61+
final TagEntry.Lookup<T> $$0,
62+
final List<TagLoader.EntryWithSource> $$1,
63+
final @Local TagLoader.EntryWithSource entry
64+
) {
65+
return this.bridge$acceptTag(instance, lookup, consumer, original::call, $$1, entry);
66+
}
67+
68+
@Inject(method = "lambda$build$5", at = @At("HEAD"))
69+
private void fabric$onStartBuildingTag(
70+
final TagEntry.Lookup<T> $$0x,
71+
final Map<ResourceLocation, Collection<T>> $$1x,
72+
final ResourceLocation $$2x,
73+
final @Coerce Object $$3x,
74+
final CallbackInfo ci
75+
) {
76+
this.bridge$buildingTagKey($$2x);
77+
}
78+
79+
@Inject(method = "lambda$build$5", at = @At("RETURN"))
80+
private void fabric$onDoneBuildingTag(final CallbackInfo ci) {
81+
this.bridge$buildingTagKey(null);
82+
}
83+
}

loofah/src/mixins/java/dk/nelind/loofah/mixin/core/world/entity/EntityTypeMixin_Fabric.java

+2-15
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,19 @@
2424
*/
2525
package dk.nelind.loofah.mixin.core.world.entity;
2626

27-
import net.minecraft.core.Registry;
2827
import net.minecraft.core.registries.BuiltInRegistries;
2928
import net.minecraft.world.entity.EntityType;
30-
import net.minecraft.world.entity.MobCategory;
3129
import org.spongepowered.asm.mixin.Mixin;
3230
import org.spongepowered.asm.mixin.injection.At;
3331
import org.spongepowered.asm.mixin.injection.Inject;
3432
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3533
import org.spongepowered.common.entity.SpongeEntityTypes;
36-
import org.spongepowered.common.entity.living.human.HumanEntity;
37-
import org.spongepowered.common.util.Constants;
3834

3935
/** Copied from {@link org.spongepowered.vanilla.mixin.core.world.entity.EntityTypeMixin_Vanilla} */
4036
@Mixin(EntityType.class)
4137
public abstract class EntityTypeMixin_Fabric {
4238
@Inject(method = "<clinit>", at = @At("TAIL"))
43-
private static void impl$createHumanType(CallbackInfo ci) {
44-
SpongeEntityTypes.HUMAN = Registry.register(
45-
BuiltInRegistries.ENTITY_TYPE,
46-
HumanEntity.KEY,
47-
EntityType.Builder.of(HumanEntity::new, MobCategory.MISC)
48-
.noSave()
49-
.sized(0.6F, 1.8F)
50-
.clientTrackingRange(Constants.Entity.Player.TRACKING_RANGE)
51-
.updateInterval(2)
52-
.build("sponge:human")
53-
);
39+
private static void impl$registerSpongeTypes(CallbackInfo ci) {
40+
SpongeEntityTypes.register(BuiltInRegistries.ENTITY_TYPE);
5441
}
5542
}

loofah/src/mixins/java/dk/nelind/loofah/mixin/core/world/level/block/entity/AbstractFurnaceBlockEntityMixin_Fabric.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Fabric extends BaseContain
104104
final var entity = (AbstractFurnaceBlockEntityMixin_Fabric) (Object) (entityIn);
105105
final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(slots.get(1));
106106

107-
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
107+
final Cause cause = PhaseTracker.getInstance().currentCause();
108108
if (entity.cookingProgress == 0) { // Start
109109
final CookingEvent.Start event = SpongeEventFactory.createCookingEventStart(cause, (FurnaceBlockEntity) entityIn, Optional.of(fuel),
110110
Optional.of((CookingRecipe) recipe.value()), Optional.of((ResourceKey) (Object) recipe.id()));
@@ -133,7 +133,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Fabric extends BaseContain
133133
final int clampedCookTime = Mth.clamp(newCookTime, zero, totalCookTime);
134134
final var entity = (AbstractFurnaceBlockEntityMixin_Fabric) (Object) entityIn;
135135
final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(entity.items.get(1));
136-
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
136+
final Cause cause = PhaseTracker.getInstance().currentCause();
137137
final var recipe = entity.bridge$getCurrentRecipe();
138138
final ItemStackSnapshot cooking = ItemStackUtil.snapshotOf(entity.items.get(0));
139139
final CookingEvent.Tick event = SpongeEventFactory.createCookingEventTick(cause, (FurnaceBlockEntity) entityIn, cooking, Optional.of(fuel),
@@ -168,7 +168,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Fabric extends BaseContain
168168
final int maxStackSize,
169169
final CallbackInfoReturnable<Boolean> cir
170170
) {
171-
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
171+
final Cause cause = PhaseTracker.getInstance().currentCause();
172172
final FurnaceBlockEntity entity = cause.first(FurnaceBlockEntity.class)
173173
.orElseThrow(() -> new IllegalStateException("Expected to have a FurnaceBlockEntity in the Cause"));
174174
((AbstractFurnaceBlockEntityMixin_Fabric) entity).fabric$filledWaterBucket = true;
@@ -186,7 +186,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Fabric extends BaseContain
186186
final ItemStack recipeResult = recipe.value().getResultItem(registryAccess);
187187
final ItemStack itemOut = slots.get(2);
188188

189-
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
189+
final Cause cause = PhaseTracker.getInstance().currentCause();
190190
final FurnaceBlockEntity entity = cause.first(FurnaceBlockEntity.class)
191191
.orElseThrow(() -> new IllegalStateException("Expected to have a FurnaceBlockEntity in the Cause"));
192192

loofah/src/mixins/java/dk/nelind/loofah/mixin/core/world/level/storage/LevelStorageSourceMixin_Vanilla.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package dk.nelind.loofah.mixin.core.world.level.storage;
2626

27+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
28+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
2729
import com.mojang.serialization.Dynamic;
2830
import com.mojang.serialization.Lifecycle;
2931
import net.minecraft.nbt.CompoundTag;
@@ -35,30 +37,27 @@
3537
import net.minecraft.world.level.storage.PrimaryLevelData;
3638
import org.spongepowered.asm.mixin.Mixin;
3739
import org.spongepowered.asm.mixin.injection.At;
38-
import org.spongepowered.asm.mixin.injection.Redirect;
3940
import org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge;
40-
import org.spongepowered.common.util.Constants;
4141

4242
/** Copied from {@link org.spongepowered.vanilla.mixin.core.world.level.storage.LevelStorageSourceMixin_Vanilla} */
4343
@Mixin(LevelStorageSource.class)
4444
public abstract class LevelStorageSourceMixin_Vanilla {
4545
private static Dynamic<Tag> impl$spongeLevelData;
4646

47-
@SuppressWarnings("deprecation")
48-
@Redirect(
47+
@WrapOperation(
4948
method = "readLevelDataTagFixed",
5049
at = @At(
5150
value = "INVOKE",
5251
target = "Lnet/minecraft/nbt/CompoundTag;getCompound(Ljava/lang/String;)Lnet/minecraft/nbt/CompoundTag;",
5352
ordinal = 0
5453
)
5554
)
56-
private static CompoundTag impl$createSpongeLevelData(final CompoundTag compoundNBT, final String path) {
57-
LevelStorageSourceMixin_Vanilla.impl$spongeLevelData = new Dynamic<>(NbtOps.INSTANCE, compoundNBT.getCompound(Constants.Sponge.Data.V2.SPONGE_DATA));
58-
return compoundNBT.getCompound(path);
55+
private static CompoundTag impl$createSpongeLevelData(final CompoundTag compoundNBT, final String path, final Operation<CompoundTag> original) {
56+
LevelStorageSourceMixin_Vanilla.impl$spongeLevelData = new Dynamic<>(NbtOps.INSTANCE, compoundNBT);
57+
return original.call(compoundNBT, path);
5958
}
6059

61-
@Redirect(
60+
@WrapOperation(
6261
method = "getLevelDataAndDimensions",
6362
at = @At(
6463
value = "INVOKE",
@@ -70,9 +69,10 @@ public abstract class LevelStorageSourceMixin_Vanilla {
7069
final LevelSettings $$1,
7170
final PrimaryLevelData.SpecialWorldProperty $$2,
7271
final WorldOptions $$3,
73-
final Lifecycle $$4
72+
final Lifecycle $$4,
73+
final Operation<PrimaryLevelData> original
7474
) {
75-
final PrimaryLevelData levelData = PrimaryLevelData.parse($$0, $$1, $$2, $$3, $$4);
75+
final PrimaryLevelData levelData = original.call($$0, $$1, $$2, $$3, $$4);
7676

7777
((PrimaryLevelDataBridge) levelData).bridge$readSpongeLevelData(LevelStorageSourceMixin_Vanilla.impl$spongeLevelData);
7878

loofah/src/mixins/java/dk/nelind/loofah/mixin/inventory/event/world/level/block/entity/HopperBlockEntityMixin_Inventory_Fabric.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class HopperBlockEntityMixin_Inventory_Fabric {
5454
target = "Lnet/minecraft/world/level/block/entity/HopperBlockEntity;isFullContainer(Lnet/minecraft/world/Container;Lnet/minecraft/core/Direction;)Z"
5555
)
5656
)
57-
private static boolean vanilla$throwTransferPreIfNotFull(
57+
private static boolean fabric$throwTransferPreIfNotFull(
5858
final Container attachedContainer,
5959
final Direction direction,
6060
final Level level,
@@ -83,7 +83,7 @@ public class HopperBlockEntityMixin_Inventory_Fabric {
8383
ordinal = 1
8484
)
8585
)
86-
private static void vanilla$afterPutStackInSlots(
86+
private static void fabric$afterPutStackInSlots(
8787
final Level var0,
8888
final BlockPos var1,
8989
final HopperBlockEntity var3,
@@ -117,5 +117,8 @@ public class HopperBlockEntityMixin_Inventory_Fabric {
117117
sourceSlotTransaction
118118
);
119119
}
120+
121+
InventoryUtil.updateInventoryNoEvents(var3);
122+
InventoryUtil.updateInventoryNoEvents(iInventory);
120123
}
121124
}

loofah/src/mixins/resources/mixins.loofah.core.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"server.network.ServerGamePacketListenerImplMixin_Fabric",
2424
"server.packs.repository.PackRepositoryMixin_Fabric",
2525
"spongepowered.common.util.ConstantsMixin",
26+
"tags.TagLoaderMixin_Fabric",
2627
"world.entity.EntityMixin_Fabric",
2728
"world.entity.EntityTypeMixin_Fabric",
2829
"world.entity.LivingEntityMixin_Attack_Impl",

0 commit comments

Comments
 (0)