Skip to content

Commit

Permalink
hopefully fix loot module compat
Browse files Browse the repository at this point in the history
  • Loading branch information
TropheusJ committed Feb 4, 2024
1 parent c9d8cea commit 267bd89
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ allprojects {
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabric_version")

// Make sure we don't break canvas
modLocalRuntime("io.vram:frex-fabric:$frex_version")
// modLocalRuntime("io.vram:frex-fabric:$frex_version")

implementation("javax.annotation:javax.annotation-api:1.3.2")
implementation("com.google.code.findbugs:jsr305:3.0.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.fabricators_of_create.porting_lib.loot.mixin;
package io.github.fabricators_of_create.porting_lib.loot.mixin.loottable;

import java.util.Objects;
import java.util.function.Consumer;
Expand Down Expand Up @@ -44,17 +44,15 @@ public ResourceLocation getLootTableId() {
at = @At("HEAD"),
argsOnly = true
)
private Consumer<ItemStack> wrapConsumer(Consumer<ItemStack> output) {
return new LootCollector(output);
private Consumer<ItemStack> aaaaaa(Consumer<ItemStack> output) {
return output;
}

@Inject(
method = "getRandomItemsRaw(Lnet/minecraft/world/level/storage/loot/LootContext;Ljava/util/function/Consumer;)V",
at = @At("RETURN")
)
private void finishCollectingLoot(LootContext context, Consumer<ItemStack> output, CallbackInfo ci) {
if (output instanceof LootCollector collector)
collector.finish(this.lootTableId, context);
private void bbbbbbbbb(LootContext context, Consumer<ItemStack> output, CallbackInfo ci) {
}

@Mixin(LootTable.Builder.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.fabricators_of_create.porting_lib.loot.mixin.loottable;

import java.util.function.Consumer;

import io.github.fabricators_of_create.porting_lib.loot.LootCollector;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootTable;

@Mixin(value = LootTable.class, priority = 100)
public class LootTableMixin_Early {
@ModifyVariable(
method = "getRandomItemsRaw(Lnet/minecraft/world/level/storage/loot/LootContext;Ljava/util/function/Consumer;)V",
at = @At("HEAD"),
argsOnly = true
)
private Consumer<ItemStack> wrapConsumer(Consumer<ItemStack> output) {
// this needs to be done really early to get ahead of all uses of the consumer.
// Lower integer priority is invoked first.
return new LootCollector(output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.github.fabricators_of_create.porting_lib.loot.mixin.loottable;

import java.util.function.Consumer;

import io.github.fabricators_of_create.porting_lib.loot.extensions.LootTableExtensions;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import io.github.fabricators_of_create.porting_lib.loot.LootCollector;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootTable;

@Mixin(value = LootTable.class, priority = 50_000)
public class LootTableMixin_Late implements LootTableExtensions {
@Inject(
method = "getRandomItemsRaw(Lnet/minecraft/world/level/storage/loot/LootContext;Ljava/util/function/Consumer;)V",
at = @At("RETURN")
)
private void finishCollectingLoot(LootContext context, Consumer<ItemStack> output, CallbackInfo ci) {
// this needs to be done really late to catch all uses of the consumer before finishing.
// Higher integer priority is invoked last.
if (output instanceof LootCollector collector)
collector.finish(this.getLootTableId(), context);
}
}
6 changes: 4 additions & 2 deletions loot/src/main/resources/porting_lib_loot.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"LootPoolMixin",
"LootPoolMixin$LootPoolBuilderMixin",
"LootPoolMixin$LootPoolSerializerMixin",
"LootTableMixin",
"LootTableMixin$BuilderMixin"
"loottable.LootTableMixin",
"loottable.LootTableMixin$BuilderMixin",
"loottable.LootTableMixin_Early",
"loottable.LootTableMixin_Late"
]
}

0 comments on commit 267bd89

Please sign in to comment.