woot woot! fix bad maven deps and improve perf on colorizers

This commit is contained in:
petrak@ 2023-04-27 14:26:15 -05:00
parent c6612c547a
commit 697450dd66
62 changed files with 400 additions and 325 deletions

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.api;
import at.petrak.hexcasting.api.addldata.ADMediaHolder; import at.petrak.hexcasting.api.addldata.ADMediaHolder;
import at.petrak.hexcasting.api.casting.ActionRegistryEntry; import at.petrak.hexcasting.api.casting.ActionRegistryEntry;
import at.petrak.hexcasting.api.casting.castables.SpecialHandler; import at.petrak.hexcasting.api.casting.castables.SpecialHandler;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.player.Sentinel;
import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
@ -154,8 +154,8 @@ public interface HexAPI {
return null; return null;
} }
default FrozenColorizer getColorizer(Player player) { default FrozenPigment getColorizer(Player player) {
return FrozenColorizer.DEFAULT.get(); return FrozenPigment.DEFAULT.get();
} }
/** /**

View file

@ -1,5 +1,6 @@
package at.petrak.hexcasting.api.addldata; package at.petrak.hexcasting.api.addldata;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import net.minecraft.util.FastColor; import net.minecraft.util.FastColor;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -7,7 +8,7 @@ import net.minecraft.world.phys.Vec3;
import java.util.UUID; import java.util.UUID;
public interface ADColorizer { public interface ADColorizer {
int color(UUID owner, float time, Vec3 position); ColorProvider provideColor(UUID owner);
static int morphBetweenColors(int[] colors, Vec3 gradientDir, float time, Vec3 position) { static int morphBetweenColors(int[] colors, Vec3 gradientDir, float time, Vec3 position) {
float fIdx = Mth.positiveModulo(time + (float) gradientDir.dot(position), 1f) * colors.length; float fIdx = Mth.positiveModulo(time + (float) gradientDir.dot(position), 1f) * colors.length;

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.api.casting package at.petrak.hexcasting.api.casting
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.common.network.MsgCastParticleAck import at.petrak.hexcasting.common.network.MsgCastParticleAck
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.server.level.ServerLevel import net.minecraft.server.level.ServerLevel
@ -23,7 +23,7 @@ data class ParticleSpray(val pos: Vec3, val vel: Vec3, val fuzziness: Double, va
} }
} }
fun sprayParticles(world: ServerLevel, color: FrozenColorizer) { fun sprayParticles(world: ServerLevel, color: FrozenPigment) {
IXplatAbstractions.INSTANCE.sendPacketNear(this.pos, 128.0, world, MsgCastParticleAck(this, color)) IXplatAbstractions.INSTANCE.sendPacketNear(this.pos, 128.0, world, MsgCastParticleAck(this, color))
} }
} }

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.api.casting.circles;
import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv; import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexItems;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
@ -50,14 +50,14 @@ public class CircleExecutionState {
public Direction enteredFrom; public Direction enteredFrom;
public CastingImage currentImage; public CastingImage currentImage;
public @Nullable UUID caster; public @Nullable UUID caster;
public FrozenColorizer colorizer; public FrozenPigment colorizer;
public final AABB bounds; public final AABB bounds;
protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, Set<BlockPos> knownPositions, protected CircleExecutionState(BlockPos impetusPos, Direction impetusDir, Set<BlockPos> knownPositions,
List<BlockPos> reachedPositions, BlockPos currentPos, Direction enteredFrom, List<BlockPos> reachedPositions, BlockPos currentPos, Direction enteredFrom,
CastingImage currentImage, @Nullable UUID caster, FrozenColorizer colorizer) { CastingImage currentImage, @Nullable UUID caster, FrozenPigment colorizer) {
this.impetusPos = impetusPos; this.impetusPos = impetusPos;
this.impetusDir = impetusDir; this.impetusDir = impetusDir;
this.knownPositions = knownPositions; this.knownPositions = knownPositions;
@ -131,10 +131,10 @@ public class CircleExecutionState {
reachedPositions.add(impetus.getBlockPos()); reachedPositions.add(impetus.getBlockPos());
var start = seenGoodPositions.get(0); var start = seenGoodPositions.get(0);
FrozenColorizer colorizer; FrozenPigment colorizer;
UUID casterUUID; UUID casterUUID;
if (caster == null) { if (caster == null) {
colorizer = new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.PURPLE)), colorizer = new FrozenPigment(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.PURPLE)),
Util.NIL_UUID); Util.NIL_UUID);
casterUUID = null; casterUUID = null;
} else { } else {
@ -198,7 +198,7 @@ public class CircleExecutionState {
if (nbt.hasUUID(TAG_CASTER)) if (nbt.hasUUID(TAG_CASTER))
caster = nbt.getUUID(TAG_CASTER); caster = nbt.getUUID(TAG_CASTER);
FrozenColorizer colorizer = FrozenColorizer.fromNBT(nbt.getCompound(TAG_COLORIZER)); FrozenPigment colorizer = FrozenPigment.fromNBT(nbt.getCompound(TAG_COLORIZER));
return new CircleExecutionState(startPos, startDir, knownPositions, reachedPositions, currentPos, return new CircleExecutionState(startPos, startDir, knownPositions, reachedPositions, currentPos,
enteredFrom, image, caster, colorizer); enteredFrom, image, caster, colorizer);

View file

@ -4,7 +4,7 @@ import at.petrak.hexcasting.api.block.circle.BlockCircleComponent;
import at.petrak.hexcasting.api.casting.ParticleSpray; import at.petrak.hexcasting.api.casting.ParticleSpray;
import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv; import at.petrak.hexcasting.api.casting.eval.env.CircleCastEnv;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.common.lib.HexSounds; import at.petrak.hexcasting.common.lib.HexSounds;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
@ -60,7 +60,7 @@ public interface ICircleComponent {
*/ */
@Contract(pure = true) @Contract(pure = true)
EnumSet<Direction> possibleExitDirections(BlockPos pos, BlockState bs, Level world); EnumSet<Direction> possibleExitDirections(BlockPos pos, BlockState bs, Level world);
/** /**
* Given the current position and a direction, return a pair of the new position after a step * Given the current position and a direction, return a pair of the new position after a step
* in that direction, along with the direction (this is a helper function for creating * in that direction, along with the direction (this is a helper function for creating
@ -70,11 +70,12 @@ public interface ICircleComponent {
default Pair<BlockPos, Direction> exitPositionFromDirection(BlockPos pos, Direction dir) { default Pair<BlockPos, Direction> exitPositionFromDirection(BlockPos pos, Direction dir) {
return Pair.of(pos.offset(dir.getStepX(), dir.getStepY(), dir.getStepZ()), dir); return Pair.of(pos.offset(dir.getStepX(), dir.getStepY(), dir.getStepZ()), dir);
} }
/** /**
* Start the {@link ICircleComponent} at the given position glowing. Returns the new state * Start the {@link ICircleComponent} at the given position glowing. Returns the new state
* of the given block. * of the given block.
* // TODO: determine if this should just be in {@link ICircleComponent#acceptControlFlow(CastingImage, CircleCastEnv, Direction, BlockPos, BlockState, ServerLevel)}. * // TODO: determine if this should just be in
* {@link ICircleComponent#acceptControlFlow(CastingImage, CircleCastEnv, Direction, BlockPos, BlockState, ServerLevel)}.
*/ */
BlockState startEnergized(BlockPos pos, BlockState bs, Level world); BlockState startEnergized(BlockPos pos, BlockState bs, Level world);
@ -82,7 +83,7 @@ public interface ICircleComponent {
* Returns whether the {@link ICircleComponent} at the given position is energized. * Returns whether the {@link ICircleComponent} at the given position is energized.
*/ */
boolean isEnergized(BlockPos pos, BlockState bs, Level world); boolean isEnergized(BlockPos pos, BlockState bs, Level world);
/** /**
* End the {@link ICircleComponent} at the given position glowing. Returns the new state of * End the {@link ICircleComponent} at the given position glowing. Returns the new state of
* the given block. * the given block.
@ -92,13 +93,13 @@ public interface ICircleComponent {
static void sfx(BlockPos pos, BlockState bs, Level world, BlockEntityAbstractImpetus impetus, boolean success) { static void sfx(BlockPos pos, BlockState bs, Level world, BlockEntityAbstractImpetus impetus, boolean success) {
Vec3 vpos; Vec3 vpos;
Vec3 vecOutDir; Vec3 vecOutDir;
FrozenColorizer colorizer; FrozenPigment colorizer;
UUID activator = Util.NIL_UUID; UUID activator = Util.NIL_UUID;
if (impetus.getExecutionState() != null && impetus.getExecutionState().caster != null) if (impetus.getExecutionState() != null && impetus.getExecutionState().caster != null)
activator = impetus.getExecutionState().caster; activator = impetus.getExecutionState().caster;
if (impetus.getExecutionState() == null) if (impetus.getExecutionState() == null)
colorizer = new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.RED)), activator); colorizer = new FrozenPigment(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.RED)), activator);
else else
colorizer = impetus.getExecutionState().colorizer; colorizer = impetus.getExecutionState().colorizer;
@ -115,10 +116,10 @@ public interface ICircleComponent {
if (world instanceof ServerLevel serverLevel) { if (world instanceof ServerLevel serverLevel) {
var spray = new ParticleSpray(vpos, vecOutDir.scale(success ? 1.0 : 1.5), success ? 0.1 : 0.5, var spray = new ParticleSpray(vpos, vecOutDir.scale(success ? 1.0 : 1.5), success ? 0.1 : 0.5,
Mth.PI / (success ? 4 : 2), success ? 30 : 100); Mth.PI / (success ? 4 : 2), success ? 30 : 100);
spray.sprayParticles(serverLevel, spray.sprayParticles(serverLevel,
success ? colorizer : new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.RED)), success ? colorizer : new FrozenPigment(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.RED)),
activator)); activator));
} }
var pitch = 1f; var pitch = 1f;

View file

@ -6,8 +6,8 @@ import at.petrak.hexcasting.api.casting.mishaps.Mishap;
import at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation; import at.petrak.hexcasting.api.casting.mishaps.MishapBadLocation;
import at.petrak.hexcasting.api.casting.mishaps.MishapDisallowedSpell; import at.petrak.hexcasting.api.casting.mishaps.MishapDisallowedSpell;
import at.petrak.hexcasting.api.casting.mishaps.MishapEntityTooFarAway; import at.petrak.hexcasting.api.casting.mishaps.MishapEntityTooFarAway;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.mod.HexConfig; import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.api.utils.HexUtils;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -200,7 +200,7 @@ public abstract class CastingEnvironment {
return null; return null;
} }
public static record HeldItemInfo(ItemStack stack, @Nullable InteractionHand hand) { public record HeldItemInfo(ItemStack stack, @Nullable InteractionHand hand) {
public ItemStack component1() { public ItemStack component1() {
return stack; return stack;
} }
@ -225,12 +225,23 @@ public abstract class CastingEnvironment {
return null; return null;
} }
/**
* Whether to provide infinite items.
*/
protected boolean isCreativeMode() {
return false;
}
/** /**
* Attempt to withdraw some number of items from stacks available. * Attempt to withdraw some number of items from stacks available.
* <p> * <p>
* Return whether it was successful. * Return whether it was successful.
*/ */
public boolean withdrawItem(Predicate<ItemStack> stackOk, int count, boolean actuallyRemove) { public boolean withdrawItem(Predicate<ItemStack> stackOk, int count, boolean actuallyRemove) {
if (this.isCreativeMode()) {
return true;
}
var stacks = this.getUsableStacks(StackDiscoveryMode.EXTRACTION); var stacks = this.getUsableStacks(StackDiscoveryMode.EXTRACTION);
var presentCount = 0; var presentCount = 0;
@ -277,7 +288,7 @@ public abstract class CastingEnvironment {
EXTRACTION, EXTRACTION,
} }
public abstract FrozenColorizer getColorizer(); public abstract FrozenPigment getColorizer();
public abstract void produceParticles(ParticleSpray particles, FrozenColorizer colorizer); public abstract void produceParticles(ParticleSpray particles, FrozenPigment colorizer);
} }

View file

@ -7,7 +7,7 @@ import at.petrak.hexcasting.api.casting.circles.CircleExecutionState;
import at.petrak.hexcasting.api.casting.eval.CastResult; import at.petrak.hexcasting.api.casting.eval.CastResult;
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment; import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
import at.petrak.hexcasting.api.casting.eval.MishapEnvironment; import at.petrak.hexcasting.api.casting.eval.MishapEnvironment;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexItems;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -130,16 +130,16 @@ public class CircleCastEnv extends CastingEnvironment {
} }
@Override @Override
public FrozenColorizer getColorizer() { public FrozenPigment getColorizer() {
var out = this.getColorizerFromImpetus(); var out = this.getColorizerFromImpetus();
if (out != null) if (out != null)
return out; return out;
// TODO: colouriser from an adjacent inventory also? // TODO: colouriser from an adjacent inventory also?
return new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.PURPLE)), Util.NIL_UUID); return new FrozenPigment(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.PURPLE)), Util.NIL_UUID);
} }
private @Nullable FrozenColorizer getColorizerFromImpetus() { private @Nullable FrozenPigment getColorizerFromImpetus() {
var impetus = this.getImpetus(); var impetus = this.getImpetus();
if (impetus == null) if (impetus == null)
return null; return null;
@ -150,7 +150,7 @@ public class CircleCastEnv extends CastingEnvironment {
} }
@Override @Override
public void produceParticles(ParticleSpray particles, FrozenColorizer colorizer) { public void produceParticles(ParticleSpray particles, FrozenPigment colorizer) {
particles.sprayParticles(this.world, colorizer); particles.sprayParticles(this.world, colorizer);
} }
} }

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.api.casting.eval.env;
import at.petrak.hexcasting.api.casting.eval.CastResult; import at.petrak.hexcasting.api.casting.eval.CastResult;
import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound; import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds; import at.petrak.hexcasting.common.lib.hex.HexEvalSounds;
import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -53,7 +53,7 @@ public class PackagedItemCastEnv extends PlayerBasedCastEnv {
} }
@Override @Override
public FrozenColorizer getColorizer() { public FrozenPigment getColorizer() {
return null; return null;
} }
} }

View file

@ -9,10 +9,10 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
import at.petrak.hexcasting.api.casting.eval.MishapEnvironment; import at.petrak.hexcasting.api.casting.eval.MishapEnvironment;
import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect; import at.petrak.hexcasting.api.casting.eval.sideeffects.OperatorSideEffect;
import at.petrak.hexcasting.api.casting.mishaps.Mishap; import at.petrak.hexcasting.api.casting.mishaps.Mishap;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.misc.HexDamageSources; import at.petrak.hexcasting.api.misc.HexDamageSources;
import at.petrak.hexcasting.api.mod.HexConfig; import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.mod.HexStatistics; import at.petrak.hexcasting.api.mod.HexStatistics;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.api.utils.MediaHelper; import at.petrak.hexcasting.api.utils.MediaHelper;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -91,10 +91,11 @@ public abstract class PlayerBasedCastEnv extends CastingEnvironment {
var out = new ArrayList<ItemStack>(); var out = new ArrayList<ItemStack>();
// First, the inventory backwards // First, the inventory backwards
// We use inv.items here to get the main inventory, but not offhand or armor
Inventory inv = this.caster.getInventory(); Inventory inv = this.caster.getInventory();
for (int i = inv.getContainerSize(); i >= 0; i--) { for (int i = inv.items.size() - 1; i >= 0; i--) {
if (i != inv.selected) { if (i != inv.selected) {
out.add(inv.getItem(i)); out.add(inv.items.get(i));
} }
} }
@ -187,7 +188,7 @@ public abstract class PlayerBasedCastEnv extends CastingEnvironment {
} }
@Override @Override
public void produceParticles(ParticleSpray particles, FrozenColorizer colorizer) { public void produceParticles(ParticleSpray particles, FrozenPigment colorizer) {
particles.sprayParticles(this.world, colorizer); particles.sprayParticles(this.world, colorizer);
} }
@ -205,4 +206,10 @@ public abstract class PlayerBasedCastEnv extends CastingEnvironment {
var msg = mishap.getMishap().errorMessageWithName(this, mishap.getErrorCtx()); var msg = mishap.getMishap().errorMessageWithName(this, mishap.getErrorCtx());
this.caster.sendSystemMessage(msg); this.caster.sendSystemMessage(msg);
} }
@Override
protected boolean isCreativeMode() {
// not sure what the diff between this and isCreative() is
return this.caster.getAbilities().instabuild;
}
} }

View file

@ -1,13 +1,14 @@
package at.petrak.hexcasting.api.casting.eval.env; package at.petrak.hexcasting.api.casting.eval.env;
import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.casting.ParticleSpray;
import at.petrak.hexcasting.api.casting.eval.CastResult; import at.petrak.hexcasting.api.casting.eval.CastResult;
import at.petrak.hexcasting.api.casting.eval.ExecutionClientView; import at.petrak.hexcasting.api.casting.eval.ExecutionClientView;
import at.petrak.hexcasting.api.casting.eval.ResolvedPattern; import at.petrak.hexcasting.api.casting.eval.ResolvedPattern;
import at.petrak.hexcasting.api.casting.iota.PatternIota; import at.petrak.hexcasting.api.casting.iota.PatternIota;
import at.petrak.hexcasting.api.casting.math.HexCoord; import at.petrak.hexcasting.api.casting.math.HexCoord;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.mod.HexStatistics; import at.petrak.hexcasting.api.mod.HexStatistics;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.network.MsgNewSpellPatternAck; import at.petrak.hexcasting.common.network.MsgNewSpellPatternAck;
import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn; import at.petrak.hexcasting.common.network.MsgNewSpellPatternSyn;
import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatAbstractions;
@ -15,6 +16,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.phys.Vec3;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -61,7 +63,7 @@ public class StaffCastEnv extends PlayerBasedCastEnv {
} }
@Override @Override
public FrozenColorizer getColorizer() { public FrozenPigment getColorizer() {
return HexAPI.instance().getColorizer(this.caster); return HexAPI.instance().getColorizer(this.caster);
} }
@ -108,5 +110,12 @@ public class StaffCastEnv extends PlayerBasedCastEnv {
IXplatAbstractions.INSTANCE.sendPacketToPlayer(sender, IXplatAbstractions.INSTANCE.sendPacketToPlayer(sender,
new MsgNewSpellPatternAck(clientInfo, resolvedPatterns.size() - 1)); new MsgNewSpellPatternAck(clientInfo, resolvedPatterns.size() - 1));
if (clientInfo.getResolutionType().getSuccess()) {
// Somehow we lost spraying particles on each new pattern, so do it here
// this also nicely prevents particle spam on trinkets
new ParticleSpray(sender.position(), new Vec3(0.0, 1.5, 0.0), 0.4, Math.PI / 3, 30)
.sprayParticles(sender.getLevel(), IXplatAbstractions.INSTANCE.getColorizer(sender));
}
} }
} }

View file

@ -5,8 +5,8 @@ import at.petrak.hexcasting.api.casting.ParticleSpray
import at.petrak.hexcasting.api.casting.RenderedSpell import at.petrak.hexcasting.api.casting.RenderedSpell
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM import at.petrak.hexcasting.api.casting.eval.vm.CastingVM
import at.petrak.hexcasting.api.casting.mishaps.Mishap import at.petrak.hexcasting.api.casting.mishaps.Mishap
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.mod.HexStatistics import at.petrak.hexcasting.api.mod.HexStatistics
import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import at.petrak.hexcasting.common.lib.HexItems import at.petrak.hexcasting.common.lib.HexItems
import net.minecraft.Util import net.minecraft.Util
@ -57,7 +57,7 @@ sealed class OperatorSideEffect {
data class Particles(val spray: ParticleSpray) : OperatorSideEffect() { data class Particles(val spray: ParticleSpray) : OperatorSideEffect() {
override fun performEffect(harness: CastingVM): Boolean { override fun performEffect(harness: CastingVM): Boolean {
harness.env.produceParticles(this.spray, harness.env.colorizer) harness.env.produceParticles(this.spray, harness.env.colorizer)
this.spray.sprayParticles(harness.env.world, harness.env.colorizer) // this.spray.sprayParticles(harness.env.world, harness.env.colorizer)
return false return false
} }
@ -70,7 +70,7 @@ sealed class OperatorSideEffect {
spray.sprayParticles(harness.env.world, color) spray.sprayParticles(harness.env.world, color)
spray.sprayParticles( spray.sprayParticles(
harness.env.world, harness.env.world,
FrozenColorizer( FrozenPigment(
ItemStack(HexItems.DYE_COLORIZERS[DyeColor.RED]!!), ItemStack(HexItems.DYE_COLORIZERS[DyeColor.RED]!!),
Util.NIL_UUID Util.NIL_UUID
) )

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.math.HexPattern import at.petrak.hexcasting.api.casting.math.HexPattern
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import at.petrak.hexcasting.api.utils.lightPurple import at.petrak.hexcasting.api.utils.lightPurple
import at.petrak.hexcasting.common.lib.HexItems import at.petrak.hexcasting.common.lib.HexItems
@ -21,7 +21,7 @@ import net.minecraft.world.phys.Vec3
abstract class Mishap : Throwable() { abstract class Mishap : Throwable() {
/** Mishaps spray half-red, half-this-color. */ /** Mishaps spray half-red, half-this-color. */
abstract fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer abstract fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment
open fun particleSpray(ctx: CastingEnvironment): ParticleSpray { open fun particleSpray(ctx: CastingEnvironment): ParticleSpray {
return ParticleSpray( return ParticleSpray(
@ -54,8 +54,8 @@ abstract class Mishap : Throwable() {
// Useful helper functions // Useful helper functions
protected fun dyeColor(color: DyeColor): FrozenColorizer = protected fun dyeColor(color: DyeColor): FrozenPigment =
FrozenColorizer( FrozenPigment(
ItemStack(HexItems.DYE_COLORIZERS[color]!!), ItemStack(HexItems.DYE_COLORIZERS[color]!!),
Util.NIL_UUID Util.NIL_UUID
) )

View file

@ -1,15 +1,15 @@
package at.petrak.hexcasting.api.casting.mishaps package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.casting.ParticleSpray import at.petrak.hexcasting.api.casting.ParticleSpray
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.entity.Mob import net.minecraft.world.entity.Mob
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapAlreadyBrainswept(val mob: Mob) : Mishap() { class MishapAlreadyBrainswept(val mob: Mob) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GREEN) dyeColor(DyeColor.GREEN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -1,9 +1,9 @@
package at.petrak.hexcasting.api.casting.mishaps package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.casting.ParticleSpray import at.petrak.hexcasting.api.casting.ParticleSpray
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
@ -12,7 +12,7 @@ import net.minecraft.world.level.Explosion
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
class MishapBadBlock(val pos: BlockPos, val expected: Component) : Mishap() { class MishapBadBlock(val pos: BlockPos, val expected: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.LIME) dyeColor(DyeColor.LIME)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -3,15 +3,15 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.ParticleSpray import at.petrak.hexcasting.api.casting.ParticleSpray
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.HexDamageSources import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.world.entity.Mob import net.minecraft.world.entity.Mob
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
class MishapBadBrainsweep(val mob: Mob, val pos: BlockPos) : Mishap() { class MishapBadBrainsweep(val mob: Mob, val pos: BlockPos) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GREEN) dyeColor(DyeColor.GREEN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.aqua import at.petrak.hexcasting.api.utils.aqua
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
@ -11,7 +11,7 @@ import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapBadEntity(val entity: Entity, val wanted: Component) : Mishap() { class MishapBadEntity(val entity: Entity, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN) dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,14 +2,14 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.entity.item.ItemEntity import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapBadItem(val item: ItemEntity, val wanted: Component) : Mishap() { class MishapBadItem(val item: ItemEntity, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN) dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -3,13 +3,13 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.Vec3Iota import at.petrak.hexcasting.api.casting.iota.Vec3Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
import net.minecraft.world.phys.Vec3 import net.minecraft.world.phys.Vec3
class MishapBadLocation(val location: Vec3, val type: String = "too_far") : Mishap() { class MishapBadLocation(val location: Vec3, val type: String = "too_far") : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.MAGENTA) dyeColor(DyeColor.MAGENTA)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.InteractionHand import net.minecraft.world.InteractionHand
@ -10,7 +10,7 @@ import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
class MishapBadOffhandItem(val item: ItemStack, val hand: InteractionHand?, val wanted: Component) : Mishap() { class MishapBadOffhandItem(val item: ItemStack, val hand: InteractionHand?, val wanted: Component) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BROWN) dyeColor(DyeColor.BROWN)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -3,11 +3,11 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() { class MishapDisallowedSpell(val type: String = "disallowed") : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK) dyeColor(DyeColor.BLACK)
override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID

View file

@ -5,7 +5,7 @@ import at.petrak.hexcasting.api.casting.iota.DoubleIota
import at.petrak.hexcasting.api.casting.iota.GarbageIota import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.Vec3Iota import at.petrak.hexcasting.api.casting.iota.Vec3Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
@ -13,7 +13,7 @@ import net.minecraft.world.phys.Vec3
class MishapDivideByZero(val operand1: Component, val operand2: Component, val suffix: String = "divide") : Mishap() { class MishapDivideByZero(val operand1: Component, val operand2: Component, val suffix: String = "divide") : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.RED) dyeColor(DyeColor.RED)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,13 +2,13 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapEntityTooFarAway(val entity: Entity) : Mishap() { class MishapEntityTooFarAway(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.PINK) dyeColor(DyeColor.PINK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,11 +2,11 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapEvalTooMuch : Mishap() { class MishapEvalTooMuch : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLUE) dyeColor(DyeColor.BLUE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,13 +2,13 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.aqua import at.petrak.hexcasting.api.utils.aqua
import net.minecraft.world.entity.Entity import net.minecraft.world.entity.Entity
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapImmuneEntity(val entity: Entity) : Mishap() { class MishapImmuneEntity(val entity: Entity) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLUE) dyeColor(DyeColor.BLUE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,11 +2,11 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapInternalException(val exception: Exception) : Mishap() { class MishapInternalException(val exception: Exception) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK) dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.GarbageIota import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.utils.asTranslatedComponent import at.petrak.hexcasting.api.utils.asTranslatedComponent
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
@ -18,7 +18,7 @@ class MishapInvalidIota(
val reverseIdx: Int, val reverseIdx: Int,
val expected: Component val expected: Component
) : Mishap() { ) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY) dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -1,14 +1,14 @@
package at.petrak.hexcasting.api.casting.mishaps package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType import at.petrak.hexcasting.api.casting.eval.ResolvedPatternType
import at.petrak.hexcasting.api.casting.iota.GarbageIota import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapInvalidPattern : Mishap() { class MishapInvalidPattern : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.YELLOW) dyeColor(DyeColor.YELLOW)
override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID override fun resolutionType(ctx: CastingEnvironment) = ResolvedPatternType.INVALID

View file

@ -1,15 +1,15 @@
package at.petrak.hexcasting.api.casting.mishaps package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
/** /**
* this is bad * this is bad
*/ */
class MishapInvalidSpellDatumType(val perpetrator: Any) : Mishap() { class MishapInvalidSpellDatumType(val perpetrator: Any) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK) dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -3,13 +3,13 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.GarbageIota import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapLocationInWrongDimension(val properDimension: ResourceLocation) : Mishap() { class MishapLocationInWrongDimension(val properDimension: ResourceLocation) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.MAGENTA) dyeColor(DyeColor.MAGENTA)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,12 +2,12 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapNoAkashicRecord(val pos: BlockPos) : Mishap() { class MishapNoAkashicRecord(val pos: BlockPos) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.PURPLE) dyeColor(DyeColor.PURPLE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -2,14 +2,14 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.enchantment.EnchantmentHelper import net.minecraft.world.item.enchantment.EnchantmentHelper
class MishapNoSpellCircle : Mishap() { class MishapNoSpellCircle : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.LIGHT_BLUE) dyeColor(DyeColor.LIGHT_BLUE)
private inline fun dropAll(player: Player, stacks: MutableList<ItemStack>, filter: (ItemStack) -> Boolean = { true }) { private inline fun dropAll(player: Player, stacks: MutableList<ItemStack>, filter: (ItemStack) -> Boolean = { true }) {

View file

@ -3,11 +3,11 @@ package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.GarbageIota import at.petrak.hexcasting.api.casting.iota.GarbageIota
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapNotEnoughArgs(val expected: Int, val got: Int) : Mishap() { class MishapNotEnoughArgs(val expected: Int, val got: Int) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.LIGHT_GRAY) dyeColor(DyeColor.LIGHT_GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -4,7 +4,7 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.EntityIota import at.petrak.hexcasting.api.casting.iota.EntityIota
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.ListIota import at.petrak.hexcasting.api.casting.iota.ListIota
import at.petrak.hexcasting.api.misc.FrozenColorizer import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
@ -12,7 +12,7 @@ import net.minecraft.world.item.DyeColor
* Also throwable for your *own* name, for cases like Chronicler's Gambit * Also throwable for your *own* name, for cases like Chronicler's Gambit
*/ */
class MishapOthersName(val confidant: Player) : Mishap() { class MishapOthersName(val confidant: Player) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK) dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.api.casting.mishaps package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.HexDamageSources
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapShameOnYou() : Mishap() { class MishapShameOnYou() : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.BLACK) dyeColor(DyeColor.BLACK)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -1,13 +1,13 @@
package at.petrak.hexcasting.api.casting.mishaps package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.iota.PatternIota import at.petrak.hexcasting.api.casting.iota.PatternIota
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
class MishapTooManyCloseParens : Mishap() { class MishapTooManyCloseParens : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.ORANGE) dyeColor(DyeColor.ORANGE)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -1,8 +1,8 @@
package at.petrak.hexcasting.api.casting.mishaps package at.petrak.hexcasting.api.casting.mishaps
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.pigment.FrozenPigment
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
/** /**
@ -11,7 +11,7 @@ import net.minecraft.world.item.DyeColor
class MishapUnescapedValue( class MishapUnescapedValue(
val perpetrator: Iota val perpetrator: Iota
) : Mishap() { ) : Mishap() {
override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenColorizer = override fun accentColor(ctx: CastingEnvironment, errorCtx: Context): FrozenPigment =
dyeColor(DyeColor.GRAY) dyeColor(DyeColor.GRAY)
override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) { override fun execute(ctx: CastingEnvironment, errorCtx: Context, stack: MutableList<Iota>) {

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.api.item; package at.petrak.hexcasting.api.item;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import java.util.UUID; import java.util.UUID;
@ -14,5 +14,5 @@ import java.util.UUID;
*/ */
@ApiStatus.OverrideOnly @ApiStatus.OverrideOnly
public interface ColorizerItem { public interface ColorizerItem {
int color(ItemStack stack, UUID owner, float time, Vec3 position); ColorProvider provideColor(ItemStack stack, UUID owner);
} }

View file

@ -1,78 +0,0 @@
package at.petrak.hexcasting.api.misc;
import at.petrak.hexcasting.api.addldata.ADColorizer;
import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.Util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.FastColor;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import java.util.UUID;
import java.util.function.Supplier;
/**
* A colorizer item and the player who owned it at the time of making the color.
*/
public record FrozenColorizer(ItemStack item, UUID owner) {
private static final int[] MINIMUM_LUMINANCE_COLOR_WHEEL = {
0xFF200000, 0xFF202000, 0xFF002000, 0xFF002020, 0xFF000020, 0xFF200020
};
public static final String TAG_STACK = "stack";
public static final String TAG_OWNER = "owner";
public static final Supplier<FrozenColorizer> DEFAULT =
() -> new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.WHITE)), Util.NIL_UUID);
public CompoundTag serializeToNBT() {
var out = new CompoundTag();
out.put(TAG_STACK, this.item.save(new CompoundTag()));
out.putUUID(TAG_OWNER, this.owner);
return out;
}
public static FrozenColorizer fromNBT(CompoundTag tag) {
if (tag.isEmpty()) {
return FrozenColorizer.DEFAULT.get();
}
try {
CompoundTag stackTag = tag.getCompound(TAG_STACK);
var stack = ItemStack.of(stackTag);
var uuid = tag.getUUID(TAG_OWNER);
return new FrozenColorizer(stack, uuid);
} catch (NullPointerException exn) {
return FrozenColorizer.DEFAULT.get();
}
}
/**
* Gets a color with a minimum luminance applied.
*
* @param time absolute world time in ticks
* @param position a position for the icosahedron, a randomish number for particles.
* @return an AARRGGBB color.
*/
public int getColor(float time, Vec3 position) {
int raw = IXplatAbstractions.INSTANCE.getRawColor(this, time, position);
var r = FastColor.ARGB32.red(raw);
var g = FastColor.ARGB32.green(raw);
var b = FastColor.ARGB32.blue(raw);
double luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 0xFF; // Standard relative luminance calculation
if (luminance < 0.05) {
int rawMod = ADColorizer.morphBetweenColors(MINIMUM_LUMINANCE_COLOR_WHEEL, new Vec3(0.1, 0.1, 0.1),
time / 20 / 20, position);
r += FastColor.ARGB32.red(rawMod);
g += FastColor.ARGB32.green(rawMod);
b += FastColor.ARGB32.blue(rawMod);
}
return 0xff_000000 | (r << 16) | (g << 8) | b;
}
}

View file

@ -3,7 +3,7 @@ package at.petrak.hexcasting.api.mod;
// Don't understand what this does so i commented it all out :gigachad: // Don't understand what this does so i commented it all out :gigachad:
/* /*
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenColorizer;
import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.player.Sentinel;
import at.petrak.hexcasting.api.spell.ParticleSpray; import at.petrak.hexcasting.api.spell.ParticleSpray;
import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.simple.SimpleChannel;
@ -24,7 +24,8 @@ public final class HexApiMessages {
Function<FrozenColorizer, Object> colorizerMessage, Function<FrozenColorizer, Object> colorizerMessage,
BiFunction<ParticleSpray, FrozenColorizer, Object> particleSprayMessage) { BiFunction<ParticleSpray, FrozenColorizer, Object> particleSprayMessage) {
if (HexApiMessages.channel != null) if (HexApiMessages.channel != null)
throw new IllegalStateException("Already set sync channel! If you're not Hex, you shouldn't be calling this."); throw new IllegalStateException("Already set sync channel! If you're not Hex, you shouldn't be calling
this.");
HexApiMessages.channel = channel; HexApiMessages.channel = channel;
HexApiMessages.sentinelMessage = sentinelMessage; HexApiMessages.sentinelMessage = sentinelMessage;
HexApiMessages.colorizerMessage = colorizerMessage; HexApiMessages.colorizerMessage = colorizerMessage;

View file

@ -0,0 +1,50 @@
package at.petrak.hexcasting.api.pigment;
import at.petrak.hexcasting.api.addldata.ADColorizer;
import net.minecraft.util.FastColor;
import net.minecraft.world.phys.Vec3;
public abstract class ColorProvider {
/**
* Implers, impl this function
*/
protected abstract int getRawColor(float time, Vec3 position);
private static final int[] MINIMUM_LUMINANCE_COLOR_WHEEL = {
0xFF200000, 0xFF202000, 0xFF002000, 0xFF002020, 0xFF000020, 0xFF200020
};
/**
* Gets a color with a minimum luminance applied.
*
* @param time absolute world time in ticks
* @param position a position for the icosahedron, a randomish number for particles.
* @return an AARRGGBB color.
*/
public final int getColor(float time, Vec3 position) {
int raw = this.getRawColor(time, position);
var r = FastColor.ARGB32.red(raw);
var g = FastColor.ARGB32.green(raw);
var b = FastColor.ARGB32.blue(raw);
double luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 0xFF; // Standard relative luminance calculation
if (luminance < 0.05) {
int rawMod = ADColorizer.morphBetweenColors(MINIMUM_LUMINANCE_COLOR_WHEEL, new Vec3(0.1, 0.1, 0.1),
time / 20 / 20, position);
r += FastColor.ARGB32.red(rawMod);
g += FastColor.ARGB32.green(rawMod);
b += FastColor.ARGB32.blue(rawMod);
}
return 0xff_000000 | (r << 16) | (g << 8) | b;
}
public static final ColorProvider MISSING = new ColorProvider() {
@Override
protected int getRawColor(float time, Vec3 position) {
return 0xFF_ff00dc;
}
};
}

View file

@ -0,0 +1,51 @@
package at.petrak.hexcasting.api.pigment;
import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.Util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import java.util.UUID;
import java.util.function.Supplier;
/**
* A snapshot of a pigment item and its owner.
* <p>
* Due to capabilities being really slow to query many times a tick on Forge, this returns a colorizer <i>supplier</i>.
* Get it once, and then query it a lot.
*/
public record FrozenPigment(ItemStack item, UUID owner) {
public static final String TAG_STACK = "stack";
public static final String TAG_OWNER = "owner";
public static final Supplier<FrozenPigment> DEFAULT =
() -> new FrozenPigment(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.WHITE)), Util.NIL_UUID);
public CompoundTag serializeToNBT() {
var out = new CompoundTag();
out.put(TAG_STACK, this.item.save(new CompoundTag()));
out.putUUID(TAG_OWNER, this.owner);
return out;
}
public static FrozenPigment fromNBT(CompoundTag tag) {
if (tag.isEmpty()) {
return FrozenPigment.DEFAULT.get();
}
try {
CompoundTag stackTag = tag.getCompound(TAG_STACK);
var stack = ItemStack.of(stackTag);
var uuid = tag.getUUID(TAG_OWNER);
return new FrozenPigment(stack, uuid);
} catch (NullPointerException exn) {
return FrozenPigment.DEFAULT.get();
}
}
public ColorProvider getColorProvider() {
return IXplatAbstractions.INSTANCE.getColorProvider(this);
}
}

View file

@ -84,9 +84,10 @@ public class HexAdditionalRenderers {
RenderSystem.lineWidth(5f); RenderSystem.lineWidth(5f);
var colorizer = IXplatAbstractions.INSTANCE.getColorizer(owner); var colorizer = IXplatAbstractions.INSTANCE.getColorizer(owner);
var colProvider = colorizer.getColorProvider();
BiConsumer<float[], float[]> v = (l, r) -> { BiConsumer<float[], float[]> v = (l, r) -> {
int lcolor = colorizer.getColor(time, new Vec3(l[0], l[1], l[2])), int lcolor = colProvider.getColor(time, new Vec3(l[0], l[1], l[2])),
rcolor = colorizer.getColor(time, new Vec3(r[0], r[1], r[2])); rcolor = colProvider.getColor(time, new Vec3(r[0], r[1], r[2]));
var normal = new Vector3f(r[0] - l[0], r[1] - l[1], r[2] - l[2]); var normal = new Vector3f(r[0] - l[0], r[1] - l[1], r[2] - l[2]);
normal.normalize(); normal.normalize();
buf.vertex(neo, l[0], l[1], l[2]) buf.vertex(neo, l[0], l[1], l[2])

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.blocks; package at.petrak.hexcasting.common.blocks;
import at.petrak.hexcasting.annotations.SoftImplement; import at.petrak.hexcasting.annotations.SoftImplement;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.blocks.entity.BlockEntityConjured; import at.petrak.hexcasting.common.blocks.entity.BlockEntityConjured;
import at.petrak.hexcasting.xplat.IForgeLikeBlock; import at.petrak.hexcasting.xplat.IForgeLikeBlock;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -70,7 +70,7 @@ public class BlockConjured extends Block implements EntityBlock, IForgeLikeBlock
return new BlockEntityConjured(pPos, pState); return new BlockEntityConjured(pPos, pState);
} }
public static void setColor(LevelAccessor pLevel, BlockPos pPos, FrozenColorizer colorizer) { public static void setColor(LevelAccessor pLevel, BlockPos pPos, FrozenPigment colorizer) {
BlockEntity blockentity = pLevel.getBlockEntity(pPos); BlockEntity blockentity = pLevel.getBlockEntity(pPos);
if (blockentity instanceof BlockEntityConjured tile) { if (blockentity instanceof BlockEntityConjured tile) {
tile.setColorizer(colorizer); tile.setColorizer(colorizer);
@ -114,13 +114,13 @@ public class BlockConjured extends Block implements EntityBlock, IForgeLikeBlock
@SoftImplement("forge") @SoftImplement("forge")
public boolean addLandingEffects(BlockState state1, ServerLevel worldserver, BlockPos pos, BlockState state2, public boolean addLandingEffects(BlockState state1, ServerLevel worldserver, BlockPos pos, BlockState state2,
LivingEntity entity, int numberOfParticles) { LivingEntity entity, int numberOfParticles) {
return addLandingEffects(state1, worldserver, pos, entity, numberOfParticles); return addLandingEffects(state1, worldserver, pos, entity, numberOfParticles);
} }
@Override @Override
public boolean addLandingEffects(BlockState state, ServerLevel worldserver, BlockPos pos, public boolean addLandingEffects(BlockState state, ServerLevel worldserver, BlockPos pos,
LivingEntity entity, int numberOfParticles) { LivingEntity entity, int numberOfParticles) {
BlockEntity tile = worldserver.getBlockEntity(pos); BlockEntity tile = worldserver.getBlockEntity(pos);
if (tile instanceof BlockEntityConjured bec) { if (tile instanceof BlockEntityConjured bec) {
bec.landParticle(entity, numberOfParticles); bec.landParticle(entity, numberOfParticles);

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.blocks.entity; package at.petrak.hexcasting.common.blocks.entity;
import at.petrak.hexcasting.api.block.HexBlockEntity; import at.petrak.hexcasting.api.block.HexBlockEntity;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.blocks.BlockConjured; import at.petrak.hexcasting.common.blocks.BlockConjured;
import at.petrak.hexcasting.common.blocks.BlockConjuredLight; import at.petrak.hexcasting.common.blocks.BlockConjuredLight;
import at.petrak.hexcasting.common.lib.HexBlockEntities; import at.petrak.hexcasting.common.lib.HexBlockEntities;
@ -16,7 +16,7 @@ import java.util.Random;
public class BlockEntityConjured extends HexBlockEntity { public class BlockEntityConjured extends HexBlockEntity {
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
private FrozenColorizer colorizer = FrozenColorizer.DEFAULT.get(); private FrozenPigment colorizer = FrozenPigment.DEFAULT.get();
public static final String TAG_COLORIZER = "tag_colorizer"; public static final String TAG_COLORIZER = "tag_colorizer";
@ -26,8 +26,9 @@ public class BlockEntityConjured extends HexBlockEntity {
public void walkParticle(Entity pEntity) { public void walkParticle(Entity pEntity) {
if (getBlockState().getBlock() instanceof BlockConjured conjured && !(conjured instanceof BlockConjuredLight)) { if (getBlockState().getBlock() instanceof BlockConjured conjured && !(conjured instanceof BlockConjuredLight)) {
var colProvider = this.colorizer.getColorProvider();
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
int color = this.colorizer.getColor(pEntity.tickCount, pEntity.position() int color = colProvider.getColor(pEntity.tickCount, pEntity.position()
.add(new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale( .add(new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale(
RANDOM.nextFloat() * 3))); RANDOM.nextFloat() * 3)));
assert level != null; assert level != null;
@ -44,7 +45,7 @@ public class BlockEntityConjured extends HexBlockEntity {
public void particleEffect() { public void particleEffect() {
if (getBlockState().getBlock() instanceof BlockConjured) { if (getBlockState().getBlock() instanceof BlockConjured) {
int color = this.colorizer.getColor(RANDOM.nextFloat() * 16384, int color = this.colorizer.getColorProvider().getColor(RANDOM.nextFloat() * 16384,
new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale( new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale(
RANDOM.nextFloat() * 3)); RANDOM.nextFloat() * 3));
assert level != null; assert level != null;
@ -73,8 +74,9 @@ public class BlockEntityConjured extends HexBlockEntity {
} }
public void landParticle(Entity entity, int number) { public void landParticle(Entity entity, int number) {
var colProvider = this.colorizer.getColorProvider();
for (int i = 0; i < number * 2; i++) { for (int i = 0; i < number * 2; i++) {
int color = this.colorizer.getColor(entity.tickCount, entity.position() int color = colProvider.getColor(entity.tickCount, entity.position()
.add(new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale( .add(new Vec3(RANDOM.nextFloat(), RANDOM.nextFloat(), RANDOM.nextFloat()).scale(
RANDOM.nextFloat() * 3))); RANDOM.nextFloat() * 3)));
assert level != null; assert level != null;
@ -93,14 +95,14 @@ public class BlockEntityConjured extends HexBlockEntity {
@Override @Override
protected void loadModData(CompoundTag tag) { protected void loadModData(CompoundTag tag) {
this.colorizer = FrozenColorizer.fromNBT(tag.getCompound(TAG_COLORIZER)); this.colorizer = FrozenPigment.fromNBT(tag.getCompound(TAG_COLORIZER));
} }
public FrozenColorizer getColorizer() { public FrozenPigment getColorizer() {
return this.colorizer; return this.colorizer;
} }
public void setColorizer(FrozenColorizer colorizer) { public void setColorizer(FrozenPigment colorizer) {
this.colorizer = colorizer; this.colorizer = colorizer;
this.sync(); this.sync();
} }

View file

@ -5,8 +5,8 @@ import at.petrak.hexcasting.api.casting.castables.SpellAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.casting.mishaps.MishapBadOffhandItem import at.petrak.hexcasting.api.casting.mishaps.MishapBadOffhandItem
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.xplat.IXplatAbstractions import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
@ -39,10 +39,10 @@ object OpColorize : SpellAction {
override fun cast(ctx: CastingEnvironment) { override fun cast(ctx: CastingEnvironment) {
val copy = stack.copy() val copy = stack.copy()
val caster = ctx.caster val caster = ctx.caster
if (caster != null && ctx.withdrawItem(copy::equals, 1, true)) { if (caster != null && ctx.withdrawItem(copy::sameItem, 1, true)) {
IXplatAbstractions.INSTANCE.setColorizer( IXplatAbstractions.INSTANCE.setColorizer(
ctx.caster, ctx.caster,
FrozenColorizer(copy, caster.uuid) FrozenPigment(copy, caster.uuid)
) )
} }
} }

View file

@ -7,8 +7,8 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getPlayer import at.petrak.hexcasting.api.casting.getPlayer
import at.petrak.hexcasting.api.casting.getPositiveDouble import at.petrak.hexcasting.api.casting.getPositiveDouble
import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.misc.FrozenColorizer
import at.petrak.hexcasting.api.misc.MediaConstants import at.petrak.hexcasting.api.misc.MediaConstants
import at.petrak.hexcasting.api.pigment.FrozenPigment
import at.petrak.hexcasting.api.player.FlightAbility import at.petrak.hexcasting.api.player.FlightAbility
import at.petrak.hexcasting.common.lib.HexItems import at.petrak.hexcasting.common.lib.HexItems
import at.petrak.hexcasting.common.lib.HexSounds import at.petrak.hexcasting.common.lib.HexSounds
@ -110,8 +110,8 @@ class OpFlight(val type: Type) : SpellAction {
} }
player.level.playSound(null, player.x, player.y, player.z, HexSounds.FLIGHT_FINISH, SoundSource.PLAYERS, 2f, 1f) player.level.playSound(null, player.x, player.y, player.z, HexSounds.FLIGHT_FINISH, SoundSource.PLAYERS, 2f, 1f)
val superDangerSpray = ParticleSpray(player.position(), Vec3(0.0, 1.0, 0.0), Math.PI, 0.4, count = 20) val superDangerSpray = ParticleSpray(player.position(), Vec3(0.0, 1.0, 0.0), Math.PI, 0.4, count = 20)
superDangerSpray.sprayParticles(player.getLevel(), FrozenColorizer(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.RED]!!), Util.NIL_UUID)) superDangerSpray.sprayParticles(player.getLevel(), FrozenPigment(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.RED]!!), Util.NIL_UUID))
superDangerSpray.sprayParticles(player.getLevel(), FrozenColorizer(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.BLACK]!!), Util.NIL_UUID)) superDangerSpray.sprayParticles(player.getLevel(), FrozenPigment(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.BLACK]!!), Util.NIL_UUID))
} else { } else {
if (!player.abilities.mayfly) { if (!player.abilities.mayfly) {
player.abilities.mayfly = true player.abilities.mayfly = true
@ -143,9 +143,9 @@ class OpFlight(val type: Type) : SpellAction {
.sprayParticles(player.getLevel(), color) .sprayParticles(player.getLevel(), color)
val dangerSpray = ParticleSpray(player.position(), Vec3(0.0, 1.0, 0.0), 0.3, Math.PI * 0.75, count = 0) val dangerSpray = ParticleSpray(player.position(), Vec3(0.0, 1.0, 0.0), 0.3, Math.PI * 0.75, count = 0)
dangerSpray.copy(count = oneDangerParticleCount) dangerSpray.copy(count = oneDangerParticleCount)
.sprayParticles(player.getLevel(), FrozenColorizer(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.BLACK]!!), Util.NIL_UUID)) .sprayParticles(player.getLevel(), FrozenPigment(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.BLACK]!!), Util.NIL_UUID))
dangerSpray.copy(count = oneDangerParticleCount) dangerSpray.copy(count = oneDangerParticleCount)
.sprayParticles(player.getLevel(), FrozenColorizer(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.RED]!!), Util.NIL_UUID)) .sprayParticles(player.getLevel(), FrozenPigment(ItemStack(HexItems.DYE_COLORIZERS[DyeColor.RED]!!), Util.NIL_UUID))
if (player.level.random.nextFloat() < 0.02) if (player.level.random.nextFloat() < 0.02)
player.level.playSound(null, player.x, player.y, player.z, HexSounds.FLIGHT_AMBIENCE, SoundSource.PLAYERS, 0.2f, 1f) player.level.playSound(null, player.x, player.y, player.z, HexSounds.FLIGHT_AMBIENCE, SoundSource.PLAYERS, 0.2f, 1f)

View file

@ -2,7 +2,7 @@ package at.petrak.hexcasting.common.impl;
import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.addldata.ADMediaHolder; import at.petrak.hexcasting.api.addldata.ADMediaHolder;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.player.Sentinel;
import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@ -85,7 +85,7 @@ public class HexAPIImpl implements HexAPI {
} }
@Override @Override
public FrozenColorizer getColorizer(Player player) { public FrozenPigment getColorizer(Player player) {
return IXplatAbstractions.INSTANCE.getColorizer(player); return IXplatAbstractions.INSTANCE.getColorizer(player);
} }
} }

View file

@ -1,6 +1,7 @@
package at.petrak.hexcasting.common.items.colorizer; package at.petrak.hexcasting.common.items.colorizer;
import at.petrak.hexcasting.api.item.ColorizerItem; import at.petrak.hexcasting.api.item.ColorizerItem;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -21,7 +22,16 @@ public class ItemDyeColorizer extends Item implements ColorizerItem {
} }
@Override @Override
public int color(ItemStack stack, UUID owner, float time, Vec3 position) { public ColorProvider provideColor(ItemStack stack, UUID owner) {
return dyeColor.getTextColor(); return colorProvider;
}
protected MyColorProvider colorProvider = new MyColorProvider();
protected class MyColorProvider extends ColorProvider {
@Override
protected int getRawColor(float time, Vec3 position) {
return dyeColor.getTextColor();
}
} }
} }

View file

@ -2,33 +2,42 @@ package at.petrak.hexcasting.common.items.colorizer;
import at.petrak.hexcasting.api.addldata.ADColorizer; import at.petrak.hexcasting.api.addldata.ADColorizer;
import at.petrak.hexcasting.api.item.ColorizerItem; import at.petrak.hexcasting.api.item.ColorizerItem;
import net.minecraft.Util; import at.petrak.hexcasting.api.pigment.ColorProvider;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import java.util.EnumMap;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.UUID;
public class ItemPrideColorizer extends Item implements ColorizerItem { public class ItemPrideColorizer extends Item implements ColorizerItem {
public enum Type { public enum Type {
AGENDER, AGENDER(new int[]{0x16a10c, 0xffffff, 0x7a8081, 0x302f30}),
AROACE, AROACE(new int[]{0x7210bc, 0xebf367, 0xffffff, 0x82dceb, 0x2f4dd8}),
AROMANTIC, AROMANTIC(new int[]{0x16a10c, 0x82eb8b, 0xffffff, 0x7a8081, 0x302f30}),
ASEXUAL, ASEXUAL(new int[]{0x333233, 0x9a9fa1, 0xffffff, 0x7210bc}),
BISEXUAL, BISEXUAL(new int[]{0xdb45ff, 0x9c2bd0, 0x6894d4}),
DEMIBOY, DEMIBOY(new int[]{0x9a9fa1, 0xa9ffff, 0xffffff}),
DEMIGIRL, DEMIGIRL(new int[]{0x9a9fa1, 0xfcb1ff, 0xffffff}),
GAY, GAY(new int[]{0xd82f3a, 0xe0883f, 0xebf367, 0x2db418, 0x2f4dd8}),
GENDERFLUID, GENDERFLUID(new int[]{0xfbacf9, 0xffffff, 0x9c2bd0, 0x333233, 0x2f4dd8}),
GENDERQUEER, GENDERQUEER(new int[]{0xca78ef, 0xffffff, 0x2db418}),
INTERSEX, // how to do an intersex gradient escapes me
LESBIAN, INTERSEX(new int[]{0xebf367, 0x7210bc}),
NONBINARY, LESBIAN(new int[]{0xd82f3a, 0xefb87d, 0xffffff, 0xfbacf9, 0xa30262}),
PANSEXUAL, NONBINARY(new int[]{0xebf367, 0xffffff, 0x7210bc, 0x333233}),
PLURAL, PANSEXUAL(new int[]{0xe278ef, 0xebf367, 0x6ac2e4}),
TRANSGENDER; PLURAL(new int[]{0x30c69f, 0x347ddf, 0x6b3fbe, 0x000000}),
TRANSGENDER(new int[]{0xeb92ea, 0xffffff, 0x6ac2e4});
private final int[] colors;
private Type(int[] colors) {
this.colors = colors;
for (int i = 0; i < this.colors.length; i++) {
this.colors[i] |= 0xFF_000000;
}
}
public String getName() { public String getName() {
return this.name().toLowerCase(Locale.ROOT); return this.name().toLowerCase(Locale.ROOT);
@ -43,40 +52,16 @@ public class ItemPrideColorizer extends Item implements ColorizerItem {
} }
@Override @Override
public int color(ItemStack stack, UUID owner, float time, Vec3 position) { public ColorProvider provideColor(ItemStack stack, UUID owner) {
return ADColorizer.morphBetweenColors(getColors(), new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position); return colorProvider;
} }
public int[] getColors() { protected MyColorProvider colorProvider = new MyColorProvider();
return COLORS.get(this.type);
}
private static final EnumMap<Type, int[]> COLORS = Util.make(() -> { protected class MyColorProvider extends ColorProvider {
var out = new EnumMap<Type, int[]>(Type.class); @Override
protected int getRawColor(float time, Vec3 position) {
out.put(Type.AGENDER, new int[]{0x16a10c, 0xffffff, 0x7a8081, 0x302f30}); return ADColorizer.morphBetweenColors(type.colors, new Vec3(0.1, 0.1, 0.1), time / 400, position);
out.put(Type.AROACE, new int[]{0x7210bc, 0xebf367, 0xffffff, 0x82dceb, 0x2f4dd8});
out.put(Type.AROMANTIC, new int[]{0x16a10c, 0x82eb8b, 0xffffff, 0x7a8081, 0x302f30});
out.put(Type.ASEXUAL, new int[]{0x333233, 0x9a9fa1, 0xffffff, 0x7210bc});
out.put(Type.BISEXUAL, new int[]{0xdb45ff, 0x9c2bd0, 0x6894d4});
out.put(Type.DEMIBOY, new int[]{0x9a9fa1, 0xa9ffff, 0xffffff});
out.put(Type.DEMIGIRL, new int[]{0x9a9fa1, 0xfcb1ff, 0xffffff});
out.put(Type.GAY, new int[]{0xd82f3a, 0xe0883f, 0xebf367, 0x2db418, 0x2f4dd8});
out.put(Type.GENDERFLUID, new int[]{0xfbacf9, 0xffffff, 0x9c2bd0, 0x333233, 0x2f4dd8});
out.put(Type.GENDERQUEER, new int[]{0xca78ef, 0xffffff, 0x2db418});
out.put(Type.INTERSEX, new int[]{0xebf367, 0x7210bc}); // how to do an intersex gradient escapes me
out.put(Type.LESBIAN, new int[]{0xd82f3a, 0xefb87d, 0xffffff, 0xfbacf9, 0xa30262});
out.put(Type.NONBINARY, new int[]{0xebf367, 0xffffff, 0x7210bc, 0x333233});
out.put(Type.PANSEXUAL, new int[]{0xe278ef, 0xebf367, 0x6ac2e4});
out.put(Type.PLURAL, new int[]{0x30c69f, 0x347ddf, 0x6b3fbe, 0x000000});
out.put(Type.TRANSGENDER, new int[]{0xeb92ea, 0xffffff, 0x6ac2e4});
for (int[] color : out.values()) {
for (int i = 0; i < color.length; i++) {
color[i] |= 0xff_000000;
}
} }
}
return out;
});
} }

View file

@ -2,13 +2,15 @@ package at.petrak.hexcasting.common.items.colorizer;
import at.petrak.hexcasting.api.addldata.ADColorizer; import at.petrak.hexcasting.api.addldata.ADColorizer;
import at.petrak.hexcasting.api.item.ColorizerItem; import at.petrak.hexcasting.api.item.ColorizerItem;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import at.petrak.paucal.api.PaucalAPI; import at.petrak.paucal.api.PaucalAPI;
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import java.awt.*; import java.awt.*;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
@ -18,34 +20,54 @@ public class ItemUUIDColorizer extends Item implements ColorizerItem {
} }
@Override @Override
public int color(ItemStack stack, UUID owner, float time, Vec3 position) { public ColorProvider provideColor(ItemStack stack, UUID owner) {
var contributor = PaucalAPI.instance().getContributor(owner); return new MyColorProvider(owner);
if (contributor != null) { }
List<?> colorList = contributor.get("hexcasting:colorizer");
if (colorList != null) { protected static class MyColorProvider extends ColorProvider {
var colors = new int[colorList.size()]; private final int[] colors;
var ok = true;
for (int i = 0; i < colorList.size(); i++) { MyColorProvider(UUID owner) {
Object elt = colorList.get(i); var contributor = PaucalAPI.instance().getContributor(owner);
if (elt instanceof Number n) { if (contributor != null) {
colors[i] = n.intValue() | 0xff_000000; var colorList = contributor.otherVals().getAsJsonArray("hexcasting:colorizer");
} else { if (colorList != null) {
ok = false; var colors = new int[colorList.size()];
break; var ok = true;
for (int i = 0; i < colorList.size(); i++) {
JsonElement elt = colorList.get(i);
if (elt instanceof JsonPrimitive n && n.isNumber()) {
colors[i] = n.getAsNumber().intValue() | 0xff_000000;
} else {
ok = false;
break;
}
}
if (ok) {
this.colors = colors;
return;
} }
} }
if (ok) {
return ADColorizer.morphBetweenColors(colors, new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position);
}
} }
// randomly scrungle the bits
var rand = new Random(owner.getLeastSignificantBits() ^ owner.getMostSignificantBits());
var hue1 = rand.nextFloat();
var saturation1 = rand.nextFloat(0.4f, 0.8f);
var brightness1 = rand.nextFloat(0.7f, 1.0f);
var hue2 = rand.nextFloat();
var saturation2 = rand.nextFloat(0.7f, 1.0f);
var brightness2 = rand.nextFloat(0.2f, 0.7f);
var col1 = Color.HSBtoRGB(hue1, saturation1, brightness1);
var col2 = Color.HSBtoRGB(hue2, saturation2, brightness2);
this.colors = new int[]{col1, col2};
} }
// randomly scrungle the bits
var rand = new Random(owner.getLeastSignificantBits() ^ owner.getMostSignificantBits());
var hue = rand.nextFloat();
var saturation = rand.nextFloat(0.4f, 1.0f);
var brightness = rand.nextFloat(0.5f, 1.0f);
return Color.HSBtoRGB(hue, saturation, brightness); @Override
protected int getRawColor(float time, Vec3 position) {
return ADColorizer.morphBetweenColors(this.colors, new Vec3(0.1, 0.1, 0.1), time / 400, position);
}
} }
} }

View file

@ -1,7 +1,7 @@
package at.petrak.hexcasting.common.network; package at.petrak.hexcasting.common.network;
import at.petrak.hexcasting.api.casting.ParticleSpray; import at.petrak.hexcasting.api.casting.ParticleSpray;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.particles.ConjureParticleOptions; import at.petrak.hexcasting.common.particles.ConjureParticleOptions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -17,7 +17,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
/** /**
* Sent server->client to spray particles everywhere. * Sent server->client to spray particles everywhere.
*/ */
public record MsgCastParticleAck(ParticleSpray spray, FrozenColorizer colorizer) implements IMessage { public record MsgCastParticleAck(ParticleSpray spray, FrozenPigment colorizer) implements IMessage {
public static final ResourceLocation ID = modLoc("cprtcl"); public static final ResourceLocation ID = modLoc("cprtcl");
@Override @Override
@ -37,7 +37,7 @@ public record MsgCastParticleAck(ParticleSpray spray, FrozenColorizer colorizer)
var spread = buf.readDouble(); var spread = buf.readDouble();
var count = buf.readInt(); var count = buf.readInt();
var tag = buf.readAnySizeNbt(); var tag = buf.readAnySizeNbt();
var colorizer = FrozenColorizer.fromNBT(tag); var colorizer = FrozenPigment.fromNBT(tag);
return new MsgCastParticleAck( return new MsgCastParticleAck(
new ParticleSpray(new Vec3(posX, posY, posZ), new Vec3(velX, velY, velZ), fuzziness, spread, count), new ParticleSpray(new Vec3(posX, posY, posZ), new Vec3(velX, velY, velZ), fuzziness, spread, count),
colorizer); colorizer);
@ -71,9 +71,10 @@ public record MsgCastParticleAck(ParticleSpray spray, FrozenColorizer colorizer)
Minecraft.getInstance().execute(new Runnable() { Minecraft.getInstance().execute(new Runnable() {
@Override @Override
public void run() { public void run() {
var colProvider = msg.colorizer().getColorProvider();
for (int i = 0; i < msg.spray().getCount(); i++) { for (int i = 0; i < msg.spray().getCount(); i++) {
// For the colors, pick any random time to get a mix of colors // For the colors, pick any random time to get a mix of colors
var color = msg.colorizer().getColor(RANDOM.nextFloat() * 256f, Vec3.ZERO); var color = colProvider.getColor(RANDOM.nextFloat() * 256f, Vec3.ZERO);
var offset = randomInCircle(Mth.TWO_PI).normalize() var offset = randomInCircle(Mth.TWO_PI).normalize()
.scale(RANDOM.nextFloat() * msg.spray().getFuzziness() / 2); .scale(RANDOM.nextFloat() * msg.spray().getFuzziness() / 2);

View file

@ -11,7 +11,8 @@ import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM; import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
import at.petrak.hexcasting.api.casting.iota.IotaType; import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.ColorProvider;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.player.AltioraAbility; import at.petrak.hexcasting.api.player.AltioraAbility;
import at.petrak.hexcasting.api.player.FlightAbility; import at.petrak.hexcasting.api.player.FlightAbility;
import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.player.Sentinel;
@ -78,7 +79,7 @@ public interface IXplatAbstractions {
boolean isBrainswept(Mob mob); boolean isBrainswept(Mob mob);
void setColorizer(Player target, FrozenColorizer colorizer); void setColorizer(Player target, FrozenPigment colorizer);
void setSentinel(Player target, @Nullable Sentinel sentinel); void setSentinel(Player target, @Nullable Sentinel sentinel);
@ -94,7 +95,7 @@ public interface IXplatAbstractions {
@Nullable AltioraAbility getAltiora(Player player); @Nullable AltioraAbility getAltiora(Player player);
FrozenColorizer getColorizer(Player player); FrozenPigment getColorizer(Player player);
@Nullable Sentinel getSentinel(Player player); @Nullable Sentinel getSentinel(Player player);
@ -123,7 +124,7 @@ public interface IXplatAbstractions {
boolean isColorizer(ItemStack stack); boolean isColorizer(ItemStack stack);
int getRawColor(FrozenColorizer colorizer, float time, Vec3 position); ColorProvider getColorProvider(FrozenPigment colorizer);
// Items // Items

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.fabric.cc; package at.petrak.hexcasting.fabric.cc;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import dev.onyxstudios.cca.api.v3.component.Component; import dev.onyxstudios.cca.api.v3.component.Component;
import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -18,20 +18,20 @@ public class CCFavoredColorizer implements Component, AutoSyncedComponent {
this.owner = owner; this.owner = owner;
} }
private FrozenColorizer colorizer = FrozenColorizer.DEFAULT.get(); private FrozenPigment colorizer = FrozenPigment.DEFAULT.get();
public FrozenColorizer getColorizer() { public FrozenPigment getColorizer() {
return colorizer; return colorizer;
} }
public void setColorizer(FrozenColorizer colorizer) { public void setColorizer(FrozenPigment colorizer) {
this.colorizer = colorizer; this.colorizer = colorizer;
HexCardinalComponents.FAVORED_COLORIZER.sync(this.owner); HexCardinalComponents.FAVORED_COLORIZER.sync(this.owner);
} }
@Override @Override
public void readFromNbt(CompoundTag tag) { public void readFromNbt(CompoundTag tag) {
this.colorizer = FrozenColorizer.fromNBT(tag.getCompound(TAG_COLORIZER)); this.colorizer = FrozenPigment.fromNBT(tag.getCompound(TAG_COLORIZER));
} }
@Override @Override

View file

@ -2,10 +2,10 @@ package at.petrak.hexcasting.fabric.cc.adimpl;
import at.petrak.hexcasting.api.addldata.ADColorizer; import at.petrak.hexcasting.api.addldata.ADColorizer;
import at.petrak.hexcasting.api.item.ColorizerItem; import at.petrak.hexcasting.api.item.ColorizerItem;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import at.petrak.hexcasting.fabric.cc.HexCardinalComponents; import at.petrak.hexcasting.fabric.cc.HexCardinalComponents;
import dev.onyxstudios.cca.api.v3.item.ItemComponent; import dev.onyxstudios.cca.api.v3.item.ItemComponent;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import java.util.UUID; import java.util.UUID;
@ -30,8 +30,8 @@ public abstract class CCColorizer extends ItemComponent implements ADColorizer {
} }
@Override @Override
public int color(UUID owner, float time, Vec3 position) { public ColorProvider provideColor(UUID owner) {
return item.color(this.stack, owner, time, position); return item.provideColor(this.stack, owner);
} }
} }
} }

View file

@ -11,9 +11,10 @@ import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM; import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
import at.petrak.hexcasting.api.casting.iota.IotaType; import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.mod.HexConfig; import at.petrak.hexcasting.api.mod.HexConfig;
import at.petrak.hexcasting.api.mod.HexTags; import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.player.AltioraAbility; import at.petrak.hexcasting.api.player.AltioraAbility;
import at.petrak.hexcasting.api.player.FlightAbility; import at.petrak.hexcasting.api.player.FlightAbility;
import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.player.Sentinel;
@ -142,7 +143,7 @@ public class FabricXplatImpl implements IXplatAbstractions {
} }
@Override @Override
public void setColorizer(Player target, FrozenColorizer colorizer) { public void setColorizer(Player target, FrozenPigment colorizer) {
var cc = HexCardinalComponents.FAVORED_COLORIZER.get(target); var cc = HexCardinalComponents.FAVORED_COLORIZER.get(target);
cc.setColorizer(colorizer); cc.setColorizer(colorizer);
} }
@ -194,7 +195,7 @@ public class FabricXplatImpl implements IXplatAbstractions {
} }
@Override @Override
public FrozenColorizer getColorizer(Player player) { public FrozenPigment getColorizer(Player player) {
var cc = HexCardinalComponents.FAVORED_COLORIZER.get(player); var cc = HexCardinalComponents.FAVORED_COLORIZER.get(player);
return cc.getColorizer(); return cc.getColorizer();
} }
@ -263,9 +264,9 @@ public class FabricXplatImpl implements IXplatAbstractions {
} }
@Override @Override
public int getRawColor(FrozenColorizer colorizer, float time, Vec3 position) { public ColorProvider getColorProvider(FrozenPigment colorizer) {
var cc = HexCardinalComponents.COLORIZER.maybeGet(colorizer.item()); var cc = HexCardinalComponents.COLORIZER.maybeGet(colorizer.item());
return cc.map(col -> col.color(colorizer.owner(), time, position)).orElse(0xff_ff00dc); return cc.map(col -> col.provideColor(colorizer.owner())).orElse(ColorProvider.MISSING);
} }
@Override @Override

View file

@ -52,7 +52,7 @@
"fabric": ">=0.64", "fabric": ">=0.64",
"fabric-language-kotlin": ">=1.7.4+kotlin.1.6.21", "fabric-language-kotlin": ">=1.7.4+kotlin.1.6.21",
"cardinal-components": "~5.0.0", "cardinal-components": "~5.0.0",
"paucal": "0.5.x", "paucal": "0.6.x",
"cloth-config": "8.2.x", "cloth-config": "8.2.x",
"patchouli": ">=1.19.2-77" "patchouli": ">=1.19.2-77"
}, },

View file

@ -1,4 +1,4 @@
forgeVersion=43.1.1 forgeVersion=43.2.8
kotlinForForgeVersion=3.7.1 kotlinForForgeVersion=3.7.1

View file

@ -2,15 +2,15 @@ package at.petrak.hexcasting.forge.cap.adimpl;
import at.petrak.hexcasting.api.addldata.ADColorizer; import at.petrak.hexcasting.api.addldata.ADColorizer;
import at.petrak.hexcasting.api.item.ColorizerItem; import at.petrak.hexcasting.api.item.ColorizerItem;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import java.util.UUID; import java.util.UUID;
public record CapItemColorizer(ColorizerItem holder, public record CapItemColorizer(ColorizerItem holder,
ItemStack stack) implements ADColorizer { ItemStack stack) implements ADColorizer {
@Override @Override
public int color(UUID owner, float time, Vec3 position) { public ColorProvider provideColor(UUID owner) {
return holder.color(stack, owner, time, position); return holder.provideColor(this.stack, owner);
} }
} }

View file

@ -1,6 +1,6 @@
package at.petrak.hexcasting.forge.network; package at.petrak.hexcasting.forge.network;
import at.petrak.hexcasting.api.misc.FrozenColorizer; import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.network.IMessage; import at.petrak.hexcasting.common.network.IMessage;
import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatAbstractions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -13,7 +13,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
/** /**
* Sent server->client to synchronize the status of the sentinel. * Sent server->client to synchronize the status of the sentinel.
*/ */
public record MsgColorizerUpdateAck(FrozenColorizer update) implements IMessage { public record MsgColorizerUpdateAck(FrozenPigment update) implements IMessage {
public static final ResourceLocation ID = modLoc("color"); public static final ResourceLocation ID = modLoc("color");
@Override @Override
@ -25,7 +25,7 @@ public record MsgColorizerUpdateAck(FrozenColorizer update) implements IMessage
var buf = new FriendlyByteBuf(buffer); var buf = new FriendlyByteBuf(buffer);
var tag = buf.readAnySizeNbt(); var tag = buf.readAnySizeNbt();
var colorizer = FrozenColorizer.fromNBT(tag); var colorizer = FrozenPigment.fromNBT(tag);
return new MsgColorizerUpdateAck(colorizer); return new MsgColorizerUpdateAck(colorizer);
} }

View file

@ -1,7 +1,6 @@
package at.petrak.hexcasting.forge.xplat; package at.petrak.hexcasting.forge.xplat;
import at.petrak.hexcasting.api.HexAPI; import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.api.addldata.ADColorizer;
import at.petrak.hexcasting.api.addldata.ADHexHolder; import at.petrak.hexcasting.api.addldata.ADHexHolder;
import at.petrak.hexcasting.api.addldata.ADIotaHolder; import at.petrak.hexcasting.api.addldata.ADIotaHolder;
import at.petrak.hexcasting.api.addldata.ADMediaHolder; import at.petrak.hexcasting.api.addldata.ADMediaHolder;
@ -13,8 +12,9 @@ import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
import at.petrak.hexcasting.api.casting.eval.vm.CastingImage; import at.petrak.hexcasting.api.casting.eval.vm.CastingImage;
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM; import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
import at.petrak.hexcasting.api.casting.iota.IotaType; import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.api.mod.HexTags; import at.petrak.hexcasting.api.mod.HexTags;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.api.player.AltioraAbility; import at.petrak.hexcasting.api.player.AltioraAbility;
import at.petrak.hexcasting.api.player.FlightAbility; import at.petrak.hexcasting.api.player.FlightAbility;
import at.petrak.hexcasting.api.player.Sentinel; import at.petrak.hexcasting.api.player.Sentinel;
@ -179,7 +179,7 @@ public class ForgeXplatImpl implements IXplatAbstractions {
} }
@Override @Override
public void setColorizer(Player player, FrozenColorizer colorizer) { public void setColorizer(Player player, FrozenPigment colorizer) {
CompoundTag tag = player.getPersistentData(); CompoundTag tag = player.getPersistentData();
tag.put(TAG_COLOR, colorizer.serializeToNBT()); tag.put(TAG_COLOR, colorizer.serializeToNBT());
@ -253,8 +253,8 @@ public class ForgeXplatImpl implements IXplatAbstractions {
} }
@Override @Override
public FrozenColorizer getColorizer(Player player) { public FrozenPigment getColorizer(Player player) {
return FrozenColorizer.fromNBT(player.getPersistentData().getCompound(TAG_COLOR)); return FrozenPigment.fromNBT(player.getPersistentData().getCompound(TAG_COLOR));
} }
@Override @Override
@ -276,7 +276,8 @@ public class ForgeXplatImpl implements IXplatAbstractions {
public CastingVM getStaffcastVM(ServerPlayer player, InteractionHand hand) { public CastingVM getStaffcastVM(ServerPlayer player, InteractionHand hand) {
// This is always from a staff because we don't need to load the harness when casting from item // This is always from a staff because we don't need to load the harness when casting from item
var ctx = new StaffCastEnv(player, hand); var ctx = new StaffCastEnv(player, hand);
return new CastingVM(CastingImage.loadFromNbt(player.getPersistentData().getCompound(TAG_HARNESS), player.getLevel()), ctx); return new CastingVM(CastingImage.loadFromNbt(player.getPersistentData().getCompound(TAG_HARNESS),
player.getLevel()), ctx);
} }
@Override @Override
@ -336,14 +337,12 @@ public class ForgeXplatImpl implements IXplatAbstractions {
} }
@Override @Override
public int getRawColor(FrozenColorizer colorizer, float time, Vec3 position) { public ColorProvider getColorProvider(FrozenPigment colorizer) {
var maybeColorizer = colorizer.item().getCapability(HexCapabilities.COLOR).resolve(); var maybeColorizer = colorizer.item().getCapability(HexCapabilities.COLOR).resolve();
if (maybeColorizer.isPresent()) { if (maybeColorizer.isPresent()) {
ADColorizer col = maybeColorizer.get(); return maybeColorizer.get().provideColor(colorizer.owner());
return col.color(colorizer.owner(), time, position);
} }
return ColorProvider.MISSING;
return 0xff_ff00dc; // missing color
} }
@Override @Override

View file

@ -17,8 +17,8 @@ plugins {
// Also it looks like property lookups don't work this early // Also it looks like property lookups don't work this early
id 'fabric-loom' version '1.0-SNAPSHOT' apply false id 'fabric-loom' version '1.0-SNAPSHOT' apply false
id("at.petra-k.PKPlugin") version "0.1.0-pre-65" id("at.petra-k.PKPlugin") version "0.1.0-pre-80"
id("at.petra-k.PKSubprojPlugin") version "0.1.0-pre-65" apply false id("at.petra-k.PKSubprojPlugin") version "0.1.0-pre-80" apply false
} }
repositories { repositories {

View file

@ -12,8 +12,8 @@ minecraftVersion=1.19.2
kotlinVersion=1.7.20 kotlinVersion=1.7.20
modVersion=0.11.0 modVersion=0.11.0
paucalVersion=0.5.0 paucalVersion=0.6.0-pre-117
patchouliVersion=77 patchouliVersion=77
jeiVersion=11.4.0.282 jeiVersion=11.4.0.282
pehkuiVersion=3.6.0 pehkuiVersion=3.7.3