-
Notifications
You must be signed in to change notification settings - Fork 1
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
68 additions
and
44 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
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
35 changes: 35 additions & 0 deletions
35
Common/src/main/java/dev/upcraft/sparkweave/mixin/LecternBlockMixin.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,35 @@ | ||
package dev.upcraft.sparkweave.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import dev.upcraft.sparkweave.event.LecternMenuRegistry; | ||
import net.minecraft.world.MenuProvider; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.block.LecternBlock; | ||
import net.minecraft.world.level.block.entity.LecternBlockEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.OptionalInt; | ||
|
||
@Mixin(LecternBlock.class) | ||
public class LecternBlockMixin { | ||
|
||
@WrapOperation(method = "openScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;openMenu(Lnet/minecraft/world/MenuProvider;)Ljava/util/OptionalInt;")) | ||
private OptionalInt customMenuProvider(Player instance, MenuProvider menu, Operation<OptionalInt> original) { | ||
if (menu instanceof LecternBlockEntity lectern) { | ||
var provider = LecternMenuRegistry.get(lectern.getBook()).map(factory -> sparkweave$createProvider(factory, instance, lectern)).orElse(menu); | ||
return original.call(instance, provider); | ||
} | ||
|
||
return original.call(instance, menu); | ||
} | ||
|
||
@Unique | ||
@Nullable | ||
private static MenuProvider sparkweave$createProvider(LecternMenuRegistry.MenuProviderFactory factory, Player player, LecternBlockEntity lectern) { | ||
return factory.create(player.level(), lectern.getBlockPos(), player, lectern, lectern.getBook()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,21 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "dev.upcraft.sparkweave.mixin", | ||
"plugin": "dev.upcraft.sparkweave.SparkweaveMixinConfigPlugin", | ||
"refmap": "${mod_id}.refmap.json", | ||
"compatibilityLevel": "JAVA_21", | ||
"mixins": [ | ||
"BlockEntityMixin", | ||
"LecternBlockEntityMixin" | ||
], | ||
"client": [ | ||
"client.LecternRendererMixin", | ||
"client.MainMixin", | ||
"client.RenderLayerMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "dev.upcraft.sparkweave.mixin", | ||
"plugin": "dev.upcraft.sparkweave.SparkweaveMixinConfigPlugin", | ||
"refmap": "${mod_id}.refmap.json", | ||
"compatibilityLevel": "JAVA_21", | ||
"mixins": [ | ||
"BlockEntityMixin", | ||
"LecternBlockEntityMixin", | ||
"LecternBlockMixin" | ||
], | ||
"client": [ | ||
"client.LecternRendererMixin", | ||
"client.MainMixin", | ||
"client.RenderLayerMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |