From 4e3d3076a2398e1bb9b86103401451d85073f454 Mon Sep 17 00:00:00 2001 From: gamma-delta <29877714+gamma-delta@users.noreply.github.com> Date: Fri, 6 May 2022 18:09:47 -0500 Subject: [PATCH] aaaaa --- .../hexcasting/api/misc/FrozenColorizer.java | 5 - .../hexcasting/api/misc/TriPredicate.java | 9 ++ .../hexcasting/api/mod/HexApiItems.java | 102 ------------------ .../hexcasting/api/spell/math/HexCoord.kt | 1 - .../hexcasting/api/spell/math/HexPattern.kt | 6 +- .../hexcasting/client/ClientTickCounter.java | 6 +- .../client/RegisterClientStuff.java | 19 ++-- .../at/petrak/hexcasting/client/RenderLib.kt | 6 +- .../akashic/BlockAkashicFloodfiller.java | 4 +- .../blocks/akashic/BlockAkashicWood.java | 31 ------ .../behavior}/HexComposting.java | 2 +- .../blocks/behavior/HexStrippables.java | 16 +++ .../impetuses/BlockStoredPlayerImpetus.java | 10 +- .../blocks/decoration/BlockStrippable.java | 40 ------- .../common/casting/operators/OpRead.kt | 15 ++- .../casting/operators/OpTheCoolerRead.kt | 11 +- .../common/casting/operators/OpWrite.kt | 24 ++--- .../casting/operators/spells/OpColorize.kt | 15 +-- .../casting/operators/spells/OpConjure.kt | 8 +- .../casting/operators/spells/OpCreateWater.kt | 4 +- .../casting/operators/spells/OpErase.kt | 42 ++++---- .../casting/operators/spells/OpExtinguish.kt | 10 +- .../casting/operators/spells/OpIgnite.kt | 8 +- .../casting/operators/spells/OpMakeBattery.kt | 4 +- .../operators/spells/OpMakePackagedSpell.kt | 10 +- .../casting/operators/spells/OpPlaceBlock.kt | 16 ++- .../casting/operators/spells/OpRecharge.kt | 26 ++--- .../operators/spells/great/OpCreateLava.kt | 4 +- .../operators/spells/great/OpFlight.kt | 19 ++-- .../operators/spells/great/OpTeleport.kt | 5 +- .../spells/sentinel/OpCreateSentinel.kt | 7 +- .../spells/sentinel/OpDestroySentinel.kt | 9 +- .../spells/sentinel/OpGetSentinelPos.kt | 6 +- .../spells/sentinel/OpGetSentinelWayfind.kt | 6 +- .../hexcasting/common/lib/HexBlocks.java | 8 +- .../common/misc/AkashicTreeGrower.java | 12 +-- .../{ => accessor}/AccessorLivingEntity.java | 2 +- .../mixin/accessor/AccessorUseOnContext.java | 21 ++++ .../mixin/client/AccessorItemProperties.java | 15 +++ .../petrak/hexcasting/server/TickScheduler.kt | 32 ------ .../xplat/IClientXplatAbstractions.java | 8 -- Common/src/main/resources/hexplat.mixins.json | 7 +- .../hexcasting/FabricHexClientInitializer.kt | 3 + .../petrak/hexcasting/FabricHexInitializer.kt | 4 +- .../hexcasting/fabric/mixin/AxeItemMixin.java | 25 +++++ .../fabric/xplat/FabricClientXplatImpl.java | 9 -- .../main/resources/fabricasting.mixins.json | 4 +- .../hexcasting/ForgeHexClientInitializer.java | 3 + .../petrak/hexcasting/ForgeHexInitializer.kt | 10 +- .../hexcasting/forge/ForgeOnlyEvents.java | 17 +++ .../forge/xplat/ForgeClientXplatImpl.java | 9 -- 51 files changed, 284 insertions(+), 411 deletions(-) create mode 100644 Common/src/main/java/at/petrak/hexcasting/api/misc/TriPredicate.java delete mode 100644 Common/src/main/java/at/petrak/hexcasting/api/mod/HexApiItems.java delete mode 100644 Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicWood.java rename Common/src/main/java/at/petrak/hexcasting/common/{recipe => blocks/behavior}/HexComposting.java (92%) create mode 100644 Common/src/main/java/at/petrak/hexcasting/common/blocks/behavior/HexStrippables.java delete mode 100644 Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockStrippable.java rename Common/src/main/java/at/petrak/hexcasting/mixin/{ => accessor}/AccessorLivingEntity.java (87%) create mode 100644 Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorUseOnContext.java create mode 100644 Common/src/main/java/at/petrak/hexcasting/mixin/client/AccessorItemProperties.java delete mode 100644 Common/src/main/java/at/petrak/hexcasting/server/TickScheduler.kt create mode 100644 Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/AxeItemMixin.java diff --git a/Common/src/main/java/at/petrak/hexcasting/api/misc/FrozenColorizer.java b/Common/src/main/java/at/petrak/hexcasting/api/misc/FrozenColorizer.java index 6df3e381..2ec1154f 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/misc/FrozenColorizer.java +++ b/Common/src/main/java/at/petrak/hexcasting/api/misc/FrozenColorizer.java @@ -48,11 +48,6 @@ public record FrozenColorizer(ItemStack item, UUID owner) { } } - @Deprecated - public static boolean isColorizer(ItemStack stack) { - return IXplatAbstractions.INSTANCE.isColorizer(stack); - } - /** * Gets a color with a minimum luminance applied. * diff --git a/Common/src/main/java/at/petrak/hexcasting/api/misc/TriPredicate.java b/Common/src/main/java/at/petrak/hexcasting/api/misc/TriPredicate.java new file mode 100644 index 00000000..04f70220 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/api/misc/TriPredicate.java @@ -0,0 +1,9 @@ +package at.petrak.hexcasting.api.misc; + +/** + * Society if java actually had first-class function support + */ +@FunctionalInterface +public interface TriPredicate { + boolean test(A a, B b, C c); +} diff --git a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexApiItems.java b/Common/src/main/java/at/petrak/hexcasting/api/mod/HexApiItems.java deleted file mode 100644 index e7cb41c2..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/api/mod/HexApiItems.java +++ /dev/null @@ -1,102 +0,0 @@ -package at.petrak.hexcasting.api.mod; - -import net.minecraft.world.item.DyeColor; -import net.minecraft.world.item.Item; -import net.minecraftforge.registries.ObjectHolder; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings("ConstantConditions") -@ApiStatus.Internal -@ObjectHolder("hexcasting") -public class HexApiItems { - - @NotNull - @ObjectHolder("dye_colorizer_white") - public static final Item COLORIZER_WHITE = null; - - @NotNull - @ObjectHolder("dye_colorizer_orange") - public static final Item COLORIZER_ORANGE = null; - - @NotNull - @ObjectHolder("dye_colorizer_magenta") - public static final Item COLORIZER_MAGENTA = null; - - @NotNull - @ObjectHolder("dye_colorizer_light_blue") - public static final Item COLORIZER_LIGHT_BLUE = null; - - @NotNull - @ObjectHolder("dye_colorizer_yellow") - public static final Item COLORIZER_YELLOW = null; - - @NotNull - @ObjectHolder("dye_colorizer_lime") - public static final Item COLORIZER_LIME = null; - - @NotNull - @ObjectHolder("dye_colorizer_pink") - public static final Item COLORIZER_PINK = null; - - @NotNull - @ObjectHolder("dye_colorizer_gray") - public static final Item COLORIZER_GRAY = null; - - @NotNull - @ObjectHolder("dye_colorizer_light_gray") - public static final Item COLORIZER_LIGHT_GRAY = null; - - @NotNull - @ObjectHolder("dye_colorizer_cyan") - public static final Item COLORIZER_CYAN = null; - - @NotNull - @ObjectHolder("dye_colorizer_purple") - public static final Item COLORIZER_PURPLE = null; - - @NotNull - @ObjectHolder("dye_colorizer_blue") - public static final Item COLORIZER_BLUE = null; - - @NotNull - @ObjectHolder("dye_colorizer_brown") - public static final Item COLORIZER_BROWN = null; - - @NotNull - @ObjectHolder("dye_colorizer_green") - public static final Item COLORIZER_GREEN = null; - - @NotNull - @ObjectHolder("dye_colorizer_red") - public static final Item COLORIZER_RED = null; - - @NotNull - @ObjectHolder("dye_colorizer_black") - public static final Item COLORIZER_BLACK = null; - - @NotNull - @ObjectHolder("amethyst_dust") - public static final Item AMETHYST_DUST = null; - - public static Item getColorizer(DyeColor color) { - return switch (color) { - case WHITE -> COLORIZER_WHITE; - case ORANGE -> COLORIZER_ORANGE; - case MAGENTA -> COLORIZER_MAGENTA; - case LIGHT_BLUE -> COLORIZER_LIGHT_BLUE; - case YELLOW -> COLORIZER_YELLOW; - case LIME -> COLORIZER_LIME; - case PINK -> COLORIZER_PINK; - case GRAY -> COLORIZER_GRAY; - case LIGHT_GRAY -> COLORIZER_LIGHT_GRAY; - case CYAN -> COLORIZER_CYAN; - case PURPLE -> COLORIZER_PURPLE; - case BLUE -> COLORIZER_BLUE; - case BROWN -> COLORIZER_BROWN; - case GREEN -> COLORIZER_GREEN; - case RED -> COLORIZER_RED; - default -> COLORIZER_BLACK; - }; - } -} diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexCoord.kt b/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexCoord.kt index f9ca2905..82506f0e 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexCoord.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexCoord.kt @@ -7,7 +7,6 @@ import kotlin.math.min /** * Uses axial coordinates as per https://www.redblobgames.com/grids/hexagons/ */ -@JvmRecord data class HexCoord(val q: Int, val r: Int) { fun s(): Int = this.q - this.r diff --git a/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexPattern.kt b/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexPattern.kt index 666c5658..469f897a 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexPattern.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/spell/math/HexPattern.kt @@ -10,7 +10,6 @@ import net.minecraft.world.phys.Vec2 /** * Sequence of angles to define a pattern traced. */ -@JvmRecord data class HexPattern(val startDir: HexDir, val angles: MutableList = arrayListOf()) { /** * @return True if it successfully appended, false if not. @@ -131,7 +130,10 @@ data class HexPattern(val startDir: HexDir, val angles: MutableList = @JvmStatic fun IsHexPattern(tag: CompoundTag): Boolean { - return tag.contains(TAG_START_DIR, Tag.TAG_ANY_NUMERIC.toInt()) && tag.contains(TAG_ANGLES, Tag.TAG_BYTE_ARRAY.toInt()) + return tag.contains(TAG_START_DIR, Tag.TAG_ANY_NUMERIC.toInt()) && tag.contains( + TAG_ANGLES, + Tag.TAG_BYTE_ARRAY.toInt() + ) } @JvmStatic diff --git a/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java b/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java index 7ca571e7..25355ba0 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/ClientTickCounter.java @@ -1,14 +1,10 @@ package at.petrak.hexcasting.client; -import net.minecraftforge.event.TickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; - // I can't find a better way to do this :( public class ClientTickCounter { private static long tickCount = 0; - @SubscribeEvent - public static void onTick(TickEvent.ClientTickEvent evt) { + public static void onTick() { tickCount++; } diff --git a/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java b/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java index f8d8e44d..eb518198 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java +++ b/Common/src/main/java/at/petrak/hexcasting/client/RegisterClientStuff.java @@ -25,6 +25,7 @@ import at.petrak.hexcasting.common.lib.HexBlockEntities; import at.petrak.hexcasting.common.lib.HexBlocks; import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexParticles; +import at.petrak.hexcasting.mixin.client.AccessorItemProperties; import at.petrak.hexcasting.xplat.IClientXplatAbstractions; import com.mojang.datafixers.util.Pair; import net.minecraft.ChatFormatting; @@ -56,23 +57,22 @@ public class RegisterClientStuff { registerPackagedSpellOverrides(HexItems.TRINKET); registerPackagedSpellOverrides(HexItems.ARTIFACT); - IClientXplatAbstractions x = IClientXplatAbstractions.INSTANCE; - x.registerItemProperty(HexItems.BATTERY, ItemManaBattery.MANA_PREDICATE, + AccessorItemProperties.hex$register(HexItems.BATTERY, ItemManaBattery.MANA_PREDICATE, (stack, level, holder, holderID) -> { var item = (ManaHolderItem) stack.getItem(); return item.getManaFullness(stack); }); - x.registerItemProperty(HexItems.BATTERY, ItemManaBattery.MAX_MANA_PREDICATE, + AccessorItemProperties.hex$register(HexItems.BATTERY, ItemManaBattery.MAX_MANA_PREDICATE, (stack, level, holder, holderID) -> { var item = (ItemManaBattery) stack.getItem(); var max = item.getMaxMana(stack); return (float) Math.sqrt((float) max / HexConfig.common().chargedCrystalManaAmount() / 10); }); - x.registerItemProperty(HexItems.SCROLL, ItemScroll.ANCIENT_PREDICATE, + AccessorItemProperties.hex$register(HexItems.SCROLL, ItemScroll.ANCIENT_PREDICATE, (stack, level, holder, holderID) -> stack.getOrCreateTag().contains(ItemScroll.TAG_OP_ID) ? 1f : 0f); - x.registerItemProperty(HexItems.SLATE, ItemSlate.WRITTEN_PRED, + AccessorItemProperties.hex$register(HexItems.SLATE, ItemSlate.WRITTEN_PRED, (stack, level, holder, holderID) -> ItemSlate.hasPattern(stack) ? 1f : 0f); registerWandOverrides(HexItems.WAND_OAK); @@ -85,6 +85,7 @@ public class RegisterClientStuff { HexTooltips.init(); + IClientXplatAbstractions x = IClientXplatAbstractions.INSTANCE; x.setRenderLayer(HexBlocks.CONJURED_LIGHT, RenderType.cutout()); x.setRenderLayer(HexBlocks.CONJURED_BLOCK, RenderType.cutout()); x.setRenderLayer(HexBlocks.AKASHIC_DOOR, RenderType.cutout()); @@ -192,7 +193,7 @@ public class RegisterClientStuff { } private static void registerDataHolderOverrides(DataHolderItem item) { - IClientXplatAbstractions.INSTANCE.registerItemProperty((Item) item, ItemFocus.DATATYPE_PRED, + AccessorItemProperties.hex$register((Item) item, ItemFocus.DATATYPE_PRED, (stack, level, holder, holderID) -> { var datum = item.readDatumTag(stack); if (datum != null) { @@ -209,19 +210,19 @@ public class RegisterClientStuff { } return 0f; }); - IClientXplatAbstractions.INSTANCE.registerItemProperty((Item) item, ItemFocus.SEALED_PRED, + AccessorItemProperties.hex$register((Item) item, ItemFocus.SEALED_PRED, (stack, level, holder, holderID) -> item.canWrite(stack, SpellDatum.make(Widget.NULL)) ? 0f : 1f); } private static void registerPackagedSpellOverrides(ItemPackagedHex item) { - IClientXplatAbstractions.INSTANCE.registerItemProperty(item, ItemPackagedHex.HAS_PATTERNS_PRED, + AccessorItemProperties.hex$register(item, ItemPackagedHex.HAS_PATTERNS_PRED, (stack, level, holder, holderID) -> item.getPatterns(stack) != null ? 1f : 0f ); } private static void registerWandOverrides(ItemWand item) { - IClientXplatAbstractions.INSTANCE.registerItemProperty(item, ItemWand.FUNNY_LEVEL_PREDICATE, + AccessorItemProperties.hex$register(item, ItemWand.FUNNY_LEVEL_PREDICATE, (stack, level, holder, holderID) -> { var name = stack.getHoverName().getString().toLowerCase(Locale.ROOT); if (name.contains("old")) { diff --git a/Common/src/main/java/at/petrak/hexcasting/client/RenderLib.kt b/Common/src/main/java/at/petrak/hexcasting/client/RenderLib.kt index 036231bf..fb138d77 100644 --- a/Common/src/main/java/at/petrak/hexcasting/client/RenderLib.kt +++ b/Common/src/main/java/at/petrak/hexcasting/client/RenderLib.kt @@ -1,8 +1,8 @@ package at.petrak.hexcasting.client import at.petrak.hexcasting.api.mod.HexConfig -import at.petrak.hexcasting.api.utils.HexUtils import at.petrak.hexcasting.api.spell.math.HexPattern +import at.petrak.hexcasting.api.utils.HexUtils import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.vertex.DefaultVertexFormat import com.mojang.blaze3d.vertex.PoseStack @@ -52,7 +52,7 @@ object RenderLib { val g1 = FC.green(tail).toFloat() val b1 = FC.blue(tail).toFloat() val a = FC.alpha(tail) - val headSource = if (Screen.hasControlDown() != HexConfig.Client.ctrlTogglesOffStrokeOrder.get()) + val headSource = if (Screen.hasControlDown() != HexConfig.client().ctrlTogglesOffStrokeOrder()) head else tail @@ -99,7 +99,7 @@ object RenderLib { if (animTime != null) { val pointCircuit = - (animTime * 30f * HexConfig.Client.patternPointSpeedMultiplier.get().toFloat()) % (points.size + 10) + (animTime * 30f * HexConfig.client().patternPointSpeedMultiplier().toFloat()) % (points.size + 10) // subtract 1 to avoid the point appearing between the end and start for 1 frame if (pointCircuit < points.size - 1) { val pointMacro = floor(pointCircuit).toInt() diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicFloodfiller.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicFloodfiller.java index e23bdb36..a5132a60 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicFloodfiller.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicFloodfiller.java @@ -1,12 +1,12 @@ package at.petrak.hexcasting.common.blocks.akashic; +import at.petrak.hexcasting.api.misc.TriPredicate; import at.petrak.hexcasting.common.lib.HexBlocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.util.TriPredicate; import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; @@ -20,7 +20,7 @@ public class BlockAkashicFloodfiller extends Block { public @Nullable BlockPos getRecordPosition(BlockPos here, BlockState state, Level world) { return floodFillFor(here, world, - (pos, bs, level) -> bs.is(HexBlocks.AKASHIC_RECORD.get())); + (pos, bs, level) -> bs.is(HexBlocks.AKASHIC_RECORD)); } @Override diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicWood.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicWood.java deleted file mode 100644 index 2813ce25..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicWood.java +++ /dev/null @@ -1,31 +0,0 @@ -package at.petrak.hexcasting.common.blocks.akashic; - -import at.petrak.hexcasting.common.blocks.decoration.BlockStrippable; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; - -import java.util.function.Supplier; - -public class BlockAkashicWood extends BlockStrippable { - public BlockAkashicWood(Properties props, Supplier stripped) { - super(props, stripped); - } - - @Override - public boolean isFlammable(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { - return true; - } - - @Override - public int getFlammability(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { - return 5; - } - - @Override - public int getFireSpreadSpeed(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { - return 5; - } -} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/recipe/HexComposting.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/behavior/HexComposting.java similarity index 92% rename from Common/src/main/java/at/petrak/hexcasting/common/recipe/HexComposting.java rename to Common/src/main/java/at/petrak/hexcasting/common/blocks/behavior/HexComposting.java index 54c5700f..277cfa31 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/recipe/HexComposting.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/behavior/HexComposting.java @@ -1,4 +1,4 @@ -package at.petrak.hexcasting.common.recipe; +package at.petrak.hexcasting.common.blocks.behavior; import at.petrak.hexcasting.common.lib.HexBlocks; import net.minecraft.world.item.Item; diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/behavior/HexStrippables.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/behavior/HexStrippables.java new file mode 100644 index 00000000..7865dcb2 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/behavior/HexStrippables.java @@ -0,0 +1,16 @@ +package at.petrak.hexcasting.common.blocks.behavior; + +import at.petrak.hexcasting.common.lib.HexBlocks; +import net.minecraft.world.level.block.Block; + +import java.util.HashMap; +import java.util.Map; + +public class HexStrippables { + public static final Map STRIPPABLES = new HashMap<>(); + + public static void init() { + STRIPPABLES.put(HexBlocks.AKASHIC_LOG, HexBlocks.AKASHIC_LOG_STRIPPED); + STRIPPABLES.put(HexBlocks.AKASHIC_WOOD, HexBlocks.AKASHIC_WOOD_STRIPPED); + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java index 6aa16819..5788ca72 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java @@ -1,10 +1,10 @@ package at.petrak.hexcasting.common.blocks.circles.impetuses; import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus; -import at.petrak.hexcasting.api.cap.HexCapabilities; import at.petrak.hexcasting.api.spell.DatumType; import at.petrak.hexcasting.common.blocks.entity.BlockEntityStoredPlayerImpetus; import at.petrak.hexcasting.common.lib.HexSounds; +import at.petrak.hexcasting.xplat.IXplatAbstractions; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -36,10 +36,10 @@ public class BlockStoredPlayerImpetus extends BlockAbstractImpetus { BlockHitResult pHit) { if (pLevel.getBlockEntity(pPos) instanceof BlockEntityStoredPlayerImpetus tile) { var usedStack = pPlayer.getItemInHand(pHand); - var datumContainer = usedStack.getCapability(HexCapabilities.DATUM).resolve(); - if (datumContainer.isPresent()) { + var datumContainer = IXplatAbstractions.INSTANCE.findDataHolder(usedStack); + if (datumContainer != null) { if (pLevel instanceof ServerLevel level) { - var stored = datumContainer.get().readDatum(level); + var stored = datumContainer.readDatum(level); if (stored != null && stored.getType() == DatumType.ENTITY) { var entity = (Entity) stored.getPayload(); if (entity instanceof Player) { @@ -47,7 +47,7 @@ public class BlockStoredPlayerImpetus extends BlockAbstractImpetus { tile.setPlayer(entity.getUUID()); tile.setChanged(); - pLevel.playSound(pPlayer, pPos, HexSounds.IMPETUS_STOREDPLAYER_DING.get(), + pLevel.playSound(pPlayer, pPos, HexSounds.IMPETUS_STOREDPLAYER_DING, SoundSource.BLOCKS, 1f, 1f); } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockStrippable.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockStrippable.java deleted file mode 100644 index 0c7a3ee9..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/decoration/BlockStrippable.java +++ /dev/null @@ -1,40 +0,0 @@ -package at.petrak.hexcasting.common.blocks.decoration; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.RotatedPillarBlock; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.ToolAction; -import net.minecraftforge.common.ToolActions; - -import javax.annotation.Nullable; -import java.util.function.Supplier; - -// aka, Blockg -// https://github.com/SammySemicolon/Malum-Mod/blob/1.18.1/src/main/java/com/sammy/malum/common/block/misc/MalumLogBlock.java -public class BlockStrippable extends RotatedPillarBlock { - public final Supplier stripped; - - public BlockStrippable(Properties p_55926_, Supplier stripped) { - super(p_55926_); - this.stripped = stripped; - } - - @Nullable - @Override - public BlockState getToolModifiedState(BlockState state, Level world, BlockPos pos, Player player, ItemStack stack, - ToolAction toolAction) { - if (toolAction == ToolActions.AXE_STRIP) { - var out = stripped.get().defaultBlockState(); - if (state.hasProperty(AXIS)) { - out = out.setValue(AXIS, state.getValue(AXIS)); - } - return out; - } else { - return null; - } - } -} diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpRead.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpRead.kt index 47f039b6..8ef48601 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpRead.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpRead.kt @@ -4,23 +4,22 @@ import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem -import at.petrak.hexcasting.forge.cap.HexCapabilities +import at.petrak.hexcasting.xplat.IXplatAbstractions object OpRead : ConstManaOperator { override val argc = 0 override fun execute(args: List>, ctx: CastingContext): List> { val (handStack, hand) = ctx.getHeldItemToOperateOn { - val datum = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() - datum.isPresent && (datum.get().readDatum(ctx.world) != null || datum.get().emptyDatum() != null) + val dataHolder = IXplatAbstractions.INSTANCE.findDataHolder(it) + dataHolder != null && (dataHolder.readDatum(ctx.world) != null || dataHolder.emptyDatum() != null) } - val datumHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() - if (!datumHolder.isPresent) - throw MishapBadOffhandItem.of(handStack, hand, "iota.read") + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) + ?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read") - val datum = datumHolder.get().readDatum(ctx.world) - ?: datumHolder.get().emptyDatum() + val datum = datumHolder.readDatum(ctx.world) + ?: datumHolder.emptyDatum() ?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read") return listOf(datum) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpTheCoolerRead.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpTheCoolerRead.kt index 7dc29dd9..7da065fe 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpTheCoolerRead.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpTheCoolerRead.kt @@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem -import at.petrak.hexcasting.forge.cap.HexCapabilities +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.world.entity.item.ItemEntity object OpTheCoolerRead : ConstManaOperator { @@ -17,15 +17,14 @@ object OpTheCoolerRead : ConstManaOperator { ): List> { val target = args.getChecked(0) val stack = target.item - val datumHolder = stack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() - if (!datumHolder.isPresent) - throw MishapBadItem.of(target, "iota.read") + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack) + ?: throw MishapBadItem.of(target, "iota.read") ctx.assertEntityInRange(target) - val datum = datumHolder.get().readDatum(ctx.world) - ?: datumHolder.get().emptyDatum() + val datum = datumHolder.readDatum(ctx.world) + ?: datumHolder.emptyDatum() ?: throw MishapBadItem.of(target, "iota.read") return listOf(datum) } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpWrite.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpWrite.kt index bc7c252a..969c8100 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpWrite.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/OpWrite.kt @@ -7,7 +7,7 @@ import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.spell.mishaps.MishapOthersName -import at.petrak.hexcasting.forge.cap.HexCapabilities +import at.petrak.hexcasting.xplat.IXplatAbstractions // we make this a spell cause imo it's a little ... anticlimactic for it to just make no noise object OpWrite : SpellOperator { @@ -19,16 +19,15 @@ object OpWrite : SpellOperator { val datum = args[0] val (handStack, hand) = ctx.getHeldItemToOperateOn { - val datumHolder = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it) - datumHolder.isPresent && datumHolder.get().writeDatum(datum, true) + datumHolder != null && datumHolder.writeDatum(datum, true) } - val datumHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() - if (!datumHolder.isPresent) - throw MishapBadOffhandItem.of(handStack, hand, "iota.write") + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) + ?: throw MishapBadOffhandItem.of(handStack, hand, "iota.write") - if (!datumHolder.get().writeDatum(datum, true)) + if (!datumHolder.writeDatum(datum, true)) throw MishapBadOffhandItem.of(handStack, hand, "iota.readonly", datum.display()) val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster) @@ -45,16 +44,13 @@ object OpWrite : SpellOperator { private data class Spell(val datum: SpellDatum<*>) : RenderedSpell { override fun cast(ctx: CastingContext) { val (handStack) = ctx.getHeldItemToOperateOn { - val datumHolder = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it) - datumHolder.isPresent && datumHolder.get().writeDatum(datum, true) + datumHolder != null && datumHolder.writeDatum(datum, true) } - val datumHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() - - if (datumHolder.isPresent) { - datumHolder.get().writeDatum(datum, false) - } + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) + datumHolder?.writeDatum(datum, false) } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpColorize.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpColorize.kt index 271ddbd4..b450e628 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpColorize.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpColorize.kt @@ -1,13 +1,13 @@ package at.petrak.hexcasting.common.casting.operators.spells +import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext -import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem -import at.petrak.hexcasting.api.player.HexPlayerDataHelper +import at.petrak.hexcasting.xplat.IXplatAbstractions object OpColorize : SpellOperator { override val argc = 0 @@ -16,8 +16,8 @@ object OpColorize : SpellOperator { args: List>, ctx: CastingContext ): Triple> { - val (handStack, hand) = ctx.getHeldItemToOperateOn { FrozenColorizer.isColorizer(it) } - if (!FrozenColorizer.isColorizer(handStack)) { + val (handStack, hand) = ctx.getHeldItemToOperateOn(IXplatAbstractions.INSTANCE::isColorizer) + if (!IXplatAbstractions.INSTANCE.isColorizer(handStack)) { throw MishapBadOffhandItem.of( handStack, hand, @@ -33,10 +33,11 @@ object OpColorize : SpellOperator { private object Spell : RenderedSpell { override fun cast(ctx: CastingContext) { - val handStack = ctx.getHeldItemToOperateOn { FrozenColorizer.isColorizer(it) }.first.copy() - if (FrozenColorizer.isColorizer(handStack)) { + val handStack = ctx.getHeldItemToOperateOn(IXplatAbstractions.INSTANCE::isColorizer).first.copy() + if (IXplatAbstractions.INSTANCE.isColorizer(handStack)) { if (ctx.withdrawItem(handStack.item, 1, true)) { - HexPlayerDataHelper.setColorizer(ctx.caster, + IXplatAbstractions.INSTANCE.setColorizer( + ctx.caster, FrozenColorizer(handStack, ctx.caster.uuid) ) } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpConjure.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpConjure.kt index 41999b9a..4ced7c9c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpConjure.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpConjure.kt @@ -5,10 +5,10 @@ import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator +import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.common.blocks.BlockConjured import at.petrak.hexcasting.common.lib.HexBlocks -import at.petrak.hexcasting.api.spell.casting.CastingContext -import at.petrak.hexcasting.api.player.HexPlayerDataHelper +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.world.item.ItemStack @@ -43,11 +43,11 @@ class OpConjure(val light: Boolean) : SpellOperator { val worldState = ctx.world.getBlockState(pos) if (worldState.canBeReplaced(placeContext)) { val block = if (this.light) HexBlocks.CONJURED_LIGHT else HexBlocks.CONJURED_BLOCK - val state = block.get().getStateForPlacement(placeContext) + val state = block.getStateForPlacement(placeContext) if (state != null) { ctx.world.setBlock(pos, state, 5) - val colorizer = HexPlayerDataHelper.getColorizer(ctx.caster) + val colorizer = IXplatAbstractions.INSTANCE.getColorizer(ctx.caster) if (ctx.world.getBlockState(pos).block is BlockConjured) { BlockConjured.setColor(ctx.world, pos, colorizer) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt index 841120e9..6428d0ec 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpCreateWater.kt @@ -1,6 +1,6 @@ package at.petrak.hexcasting.common.casting.operators.spells -import at.petrak.hexcasting.HexMod +import at.petrak.hexcasting.api.HexAPI import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.RenderedSpell @@ -40,7 +40,7 @@ object OpCreateWater : SpellOperator { // make the player null so we don't give them a usage statistic for example charlie.emptyContents(null, ctx.world, pos, null) } else { - HexMod.getLogger().warn("Items.WATER_BUCKET wasn't a BucketItem?") + HexAPI.LOGGER.warn("Items.WATER_BUCKET wasn't a BucketItem?") } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpErase.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpErase.kt index 61c6fcdd..5bb451f3 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpErase.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpErase.kt @@ -6,7 +6,7 @@ import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem -import at.petrak.hexcasting.forge.cap.HexCapabilities +import at.petrak.hexcasting.xplat.IXplatAbstractions class OpErase : SpellOperator { override val argc = 0 @@ -16,18 +16,19 @@ class OpErase : SpellOperator { ctx: CastingContext ): Triple> { val (handStack, hand) = ctx.getHeldItemToOperateOn { - val spellHolder = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.SPELL).resolve() - val datumHolder = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() + val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(it) + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it) - (spellHolder.isPresent && spellHolder.get().patterns != null) || - (datumHolder.isPresent && datumHolder.get().writeDatum(null, true)) + (hexHolder?.patterns != null) || + (datumHolder?.writeDatum(null, true) ?: false) } - val spellHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.SPELL).resolve() - val datumHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() + val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack) + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) - if ((!spellHolder.isPresent || spellHolder.get().patterns == null) && - (!datumHolder.isPresent || datumHolder.get().readDatum(ctx.world) == null || - !datumHolder.get().writeDatum(null, true)) + if ((hexHolder?.patterns == null) && + (datumHolder == null + || datumHolder.readDatum(ctx.world) == null + || !datumHolder.writeDatum(null, true)) ) { throw MishapBadOffhandItem.of(handStack, hand, "eraseable") } @@ -38,20 +39,19 @@ class OpErase : SpellOperator { private object Spell : RenderedSpell { override fun cast(ctx: CastingContext) { val (handStack) = ctx.getHeldItemToOperateOn { - val spellHolder = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.SPELL).resolve() - val datumHolder = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() + val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(it) + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it) - (spellHolder.isPresent && spellHolder.get().patterns != null) || - (datumHolder.isPresent && datumHolder.get().writeDatum(null, true)) + (hexHolder?.patterns != null) || + (datumHolder?.writeDatum(null, true) ?: false) } - val spellHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.SPELL).resolve() - val datumHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.DATUM).resolve() + val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack) + val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) + if (hexHolder?.patterns != null) + hexHolder.clearPatterns() - if (spellHolder.isPresent && spellHolder.get().patterns != null) - spellHolder.get().clearPatterns() - - if (datumHolder.isPresent && datumHolder.get().writeDatum(null, true)) - datumHolder.get().writeDatum(null, false) + if (datumHolder != null && datumHolder.writeDatum(null, true)) + datumHolder.writeDatum(null, false) } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpExtinguish.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpExtinguish.kt index 196beea2..c9ac15b4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpExtinguish.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpExtinguish.kt @@ -3,6 +3,7 @@ package at.petrak.hexcasting.common.casting.operators.spells import at.petrak.hexcasting.api.spell.* import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked import at.petrak.hexcasting.api.spell.casting.CastingContext +import at.petrak.hexcasting.mixin.accessor.AccessorUseOnContext import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.core.particles.ParticleTypes @@ -11,7 +12,6 @@ import net.minecraft.sounds.SoundSource import net.minecraft.world.InteractionHand import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items -import net.minecraft.world.item.context.UseOnContext import net.minecraft.world.level.block.* import net.minecraft.world.phys.BlockHitResult import net.minecraft.world.phys.Vec3 @@ -55,7 +55,11 @@ object OpExtinguish : SpellOperator { here.z.toDouble() ) ) // max distance to prevent runaway shenanigans - if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && distFromTarget < 10 && ctx.world.mayInteract(ctx.caster, here)) { + if (distFromFocus < Operator.MAX_DISTANCE * Operator.MAX_DISTANCE && seen.add(here) && distFromTarget < 10 && ctx.world.mayInteract( + ctx.caster, + here + ) + ) { // never seen this pos in my life val blockstate = ctx.world.getBlockState(here) val success = @@ -68,7 +72,7 @@ object OpExtinguish : SpellOperator { val wilson = Items.WOODEN_SHOVEL // summon shovel from the ether to do our bidding val hereVec = (Vec3(here.x.toDouble(), here.y.toDouble(), here.z.toDouble())) wilson.useOn( - UseOnContext( + AccessorUseOnContext.`hex$new`( ctx.world, null, InteractionHand.MAIN_HAND, diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpIgnite.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpIgnite.kt index 0428d0ef..31bbe6ea 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpIgnite.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpIgnite.kt @@ -1,19 +1,19 @@ package at.petrak.hexcasting.common.casting.operators.spells -import at.petrak.hexcasting.HexMod +import at.petrak.hexcasting.api.HexAPI import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext +import at.petrak.hexcasting.mixin.accessor.AccessorUseOnContext import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.world.InteractionHand import net.minecraft.world.item.FireChargeItem import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items -import net.minecraft.world.item.context.UseOnContext import net.minecraft.world.phys.BlockHitResult import net.minecraft.world.phys.Vec3 @@ -44,7 +44,7 @@ object OpIgnite : SpellOperator { if (maxwell is FireChargeItem) { // help maxwell.useOn( - UseOnContext( + AccessorUseOnContext.`hex$new`( ctx.world, null, InteractionHand.MAIN_HAND, @@ -53,7 +53,7 @@ object OpIgnite : SpellOperator { ) ) } else { - HexMod.getLogger().warn("Items.FIRE_CHARGE wasn't a FireChargeItem?") + HexAPI.LOGGER.warn("Items.FIRE_CHARGE wasn't a FireChargeItem?") } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt index 99c91370..1fc5a6ad 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakeBattery.kt @@ -10,8 +10,8 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.utils.ManaHelper -import at.petrak.hexcasting.common.lib.HexItems import at.petrak.hexcasting.common.items.magic.ItemManaHolder +import at.petrak.hexcasting.common.lib.HexItems import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.item.ItemStack @@ -66,7 +66,7 @@ object OpMakeBattery : SpellOperator { if (manaAmt > 0) { ctx.caster.setItemInHand( hand, - ItemManaHolder.withMana(ItemStack(HexItems.BATTERY.get()), manaAmt, manaAmt) + ItemManaHolder.withMana(ItemStack(HexItems.BATTERY), manaAmt, manaAmt) ) } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt index 20f8695e..8fd0dc8b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpMakePackagedSpell.kt @@ -12,7 +12,7 @@ import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota import at.petrak.hexcasting.api.utils.ManaHelper import at.petrak.hexcasting.common.items.magic.ItemPackagedHex -import at.petrak.hexcasting.forge.cap.HexCapabilities +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.network.chat.TranslatableComponent import net.minecraft.world.entity.item.ItemEntity @@ -54,15 +54,15 @@ class OpMakePackagedSpell(val itemType: T, val cost: Int) : private inner class Spell(val itemEntity: ItemEntity, val patterns: List) : RenderedSpell { override fun cast(ctx: CastingContext) { val (handStack) = ctx.getHeldItemToOperateOn { it.`is`(itemType) } - val spellHolder = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.SPELL).resolve() - if (spellHolder.isPresent - && spellHolder.get().patterns == null + val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack) + if (hexHolder != null + && hexHolder.patterns == null && itemEntity.isAlive ) { val entityStack = itemEntity.item.copy() val manaAmt = ManaHelper.extractMana(entityStack, drainForBatteries = true) if (manaAmt > 0) { - spellHolder.get().writePatterns(patterns, manaAmt) + hexHolder.writePatterns(patterns, manaAmt) } itemEntity.item = entityStack diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt index 70df9c79..8f146ed8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpPlaceBlock.kt @@ -15,9 +15,6 @@ import net.minecraft.world.item.BlockItem import net.minecraft.world.item.context.UseOnContext import net.minecraft.world.phys.BlockHitResult import net.minecraft.world.phys.Vec3 -import net.minecraftforge.common.MinecraftForge -import net.minecraftforge.common.util.BlockSnapshot -import net.minecraftforge.event.world.BlockEvent object OpPlaceBlock : SpellOperator { override val argc: Int @@ -52,12 +49,13 @@ object OpPlaceBlock : SpellOperator { val placee = placeeStack.item as BlockItem if (ctx.withdrawItem(placee, 1, false)) { // https://github.com/VazkiiMods/Psi/blob/master/src/main/java/vazkii/psi/common/spell/trick/block/PieceTrickPlaceBlock.java#L143 - val evt = BlockEvent.EntityPlaceEvent( - BlockSnapshot.create(ctx.world.dimension(), ctx.world, pos), - ctx.world.getBlockState(pos.above()), - ctx.caster - ) - MinecraftForge.EVENT_BUS.post(evt) + // TODO do we need to add this back somehow + // val evt = BlockEvent.EntityPlaceEvent( + // BlockSnapshot.create(ctx.world.dimension(), ctx.world, pos), + // ctx.world.getBlockState(pos.above()), + // ctx.caster + // ) + // MinecraftForge.EVENT_BUS.post(evt) // we temporarily give the player the stack, place it using mc code, then give them the old stack back. val oldStack = ctx.caster.getItemInHand(ctx.castingHand) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt index 983159f6..b4ac75af 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/OpRecharge.kt @@ -9,7 +9,7 @@ import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.utils.ManaHelper -import at.petrak.hexcasting.forge.cap.HexCapabilities +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.world.entity.item.ItemEntity object OpRecharge : SpellOperator { @@ -19,13 +19,13 @@ object OpRecharge : SpellOperator { ctx: CastingContext ): Triple>? { val (handStack, hand) = ctx.getHeldItemToOperateOn { - val mana = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).resolve() - mana.isPresent && mana.get().canRecharge() && mana.get().mana < mana.get().maxMana + val mana = IXplatAbstractions.INSTANCE.findManaHolder(it) + mana != null && mana.canRecharge() && mana.mana /* doo doo da do doo */ < mana.maxMana } - val mana = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).resolve() + val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack) - if (!mana.isPresent || !mana.get().canRecharge()) + if (mana == null || !mana.canRecharge()) throw MishapBadOffhandItem.of( handStack, hand, @@ -42,7 +42,7 @@ object OpRecharge : SpellOperator { ) } - if (mana.get().mana >= mana.get().maxMana) + if (mana.mana >= mana.maxMana) return null return Triple(Spell(entity), 100_000, listOf(ParticleSpray.Burst(entity.position(), 0.5))) @@ -51,20 +51,20 @@ object OpRecharge : SpellOperator { private data class Spell(val itemEntity: ItemEntity) : RenderedSpell { override fun cast(ctx: CastingContext) { val (handStack) = ctx.getHeldItemToOperateOn { - val mana = it.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).resolve() - mana.isPresent && mana.get().canRecharge() && mana.get().mana < mana.get().maxMana + val mana = IXplatAbstractions.INSTANCE.findManaHolder(it) + mana != null && mana.canRecharge() && mana.mana < mana.maxMana } - val mana = handStack.getCapability(at.petrak.hexcasting.forge.cap.HexCapabilities.MANA).resolve() + val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack) - if (mana.isPresent && itemEntity.isAlive) { + if (mana != null && itemEntity.isAlive) { val entityStack = itemEntity.item.copy() - val maxMana = mana.get().maxMana - val existingMana = mana.get().mana + val maxMana = mana.maxMana + val existingMana = mana.mana val manaAmt = ManaHelper.extractMana(entityStack, maxMana - existingMana) - mana.get().mana = manaAmt + existingMana + mana.mana = manaAmt + existingMana itemEntity.item = entityStack if (entityStack.isEmpty) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt index 336e0924..1da29944 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpCreateLava.kt @@ -1,6 +1,6 @@ package at.petrak.hexcasting.common.casting.operators.spells.great -import at.petrak.hexcasting.HexMod +import at.petrak.hexcasting.api.HexAPI import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.RenderedSpell @@ -42,7 +42,7 @@ object OpCreateLava : SpellOperator { // make the player null so we don't give them a usage statistic for example charlie.emptyContents(null, ctx.world, pos, null) } else { - HexMod.getLogger().warn("Items.LAVA_BUCKET wasn't a BucketItem?") + HexAPI.LOGGER.warn("Items.LAVA_BUCKET wasn't a BucketItem?") } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpFlight.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpFlight.kt index 248f1926..3f25ccec 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpFlight.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpFlight.kt @@ -7,11 +7,10 @@ import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext -import at.petrak.hexcasting.api.player.HexPlayerDataHelper +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.server.level.ServerPlayer +import net.minecraft.world.entity.LivingEntity import net.minecraft.world.phys.Vec3 -import net.minecraftforge.event.entity.living.LivingEvent -import net.minecraftforge.eventbus.api.SubscribeEvent import kotlin.math.max import kotlin.math.roundToInt @@ -43,7 +42,8 @@ object OpFlight : SpellOperator { return } - HexPlayerDataHelper.setFlight(target, + IXplatAbstractions.INSTANCE.setFlight( + target, FlightAbility( true, time, @@ -61,12 +61,10 @@ object OpFlight : SpellOperator { } } - @SubscribeEvent - fun tickDownFlight(evt: LivingEvent.LivingUpdateEvent) { - val entity = evt.entityLiving + fun tickDownFlight(entity: LivingEntity) { if (entity !is ServerPlayer) return - val flight = HexPlayerDataHelper.getFlight(entity) + val flight = IXplatAbstractions.INSTANCE.getFlight(entity) if (flight.allowed) { val flightTime = flight.timeLeft - 1 @@ -74,7 +72,7 @@ object OpFlight : SpellOperator { if (!entity.isOnGround) { entity.fallDistance = 1_000_000f } - HexPlayerDataHelper.setFlight(entity, FlightAbility.deny()) + IXplatAbstractions.INSTANCE.setFlight(entity, FlightAbility.deny()) if (!entity.isCreative && !entity.isSpectator) { val abilities = entity.abilities @@ -83,7 +81,8 @@ object OpFlight : SpellOperator { entity.onUpdateAbilities() } } else - HexPlayerDataHelper.setFlight(entity, + IXplatAbstractions.INSTANCE.setFlight( + entity, FlightAbility( true, flightTime, diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpTeleport.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpTeleport.kt index 73d1fdbc..ed868bb9 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpTeleport.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/great/OpTeleport.kt @@ -7,12 +7,11 @@ import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapImmuneEntity -import at.petrak.hexcasting.common.lib.HexMessages import at.petrak.hexcasting.common.network.MsgBlinkAck +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.server.level.ServerPlayer import net.minecraft.world.entity.Entity import net.minecraft.world.phys.Vec3 -import net.minecraftforge.network.PacketDistributor object OpTeleport : SpellOperator { override val argc = 2 @@ -45,7 +44,7 @@ object OpTeleport : SpellOperator { if (distance < 32768.0) { teleportee.setPos(teleportee.position().add(delta)) if (teleportee is ServerPlayer) { - HexMessages.getNetwork().send(PacketDistributor.PLAYER.with { teleportee }, MsgBlinkAck(delta)) + IXplatAbstractions.INSTANCE.sendPacketToPlayer(teleportee, MsgBlinkAck(delta)) } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpCreateSentinel.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpCreateSentinel.kt index 786ed74c..466063c5 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpCreateSentinel.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpCreateSentinel.kt @@ -1,13 +1,13 @@ package at.petrak.hexcasting.common.casting.operators.spells.sentinel +import at.petrak.hexcasting.api.player.Sentinel import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext -import at.petrak.hexcasting.api.player.HexPlayerDataHelper -import at.petrak.hexcasting.api.player.Sentinel +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.world.phys.Vec3 class OpCreateSentinel(val extendsRange: Boolean) : SpellOperator { @@ -30,7 +30,8 @@ class OpCreateSentinel(val extendsRange: Boolean) : SpellOperator { private data class Spell(val target: Vec3, val extendsRange: Boolean) : RenderedSpell { override fun cast(ctx: CastingContext) { - HexPlayerDataHelper.setSentinel(ctx.caster, + IXplatAbstractions.INSTANCE.setSentinel( + ctx.caster, Sentinel( true, extendsRange, diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpDestroySentinel.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpDestroySentinel.kt index 354d7141..9948ff78 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpDestroySentinel.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpDestroySentinel.kt @@ -1,13 +1,13 @@ package at.petrak.hexcasting.common.casting.operators.spells.sentinel +import at.petrak.hexcasting.api.player.Sentinel import at.petrak.hexcasting.api.spell.ParticleSpray import at.petrak.hexcasting.api.spell.RenderedSpell import at.petrak.hexcasting.api.spell.SpellDatum import at.petrak.hexcasting.api.spell.SpellOperator import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapLocationInWrongDimension -import at.petrak.hexcasting.api.player.HexPlayerDataHelper -import at.petrak.hexcasting.api.player.Sentinel +import at.petrak.hexcasting.xplat.IXplatAbstractions object OpDestroySentinel : SpellOperator { override val argc = 0 @@ -16,7 +16,8 @@ object OpDestroySentinel : SpellOperator { ctx: CastingContext ): Triple> { val particles = mutableListOf() - val sentinel = HexPlayerDataHelper.getSentinel(ctx.caster) + val sentinel = IXplatAbstractions.INSTANCE.getSentinel(ctx.caster) + // TODO why can't you remove things from other dimensions? if (sentinel.dimension != ctx.world.dimension()) throw MishapLocationInWrongDimension(sentinel.dimension.location()) particles.add(ParticleSpray.Cloud(sentinel.position, 2.0)) @@ -30,7 +31,7 @@ object OpDestroySentinel : SpellOperator { private object Spell : RenderedSpell { override fun cast(ctx: CastingContext) { - HexPlayerDataHelper.setSentinel(ctx.caster, Sentinel.none()) + IXplatAbstractions.INSTANCE.setSentinel(ctx.caster, Sentinel.none()) } } } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelPos.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelPos.kt index 50ae2d23..9534be7c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelPos.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelPos.kt @@ -3,16 +3,16 @@ package at.petrak.hexcasting.common.casting.operators.spells.sentinel import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf import at.petrak.hexcasting.api.spell.SpellDatum -import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.Widget +import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapLocationInWrongDimension -import at.petrak.hexcasting.api.player.HexPlayerDataHelper +import at.petrak.hexcasting.xplat.IXplatAbstractions object OpGetSentinelPos : ConstManaOperator { override val argc = 0 override val manaCost = 1_000 override fun execute(args: List>, ctx: CastingContext): List> { - val sentinel = HexPlayerDataHelper.getSentinel(ctx.caster) + val sentinel = IXplatAbstractions.INSTANCE.getSentinel(ctx.caster) if (sentinel.dimension != ctx.world.dimension()) throw MishapLocationInWrongDimension(sentinel.dimension.location()) return spellListOf( diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelWayfind.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelWayfind.kt index 124e08da..3b51e752 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelWayfind.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/operators/spells/sentinel/OpGetSentinelWayfind.kt @@ -4,10 +4,10 @@ import at.petrak.hexcasting.api.spell.ConstManaOperator import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf import at.petrak.hexcasting.api.spell.SpellDatum -import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.Widget +import at.petrak.hexcasting.api.spell.casting.CastingContext import at.petrak.hexcasting.api.spell.mishaps.MishapLocationInWrongDimension -import at.petrak.hexcasting.api.player.HexPlayerDataHelper +import at.petrak.hexcasting.xplat.IXplatAbstractions import net.minecraft.world.phys.Vec3 object OpGetSentinelWayfind : ConstManaOperator { @@ -16,7 +16,7 @@ object OpGetSentinelWayfind : ConstManaOperator { override fun execute(args: List>, ctx: CastingContext): List> { val from = args.getChecked(0) - val sentinel = HexPlayerDataHelper.getSentinel(ctx.caster) + val sentinel = IXplatAbstractions.INSTANCE.getSentinel(ctx.caster) if (sentinel.dimension != ctx.world.dimension()) throw MishapLocationInWrongDimension(sentinel.dimension.location()) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java index a32764aa..1af3871f 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexBlocks.java @@ -170,12 +170,12 @@ public class HexBlocks { public static final BlockAxis AKASHIC_LOG_STRIPPED = blockItem("akashic_log_stripped", new BlockAkashicLog(akashicWoody())); - public static final BlockStrippable AKASHIC_LOG = blockItem("akashic_log", - new BlockAkashicWood(akashicWoody(), () -> AKASHIC_LOG_STRIPPED)); + public static final Block AKASHIC_LOG = blockItem("akashic_log", + IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 5, 5)); public static final Block AKASHIC_WOOD_STRIPPED = blockItem("akashic_wood_stripped", IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 5, 5)); - public static final BlockStrippable AKASHIC_WOOD = blockItem("akashic_wood", - new BlockStrippable(akashicWoody(), () -> AKASHIC_WOOD_STRIPPED)); + public static final Block AKASHIC_WOOD = blockItem("akashic_log", + IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 5, 5)); public static final Block AKASHIC_PLANKS = blockItem("akashic_planks", IXplatAbstractions.INSTANCE.makeFlammable(akashicWoody(), 20, 5)); public static final Block AKASHIC_PANEL = blockItem("akashic_panel", diff --git a/Common/src/main/java/at/petrak/hexcasting/common/misc/AkashicTreeGrower.java b/Common/src/main/java/at/petrak/hexcasting/common/misc/AkashicTreeGrower.java index bd8f1770..71f56cdc 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/misc/AkashicTreeGrower.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/misc/AkashicTreeGrower.java @@ -1,6 +1,6 @@ package at.petrak.hexcasting.common.misc; -import at.petrak.hexcasting.HexMod; +import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.common.lib.HexBlocks; import com.google.common.collect.Lists; import net.minecraft.core.Holder; @@ -27,15 +27,15 @@ public class AkashicTreeGrower extends AbstractTreeGrower { public static final List>> GROWERS = Lists.newArrayList(); static { - GROWERS.add(buildTreeFeature(HexBlocks.AKASHIC_LEAVES1.get(), "1")); - GROWERS.add(buildTreeFeature(HexBlocks.AKASHIC_LEAVES2.get(), "2")); - GROWERS.add(buildTreeFeature(HexBlocks.AKASHIC_LEAVES3.get(), "3")); + GROWERS.add(buildTreeFeature(HexBlocks.AKASHIC_LEAVES1, "1")); + GROWERS.add(buildTreeFeature(HexBlocks.AKASHIC_LEAVES2, "2")); + GROWERS.add(buildTreeFeature(HexBlocks.AKASHIC_LEAVES3, "3")); } private static Holder> buildTreeFeature(Block leaves, String name) { - return FeatureUtils.register(HexMod.MOD_ID + ":akashic_tree" + name, Feature.TREE, + return FeatureUtils.register(HexAPI.MOD_ID + ":akashic_tree" + name, Feature.TREE, new TreeConfiguration.TreeConfigurationBuilder( - BlockStateProvider.simple(HexBlocks.AKASHIC_LOG.get()), + BlockStateProvider.simple(HexBlocks.AKASHIC_LOG), // baseHeight, heightRandA, heightRandB new FancyTrunkPlacer(5, 5, 3), BlockStateProvider.simple(leaves), diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/AccessorLivingEntity.java b/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorLivingEntity.java similarity index 87% rename from Common/src/main/java/at/petrak/hexcasting/mixin/AccessorLivingEntity.java rename to Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorLivingEntity.java index eb845d24..2331d9fc 100644 --- a/Common/src/main/java/at/petrak/hexcasting/mixin/AccessorLivingEntity.java +++ b/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorLivingEntity.java @@ -1,4 +1,4 @@ -package at.petrak.hexcasting.mixin; +package at.petrak.hexcasting.mixin.accessor; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.Brain; diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorUseOnContext.java b/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorUseOnContext.java new file mode 100644 index 00000000..1cf59b94 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/mixin/accessor/AccessorUseOnContext.java @@ -0,0 +1,21 @@ +package at.petrak.hexcasting.mixin.accessor; + +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.phys.BlockHitResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import javax.annotation.Nullable; + +@Mixin(UseOnContext.class) +public interface AccessorUseOnContext { + @Invoker("") + static UseOnContext hex$new(Level $$0, @Nullable Player $$1, InteractionHand $$2, ItemStack $$3, + BlockHitResult $$4) { + throw new IllegalStateException(); + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/client/AccessorItemProperties.java b/Common/src/main/java/at/petrak/hexcasting/mixin/client/AccessorItemProperties.java new file mode 100644 index 00000000..cb366351 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/mixin/client/AccessorItemProperties.java @@ -0,0 +1,15 @@ +package at.petrak.hexcasting.mixin.client; + +import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(ItemProperties.class) +public interface AccessorItemProperties { + @Invoker("register") + static void hex$register(Item $$0, ResourceLocation $$1, ClampedItemPropertyFunction $$2) { + } +} diff --git a/Common/src/main/java/at/petrak/hexcasting/server/TickScheduler.kt b/Common/src/main/java/at/petrak/hexcasting/server/TickScheduler.kt deleted file mode 100644 index 5614cd79..00000000 --- a/Common/src/main/java/at/petrak/hexcasting/server/TickScheduler.kt +++ /dev/null @@ -1,32 +0,0 @@ -package at.petrak.hexcasting.server - -import net.minecraftforge.event.TickEvent -import net.minecraftforge.eventbus.api.SubscribeEvent -import java.util.* - -object TickScheduler { - val tasks: MutableList = LinkedList() - - fun schedule(task: Task) { - this.tasks.add(task) - } - - fun schedule(ticks: Int, task: Runnable) { - this.tasks.add(Task(ticks, task)) - } - - @SubscribeEvent - fun onTick(evt: TickEvent.ServerTickEvent) { - this.tasks.removeIf { - it.ticks-- - if (it.ticks <= 0) { - it.task.run() - true - } else { - false - } - } - } - - data class Task(var ticks: Int, val task: Runnable) -} \ No newline at end of file diff --git a/Common/src/main/java/at/petrak/hexcasting/xplat/IClientXplatAbstractions.java b/Common/src/main/java/at/petrak/hexcasting/xplat/IClientXplatAbstractions.java index d17f56df..0334c1d4 100644 --- a/Common/src/main/java/at/petrak/hexcasting/xplat/IClientXplatAbstractions.java +++ b/Common/src/main/java/at/petrak/hexcasting/xplat/IClientXplatAbstractions.java @@ -6,13 +6,10 @@ import net.minecraft.client.particle.ParticleProvider; import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import java.util.ServiceLoader; @@ -22,11 +19,6 @@ import java.util.stream.Collectors; public interface IClientXplatAbstractions { void sendPacketToServer(IMessage packet); - // The funny thing is both forge and fabric separately access widen the SAME FUNCTION - // but i can't use it without xplat cause it's not widened in common - // waa - void registerItemProperty(Item item, ResourceLocation id, ClampedItemPropertyFunction func); - void setRenderLayer(Block block, RenderType type); void registerEntityRenderer(EntityType type, EntityRendererProvider renderer); diff --git a/Common/src/main/resources/hexplat.mixins.json b/Common/src/main/resources/hexplat.mixins.json index 28d419c5..cc7102ef 100644 --- a/Common/src/main/resources/hexplat.mixins.json +++ b/Common/src/main/resources/hexplat.mixins.json @@ -4,9 +4,6 @@ "compatibilityLevel": "JAVA_17", "refmap": "hexcasting.mixins.refmap.json", "package": "at.petrak.hexcasting.mixin", - "mixins": [ - "AccessorLivingEntity", - "MixinMob", - "MixinVillager" - ] + "mixins": ["MixinMob", "MixinVillager", "accessor.AccessorLivingEntity", "accessor.AccessorUseOnContext"], + "client": ["client.AccessorItemProperties"] } diff --git a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt index 6e89822d..f9737274 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt +++ b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt @@ -1,7 +1,9 @@ +import at.petrak.hexcasting.client.ClientTickCounter import at.petrak.hexcasting.client.HexAdditionalRenderers import at.petrak.hexcasting.client.RegisterClientStuff import at.petrak.hexcasting.fabric.network.FabricPacketHandler import net.fabricmc.api.ClientModInitializer +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents @@ -13,6 +15,7 @@ object FabricHexClientInitializer : ClientModInitializer { HexAdditionalRenderers.overlayLevel(ctx.matrixStack(), ctx.tickDelta()) } HudRenderCallback.EVENT.register(HexAdditionalRenderers::overlayGui) + ClientTickEvents.START_CLIENT_TICK.register { ClientTickCounter.onTick() } RegisterClientStuff.init() RegisterClientStuff.registerParticles() diff --git a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt index e94aa91c..30cb6610 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt +++ b/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt @@ -1,9 +1,10 @@ import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers +import at.petrak.hexcasting.common.blocks.behavior.HexComposting +import at.petrak.hexcasting.common.blocks.behavior.HexStrippables import at.petrak.hexcasting.common.casting.RegisterPatterns import at.petrak.hexcasting.common.command.PatternResLocArgument import at.petrak.hexcasting.common.lib.* import at.petrak.hexcasting.common.misc.Brainsweeping -import at.petrak.hexcasting.common.recipe.HexComposting import at.petrak.hexcasting.fabric.FabricHexConfig import at.petrak.hexcasting.fabric.event.VillagerConversionCallback import at.petrak.hexcasting.fabric.network.FabricPacketHandler @@ -32,6 +33,7 @@ object FabricHexInitializer : ModInitializer { RegisterPatterns.registerPatterns() HexAdvancementTriggers.registerTriggers() HexComposting.setup() + HexStrippables.init() } fun initListeners() { diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/AxeItemMixin.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/AxeItemMixin.java new file mode 100644 index 00000000..d0b42a5e --- /dev/null +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/mixin/AxeItemMixin.java @@ -0,0 +1,25 @@ +package at.petrak.hexcasting.fabric.mixin; + +import at.petrak.hexcasting.common.blocks.behavior.HexStrippables; +import net.minecraft.world.item.AxeItem; +import net.minecraft.world.level.block.state.BlockState; +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.CallbackInfoReturnable; + +import java.util.Optional; + +// https://github.com/VazkiiMods/Botania/blob/1.18.x/Fabric/src/main/java/vazkii/botania/fabric/mixin/FabricMixinAxeItem.java +@Mixin(AxeItem.class) +public class AxeItemMixin { + @Inject(method = "getStripped", at = @At("RETURN"), cancellable = true) + private void stripBlock(BlockState state, CallbackInfoReturnable> cir) { + if (cir.getReturnValue().isEmpty()) { + var block = HexStrippables.STRIPPABLES.get(state.getBlock()); + if (block != null) { + cir.setReturnValue(Optional.of(block.withPropertiesOf(state))); + } + } + } +} diff --git a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java index 749505c6..bc51a54a 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/xplat/FabricClientXplatImpl.java @@ -10,14 +10,10 @@ import net.minecraft.client.particle.ParticleProvider; import net.minecraft.client.particle.SpriteSet; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; -import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import java.util.function.Function; @@ -28,11 +24,6 @@ public class FabricClientXplatImpl implements IClientXplatAbstractions { ClientPlayNetworking.send(packet.getFabricId(), packet.toBuf()); } - @Override - public void registerItemProperty(Item item, ResourceLocation id, ClampedItemPropertyFunction func) { - ItemProperties.register(item, id, func); - } - @Override public void setRenderLayer(Block block, RenderType type) { BlockRenderLayerMap.INSTANCE.putBlock(block, type); diff --git a/Fabric/src/main/resources/fabricasting.mixins.json b/Fabric/src/main/resources/fabricasting.mixins.json index 51fa4af7..bb0bd89d 100644 --- a/Fabric/src/main/resources/fabricasting.mixins.json +++ b/Fabric/src/main/resources/fabricasting.mixins.json @@ -4,7 +4,5 @@ "compatibilityLevel": "JAVA_17", "refmap": "hexcasting.mixins.refmap.json", "package": "at.petrak.hexcasting.fabric.mixin", - "mixins": [ - "VillagerTurnIntoWitchMixin" - ] + "mixins": ["AxeItemMixin", "VillagerTurnIntoWitchMixin"] } diff --git a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexClientInitializer.java b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexClientInitializer.java index 7e2884ca..d110e8f4 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexClientInitializer.java +++ b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexClientInitializer.java @@ -1,5 +1,6 @@ package at.petrak.hexcasting; +import at.petrak.hexcasting.client.ClientTickCounter; import at.petrak.hexcasting.client.HexAdditionalRenderers; import at.petrak.hexcasting.client.RegisterClientStuff; import net.minecraftforge.client.event.EntityRenderersEvent; @@ -7,6 +8,7 @@ import net.minecraftforge.client.event.ParticleFactoryRegisterEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderLevelLastEvent; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; @@ -25,6 +27,7 @@ public class ForgeHexClientInitializer { HexAdditionalRenderers.overlayGui(e.getMatrixStack(), e.getPartialTicks())); evBus.addListener(EventPriority.LOWEST, (ParticleFactoryRegisterEvent e) -> RegisterClientStuff.registerParticles()); + evBus.addListener((TickEvent.ClientTickEvent e) -> ClientTickCounter.onTick()); } @SubscribeEvent diff --git a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt index e3f50770..9bcb88b8 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt +++ b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt @@ -4,11 +4,13 @@ import at.petrak.hexcasting.api.HexAPI import at.petrak.hexcasting.api.PatternRegistry import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers import at.petrak.hexcasting.api.mod.HexConfig +import at.petrak.hexcasting.common.blocks.behavior.HexComposting +import at.petrak.hexcasting.common.blocks.behavior.HexStrippables import at.petrak.hexcasting.common.casting.RegisterPatterns +import at.petrak.hexcasting.common.casting.operators.spells.great.OpFlight import at.petrak.hexcasting.common.command.PatternResLocArgument import at.petrak.hexcasting.common.lib.* import at.petrak.hexcasting.common.misc.Brainsweeping -import at.petrak.hexcasting.common.recipe.HexComposting import at.petrak.hexcasting.forge.ForgeHexConfig import at.petrak.hexcasting.forge.ForgeOnlyEvents import at.petrak.hexcasting.forge.cap.CapSyncers @@ -19,6 +21,7 @@ import net.minecraft.resources.ResourceLocation import net.minecraftforge.common.ForgeConfigSpec import net.minecraftforge.event.RegistryEvent import net.minecraftforge.event.entity.living.LivingConversionEvent +import net.minecraftforge.event.entity.living.LivingEvent import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract import net.minecraftforge.fml.ModLoadingContext import net.minecraftforge.fml.common.Mod @@ -88,6 +91,7 @@ object ForgeHexInitializer { evt.enqueueWork { ForgePacketHandler.init() HexComposting.setup() + HexStrippables.init() } } @@ -113,6 +117,10 @@ object ForgeHexInitializer { ) } + evBus.addListener { evt: LivingEvent.LivingUpdateEvent -> + OpFlight.tickDownFlight(evt.entityLiving) + } + evBus.register(CapSyncers::class.java) evBus.register(ForgeOnlyEvents::class.java) } diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeOnlyEvents.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeOnlyEvents.java index 15ff023a..f545738d 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeOnlyEvents.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeOnlyEvents.java @@ -1,15 +1,20 @@ package at.petrak.hexcasting.forge; +import at.petrak.hexcasting.common.blocks.behavior.HexStrippables; import at.petrak.hexcasting.forge.network.ForgePacketHandler; import at.petrak.hexcasting.forge.network.MsgBrainsweepAck; import at.petrak.hexcasting.xplat.IXplatAbstractions; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.ToolActions; import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; +// Events we don't need on fabric for whatever reasons public class ForgeOnlyEvents { // On Fabric this should be auto-synced @SubscribeEvent @@ -21,4 +26,16 @@ public class ForgeOnlyEvents { .send(PacketDistributor.PLAYER.with(() -> serverPlayer), MsgBrainsweepAck.of(mob)); } } + + // Implemented with a mixin + @SubscribeEvent + public static void stripBlock(BlockEvent.BlockToolModificationEvent evt) { + if (!evt.isSimulated() && evt.getToolAction() == ToolActions.AXE_STRIP) { + BlockState bs = evt.getState(); + var output = HexStrippables.STRIPPABLES.get(bs.getBlock()); + if (output != null) { + evt.setFinalState(output.withPropertiesOf(bs)); + } + } + } } diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java index 452e4087..81270f33 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/xplat/ForgeClientXplatImpl.java @@ -10,14 +10,10 @@ import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.EntityRenderers; -import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; -import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import java.util.function.Function; @@ -28,11 +24,6 @@ public class ForgeClientXplatImpl implements IClientXplatAbstractions { ForgePacketHandler.getNetwork().sendToServer(packet); } - @Override - public void registerItemProperty(Item item, ResourceLocation id, ClampedItemPropertyFunction func) { - ItemProperties.register(item, id, func); - } - @Override public void setRenderLayer(Block block, RenderType type) { ItemBlockRenderTypes.setRenderLayer(block, type);