From bf35952778392f2a31d30aa9a36a243a27552627 Mon Sep 17 00:00:00 2001 From: gamma-delta <29877714+gamma-delta@users.noreply.github.com> Date: Thu, 2 Jun 2022 02:11:48 -0500 Subject: [PATCH] lilliputian --- Common/build.gradle | 2 -- .../{OpGetScale.kt.nope => OpGetScale.kt} | 5 ++-- .../{OpSetScale.kt.nope => OpSetScale.kt} | 7 ++--- .../interop/pehkui/PehkuiInterop.java | 22 ++++++++++++-- .../hexcasting/xplat/IXplatAbstractions.java | 5 ++++ .../assets/hexcasting/lang/en_us.json | 2 ++ .../en_us/entries/interop/pehkui.json | 4 +-- Fabric/build.gradle | 6 ++-- .../fabric/xplat/FabricXplatImpl.java | 27 +++++++++++++++++ Forge/build.gradle | 2 +- .../hexcasting/forge/ForgeHexInitializer.java | 4 +-- .../forge/xplat/ForgeXplatImpl.java | 29 +++++++++++++++++++ 12 files changed, 95 insertions(+), 20 deletions(-) rename Common/src/main/java/at/petrak/hexcasting/interop/pehkui/{OpGetScale.kt.nope => OpGetScale.kt} (79%) rename Common/src/main/java/at/petrak/hexcasting/interop/pehkui/{OpSetScale.kt.nope => OpSetScale.kt} (81%) diff --git a/Common/build.gradle b/Common/build.gradle index 9a08ec08..3b919372 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -39,8 +39,6 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.1' - - compileOnly "com.github.Virtuoel:Pehkui:${pehkuiVersion}" } test { diff --git a/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpGetScale.kt.nope b/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpGetScale.kt similarity index 79% rename from Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpGetScale.kt.nope rename to Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpGetScale.kt index f32490f5..d0b3e815 100644 --- a/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpGetScale.kt.nope +++ b/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpGetScale.kt @@ -5,15 +5,14 @@ import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.asSpellResult import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.getChecked +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.world.entity.Entity -import virtuoel.pehkui.api.ScaleTypes object OpGetScale : ConstManaOperator { override val argc = 1 override fun execute(args: List>, ctx: CastingContext): List> { val target = args.getChecked(0) - val data = ScaleTypes.BASE.getScaleData(target) - return data.scale.toDouble().asSpellResult + return IXplatAbstractions.INSTANCE.pehkuiApi.getScale(target).toDouble().asSpellResult } } \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpSetScale.kt.nope b/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpSetScale.kt similarity index 81% rename from Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpSetScale.kt.nope rename to Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpSetScale.kt index a43c4db8..65c7070b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpSetScale.kt.nope +++ b/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/OpSetScale.kt @@ -2,8 +2,8 @@ package at.petrak.hexcasting.interop.pehkui import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.casting.CastingContext +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.world.entity.Entity -import virtuoel.pehkui.api.ScaleTypes object OpSetScale : SpellOperator { override val argc = 2 @@ -24,10 +24,7 @@ object OpSetScale : SpellOperator { private data class Spell(val target: Entity, val scale: Double) : RenderedSpell { override fun cast(ctx: CastingContext) { - val scaleType = ScaleTypes.BASE - val data = scaleType.getScaleData(target) - - data.scale = scale.toFloat() + IXplatAbstractions.INSTANCE.pehkuiApi.setScale(target, scale.toFloat()) } } } \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/PehkuiInterop.java b/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/PehkuiInterop.java index ae17d456..cc83edf7 100644 --- a/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/PehkuiInterop.java +++ b/Common/src/main/java/at/petrak/hexcasting/interop/pehkui/PehkuiInterop.java @@ -1,12 +1,30 @@ package at.petrak.hexcasting.interop.pehkui; +import at.petrak.hexcasting.api.PatternRegistry; +import at.petrak.hexcasting.api.spell.math.HexDir; +import at.petrak.hexcasting.api.spell.math.HexPattern; +import net.minecraft.world.entity.Entity; + +import static at.petrak.hexcasting.api.HexAPI.modLoc; + public class PehkuiInterop { public static void init() { - /* try { + PatternRegistry.mapPattern(HexPattern.fromAngles("aawawwawwa", HexDir.NORTH_WEST), + modLoc("interop/pehkui/get"), OpGetScale.INSTANCE); + PatternRegistry.mapPattern(HexPattern.fromAngles("ddwdwwdwwd", HexDir.NORTH_EAST), + modLoc("interop/pehkui/set"), OpSetScale.INSTANCE); } catch (PatternRegistry.RegisterPatternException e) { e.printStackTrace(); } - */ + } + + /** + * Pehkui doesn't publish an API jar so we do this BS + */ + public interface ApiAbstraction { + float getScale(Entity e); + + void setScale(Entity e, float scale); } } diff --git a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java index f758c848..f7d0d20f 100644 --- a/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java +++ b/Common/src/main/java/at/petrak/hexcasting/xplat/IXplatAbstractions.java @@ -10,6 +10,7 @@ import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.spell.casting.CastingHarness; import at.petrak.hexcasting.api.spell.casting.ResolvedPattern; import at.petrak.hexcasting.common.network.IMessage; +import at.petrak.hexcasting.interop.pehkui.PehkuiInterop; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.Packet; import net.minecraft.resources.ResourceLocation; @@ -141,6 +142,10 @@ public interface IXplatAbstractions { LootItemCondition.Builder isShearsCondition(); + // interop + + PehkuiInterop.ApiAbstraction getPehkuiApi(); + /// IXplatAbstractions INSTANCE = find(); diff --git a/Common/src/main/resources/assets/hexcasting/lang/en_us.json b/Common/src/main/resources/assets/hexcasting/lang/en_us.json index 72c68f77..8839200b 100644 --- a/Common/src/main/resources/assets/hexcasting/lang/en_us.json +++ b/Common/src/main/resources/assets/hexcasting/lang/en_us.json @@ -357,6 +357,8 @@ "hexcasting.spell.hexcasting:interop/gravity/get": "Gravitational Purification", "hexcasting.spell.hexcasting:interop/gravity/set": "Alter Gravity", + "hexcasting.spell.hexcasting:interop/pehkui/get": "Gulliver's Purification", + "hexcasting.spell.hexcasting:interop/pehkui/set": "Alter Scale", "hexcasting.mishap.invalid_pattern": "That pattern isn't associated with any action", "hexcasting.mishap.unescaped": "Expected to evaluate a pattern, but evaluated %s instead", diff --git a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/interop/pehkui.json b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/interop/pehkui.json index 73a2b95a..a806c928 100644 --- a/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/interop/pehkui.json +++ b/Common/src/main/resources/data/hexcasting/patchouli_books/thehexbook/en_us/entries/interop/pehkui.json @@ -1,9 +1,9 @@ { "name": "hexcasting.entry.interop.pehkui", - "icon": "minecraft:iron_nugget", + "icon": "minecraft:red_mushroom", "category": "hexcasting:interop", "advancement": "hexcasting:root", - "flag": "never", + "flag": "mod:pehkui", "pages": [ "hexcasting.page.interop.pehkui.1", { diff --git a/Fabric/build.gradle b/Fabric/build.gradle index 9690439c..1bc24a71 100644 --- a/Fabric/build.gradle +++ b/Fabric/build.gradle @@ -74,9 +74,9 @@ dependencies { modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:$reiVersion" modImplementation "maven.modrinth:fusions-gravity-api:$gravityApiVersion" - // modApi("com.github.Virtuoel:Pehkui:${pehkuiVersion}", { - // exclude group: "net.fabricmc.fabric-api" - // }) + modApi("com.github.Virtuoel:Pehkui:${pehkuiVersion}", { + exclude group: "net.fabricmc.fabric-api" + }) } tasks.withType(JavaCompile) { diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java index 50711e0a..dec835b7 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricXplatImpl.java @@ -16,6 +16,7 @@ import at.petrak.hexcasting.fabric.cc.HexCardinalComponents; import at.petrak.hexcasting.fabric.interop.gravity.GravityApiInterop; import at.petrak.hexcasting.fabric.recipe.FabricUnsealedIngredient; import at.petrak.hexcasting.interop.HexInterop; +import at.petrak.hexcasting.interop.pehkui.PehkuiInterop; import at.petrak.hexcasting.ktxt.AccessorWrappers; import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatTags; @@ -37,6 +38,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.TagKey; import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attribute; @@ -56,6 +58,7 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.MatchTool; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; +import virtuoel.pehkui.api.ScaleTypes; import java.util.List; import java.util.function.BiFunction; @@ -330,4 +333,28 @@ public class FabricXplatImpl implements IXplatAbstractions { HexItemTags.create(new ResourceLocation("c", "shears")))) ); } + + private static PehkuiInterop.ApiAbstraction PEHKUI_API = null; + + @Override + public PehkuiInterop.ApiAbstraction getPehkuiApi() { + if (!this.isModPresent(HexInterop.PEHKUI_ID)) { + throw new IllegalArgumentException("cannot get the pehkui api without pehkui"); + } + + if (PEHKUI_API == null) { + PEHKUI_API = new PehkuiInterop.ApiAbstraction() { + @Override + public float getScale(Entity e) { + return ScaleTypes.BASE.getScaleData(e).getScale(); + } + + @Override + public void setScale(Entity e, float scale) { + ScaleTypes.BASE.getScaleData(e).setScale(scale); + } + }; + } + return PEHKUI_API; + } } diff --git a/Forge/build.gradle b/Forge/build.gradle index 15cf4405..19cce6fb 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -141,7 +141,7 @@ dependencies { testCompileOnly fg.deobf("at.petra-k.paucal:paucal-forge-$minecraftVersion:$paucalVersion") testCompileOnly fg.deobf("vazkii.patchouli:Patchouli:$minecraftVersion-$patchouliVersion") - api fg.deobf("com.github.Virtuoel:Pehkui:${pehkuiVersion}") + api fg.deobf("com.github.Virtuoel:Pehkui:${pehkuiVersion}-${minecraftVersion}-forge") } mixin { diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java index 3b57be69..afadcaf7 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java @@ -72,8 +72,6 @@ public class ForgeHexInitializer { initConfig(); initRegistry(); initListeners(); - - HexInterop.init(); } private static void initConfig() { @@ -132,6 +130,8 @@ public class ForgeHexInitializer { HexComposting.setup(); HexStrippables.init(); RegisterPatterns.registerPatterns(); + + HexInterop.init(); })); // We have to do these at some point when the registries are still open diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java index ef3d513e..b3af4339 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeXplatImpl.java @@ -20,6 +20,8 @@ import at.petrak.hexcasting.forge.cap.HexCapabilities; import at.petrak.hexcasting.forge.network.ForgePacketHandler; import at.petrak.hexcasting.forge.network.MsgBrainsweepAck; import at.petrak.hexcasting.forge.recipe.ForgeUnsealedIngredient; +import at.petrak.hexcasting.interop.HexInterop; +import at.petrak.hexcasting.interop.pehkui.PehkuiInterop; import at.petrak.hexcasting.ktxt.AccessorWrappers; import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatTags; @@ -37,6 +39,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.TagKey; import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attribute; @@ -70,6 +73,7 @@ import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.network.NetworkDirection; import net.minecraftforge.network.PacketDistributor; import org.jetbrains.annotations.Nullable; +import virtuoel.pehkui.api.ScaleTypes; import java.util.ArrayList; import java.util.List; @@ -379,6 +383,31 @@ public class ForgeXplatImpl implements IXplatAbstractions { return CanToolPerformAction.canToolPerformAction(ToolActions.SHEARS_DIG); } + // it's literally the EXACT SAME on fabric aaa + private static PehkuiInterop.ApiAbstraction PEHKUI_API = null; + + @Override + public PehkuiInterop.ApiAbstraction getPehkuiApi() { + if (!this.isModPresent(HexInterop.PEHKUI_ID)) { + throw new IllegalArgumentException("cannot get the pehkui api without pehkui"); + } + + if (PEHKUI_API == null) { + PEHKUI_API = new PehkuiInterop.ApiAbstraction() { + @Override + public float getScale(Entity e) { + return ScaleTypes.BASE.getScaleData(e).getScale(); + } + + @Override + public void setScale(Entity e, float scale) { + ScaleTypes.BASE.getScaleData(e).setScale(scale); + } + }; + } + return PEHKUI_API; + } + public static final String TAG_BRAINSWEPT = "hexcasting:brainswept"; public static final String TAG_SENTINEL_EXISTS = "hexcasting:sentinel_exists"; public static final String TAG_SENTINEL_GREATER = "hexcasting:sentinel_extends_range";