generated from TropheusJ/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...o/github/fabricators_of_create/porting_lib/loot/mixin/loottable/LootTableMixin_Early.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...io/github/fabricators_of_create/porting_lib/loot/mixin/loottable/LootTableMixin_Late.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters