This commit is contained in:
gamma-delta 2022-05-06 18:09:47 -05:00
parent fbf5f003c8
commit 4e3d3076a2
51 changed files with 284 additions and 411 deletions

View file

@ -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.
*

View file

@ -0,0 +1,9 @@
package at.petrak.hexcasting.api.misc;
/**
* Society if java actually had first-class function support
*/
@FunctionalInterface
public interface TriPredicate<A, B, C> {
boolean test(A a, B b, C c);
}

View file

@ -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;
};
}
}

View file

@ -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

View file

@ -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<HexAngle> = arrayListOf()) {
/**
* @return True if it successfully appended, false if not.
@ -131,7 +130,10 @@ data class HexPattern(val startDir: HexDir, val angles: MutableList<HexAngle> =
@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

View file

@ -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++;
}

View file

@ -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")) {

View file

@ -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()

View file

@ -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

View file

@ -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<? extends Block> 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;
}
}

View file

@ -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;

View file

@ -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<Block, Block> 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);
}
}

View file

@ -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);
}

View file

@ -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<? extends Block> stripped;
public BlockStrippable(Properties p_55926_, Supplier<? extends Block> 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;
}
}
}

View file

@ -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<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
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)

View file

@ -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<SpellDatum<*>> {
val target = args.getChecked<ItemEntity>(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)
}

View file

@ -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)
}
}

View file

@ -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<SpellDatum<*>>,
ctx: CastingContext
): Triple<RenderedSpell, Int, List<ParticleSpray>> {
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)
)
}

View file

@ -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)

View file

@ -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?")
}
}
}

View file

@ -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<RenderedSpell, Int, List<ParticleSpray>> {
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)
}
}
}

View file

@ -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,

View file

@ -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?")
}
}
}

View file

@ -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)
)
}

View file

@ -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<T : ItemPackagedHex>(val itemType: T, val cost: Int) :
private inner class Spell(val itemEntity: ItemEntity, val patterns: List<HexPattern>) : 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

View file

@ -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)

View file

@ -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<RenderedSpell, Int, List<ParticleSpray>>? {
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)

View file

@ -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?")
}
}
}

View file

@ -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,

View file

@ -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))
}
}

View file

@ -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,

View file

@ -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<RenderedSpell, Int, List<ParticleSpray>> {
val particles = mutableListOf<ParticleSpray>()
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())
}
}
}

View file

@ -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<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
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(

View file

@ -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<SpellDatum<*>>, ctx: CastingContext): List<SpellDatum<*>> {
val from = args.getChecked<Vec3>(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())

View file

@ -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",

View file

@ -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<Holder<ConfiguredFeature<TreeConfiguration, ?>>> 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<ConfiguredFeature<TreeConfiguration, ?>> 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),

View file

@ -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;

View file

@ -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("<init>")
static UseOnContext hex$new(Level $$0, @Nullable Player $$1, InteractionHand $$2, ItemStack $$3,
BlockHitResult $$4) {
throw new IllegalStateException();
}
}

View file

@ -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) {
}
}

View file

@ -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<Task> = 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)
}

View file

@ -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);
<T extends Entity> void registerEntityRenderer(EntityType<? extends T> type, EntityRendererProvider<T> renderer);

View file

@ -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"]
}

View file

@ -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()

View file

@ -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() {

View file

@ -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<Optional<BlockState>> cir) {
if (cir.getReturnValue().isEmpty()) {
var block = HexStrippables.STRIPPABLES.get(state.getBlock());
if (block != null) {
cir.setReturnValue(Optional.of(block.withPropertiesOf(state)));
}
}
}
}

View file

@ -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);

View file

@ -4,7 +4,5 @@
"compatibilityLevel": "JAVA_17",
"refmap": "hexcasting.mixins.refmap.json",
"package": "at.petrak.hexcasting.fabric.mixin",
"mixins": [
"VillagerTurnIntoWitchMixin"
]
"mixins": ["AxeItemMixin", "VillagerTurnIntoWitchMixin"]
}

View file

@ -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

View file

@ -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)
}

View file

@ -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));
}
}
}
}

View file

@ -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);