start work on better mishaps
This commit is contained in:
parent
96b2e59f88
commit
239762fc01
9 changed files with 183 additions and 14 deletions
|
@ -27,7 +27,8 @@ public record FrozenColorizer(Item item, UUID owner) {
|
||||||
public static final String TAG_ITEM = "item";
|
public static final String TAG_ITEM = "item";
|
||||||
public static final String TAG_OWNER = "owner";
|
public static final String TAG_OWNER = "owner";
|
||||||
|
|
||||||
public static final FrozenColorizer DEFAULT = new FrozenColorizer(HexItems.DYE_COLORIZERS[0].get(), Util.NIL_UUID);
|
public static final FrozenColorizer DEFAULT =
|
||||||
|
new FrozenColorizer(HexItems.DYE_COLORIZERS.get(DyeColor.WHITE).get(), Util.NIL_UUID);
|
||||||
|
|
||||||
public CompoundTag serialize() {
|
public CompoundTag serialize() {
|
||||||
var out = new CompoundTag();
|
var out = new CompoundTag();
|
||||||
|
@ -60,7 +61,7 @@ public record FrozenColorizer(Item item, UUID owner) {
|
||||||
*/
|
*/
|
||||||
public int getColor(float time, Vec3 position) {
|
public int getColor(float time, Vec3 position) {
|
||||||
if (this.item instanceof ItemDyeColorizer dye) {
|
if (this.item instanceof ItemDyeColorizer dye) {
|
||||||
return DyeColor.values()[dye.getDyeIdx()].getTextColor() | 0xff_000000;
|
return dye.getDyeColor().getTextColor() | 0xff_000000;
|
||||||
} else if (this.item instanceof ItemPrideColorizer politics) {
|
} else if (this.item instanceof ItemPrideColorizer politics) {
|
||||||
var colors = politics.getColors();
|
var colors = politics.getColors();
|
||||||
return morphBetweenColors(colors, new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position);
|
return morphBetweenColors(colors, new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position);
|
||||||
|
@ -86,7 +87,7 @@ public record FrozenColorizer(Item item, UUID owner) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// randomly scrungle the bits
|
// randomly scrungle the bits
|
||||||
var rand = new Random(this.owner.getLeastSignificantBits() ^ this.owner.getMostSignificantBits());
|
var rand = new Random(this.owner.getLeastSignificantBits() ^ this.owner.getMostSignificantBits());
|
||||||
var hue = rand.nextFloat();
|
var hue = rand.nextFloat();
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package at.petrak.hexcasting.common.casting.mishaps
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.ParticleSpray
|
||||||
|
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||||
|
import at.petrak.hexcasting.common.casting.CastingContext
|
||||||
|
import at.petrak.hexcasting.common.casting.Widget
|
||||||
|
import at.petrak.hexcasting.common.casting.colors.FrozenColorizer
|
||||||
|
import at.petrak.hexcasting.common.items.HexItems
|
||||||
|
import net.minecraft.Util
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
import net.minecraft.world.item.DyeColor
|
||||||
|
|
||||||
|
sealed class Mishap : Throwable() {
|
||||||
|
/** Mishaps spray half-red, half-this-color. */
|
||||||
|
abstract fun accentColor(ctx: CastingContext): FrozenColorizer
|
||||||
|
|
||||||
|
open fun particleSpray(ctx: CastingContext): ParticleSpray {
|
||||||
|
return ParticleSpray.Burst(ctx.position, 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the actual effect, not any sfx.
|
||||||
|
*
|
||||||
|
* You can also mess up the stack with this.
|
||||||
|
*/
|
||||||
|
abstract fun execute(ctx: CastingContext, stack: MutableList<SpellDatum<*>>)
|
||||||
|
|
||||||
|
abstract fun errorMessage(ctx: CastingContext): Component
|
||||||
|
|
||||||
|
protected fun dyeColor(color: DyeColor): FrozenColorizer =
|
||||||
|
FrozenColorizer(HexItems.DYE_COLORIZERS[color]!!.get(), Util.NIL_UUID)
|
||||||
|
|
||||||
|
protected fun pushGarbage(stack: MutableList<SpellDatum<*>>) {
|
||||||
|
stack.add(SpellDatum.make(Widget.GARBAGE))
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun error(stub: String, vararg args: Any): Component =
|
||||||
|
TranslatableComponent("hexcasting.mishap.$stub", *args)
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package at.petrak.hexcasting.common.casting.mishaps
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||||
|
import at.petrak.hexcasting.common.casting.CastingContext
|
||||||
|
import at.petrak.hexcasting.common.casting.colors.FrozenColorizer
|
||||||
|
import at.petrak.hexcasting.hexmath.HexPattern
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.world.item.DyeColor
|
||||||
|
|
||||||
|
class MishapInvalidPattern(val pattern: HexPattern) : Mishap() {
|
||||||
|
override fun accentColor(ctx: CastingContext): FrozenColorizer =
|
||||||
|
dyeColor(DyeColor.YELLOW)
|
||||||
|
|
||||||
|
|
||||||
|
override fun execute(ctx: CastingContext, stack: MutableList<SpellDatum<*>>) {
|
||||||
|
pushGarbage(stack)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun errorMessage(ctx: CastingContext): Component =
|
||||||
|
error("invalid_pattern")
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package at.petrak.hexcasting.common.casting.mishaps
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||||
|
import at.petrak.hexcasting.common.casting.CastingContext
|
||||||
|
import at.petrak.hexcasting.common.casting.colors.FrozenColorizer
|
||||||
|
import net.minecraft.Util
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.world.item.DyeColor
|
||||||
|
|
||||||
|
class MishapInvalidSpellDatumType(val perpetrator: Any) : Mishap() {
|
||||||
|
override fun accentColor(ctx: CastingContext): FrozenColorizer =
|
||||||
|
dyeColor(DyeColor.BLACK)
|
||||||
|
|
||||||
|
override fun execute(ctx: CastingContext, stack: MutableList<SpellDatum<*>>) {
|
||||||
|
val msg = this.errorMessage(ctx)
|
||||||
|
ctx.caster.sendMessage(msg, Util.NIL_UUID)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun errorMessage(ctx: CastingContext): Component =
|
||||||
|
error("invalid_spell_datum_type", this.perpetrator.toString(), this.perpetrator.javaClass.typeName)
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package at.petrak.hexcasting.common.casting.mishaps
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||||
|
import at.petrak.hexcasting.common.casting.CastingContext
|
||||||
|
import at.petrak.hexcasting.common.casting.Widget
|
||||||
|
import at.petrak.hexcasting.common.casting.colors.FrozenColorizer
|
||||||
|
import at.petrak.hexcasting.hexmath.HexPattern
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
import net.minecraft.world.entity.Entity
|
||||||
|
import net.minecraft.world.entity.LivingEntity
|
||||||
|
import net.minecraft.world.entity.item.ItemEntity
|
||||||
|
import net.minecraft.world.entity.player.Player
|
||||||
|
import net.minecraft.world.item.DyeColor
|
||||||
|
import net.minecraft.world.phys.Vec3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value failed some kind of predicate.
|
||||||
|
*
|
||||||
|
* [MishapInvalidValue.idx] is the absolute index in the stack.
|
||||||
|
*/
|
||||||
|
class MishapInvalidValue(val perpetrator: SpellDatum<*>, val idx: Int, val expectedKey: String) : Mishap() {
|
||||||
|
override fun accentColor(ctx: CastingContext): FrozenColorizer =
|
||||||
|
dyeColor(DyeColor.GRAY)
|
||||||
|
|
||||||
|
override fun execute(ctx: CastingContext, stack: MutableList<SpellDatum<*>>) {
|
||||||
|
stack[idx] = SpellDatum.make(Widget.GARBAGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun errorMessage(ctx: CastingContext): Component =
|
||||||
|
error("invalid_value", TranslatableComponent(expectedKey), perpetrator.display())
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun ofClass(perpetrator: SpellDatum<*>, reverseIdx: Int, cls: Class<*>): MishapInvalidValue {
|
||||||
|
val key = "hexcasting.mishap.invalid_value.class" + when {
|
||||||
|
Double::class.java.isAssignableFrom(cls) -> "double"
|
||||||
|
Vec3::class.java.isAssignableFrom(cls) -> "vector"
|
||||||
|
List::class.java.isAssignableFrom(cls) -> "list"
|
||||||
|
Widget::class.java.isAssignableFrom(cls) -> "widget"
|
||||||
|
HexPattern::class.java.isAssignableFrom(cls) -> "pattern"
|
||||||
|
|
||||||
|
ItemEntity::class.java.isAssignableFrom(cls) -> "entity.item"
|
||||||
|
LivingEntity::class.java.isAssignableFrom(cls) -> "entity.living"
|
||||||
|
Player::class.java.isAssignableFrom(cls) -> "entity.player"
|
||||||
|
Entity::class.java.isAssignableFrom(cls) -> "entity"
|
||||||
|
|
||||||
|
else -> "unknown"
|
||||||
|
}
|
||||||
|
return MishapInvalidValue(perpetrator, reverseIdx, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package at.petrak.hexcasting.common.casting.mishaps
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||||
|
import at.petrak.hexcasting.common.casting.CastingContext
|
||||||
|
import at.petrak.hexcasting.common.casting.Widget
|
||||||
|
import at.petrak.hexcasting.common.casting.colors.FrozenColorizer
|
||||||
|
import net.minecraft.network.chat.Component
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent
|
||||||
|
import net.minecraft.world.item.DyeColor
|
||||||
|
|
||||||
|
class MishapWrongType(val perpetrator: SpellDatum<*>, val reverseIdx: Int, val expectedKey: String) : Mishap() {
|
||||||
|
override fun accentColor(ctx: CastingContext): FrozenColorizer =
|
||||||
|
dyeColor(DyeColor.GRAY)
|
||||||
|
|
||||||
|
override fun execute(ctx: CastingContext, stack: MutableList<SpellDatum<*>>) {
|
||||||
|
stack[stack.size - 1 - reverseIdx] = SpellDatum.make(Widget.GARBAGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun errorMessage(ctx: CastingContext): Component =
|
||||||
|
error("invalid_value", TranslatableComponent(expectedKey), perpetrator.display())
|
||||||
|
}
|
|
@ -18,6 +18,8 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
import net.minecraftforge.registries.RegistryObject;
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
|
|
||||||
public class HexItems {
|
public class HexItems {
|
||||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, HexMod.MOD_ID);
|
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, HexMod.MOD_ID);
|
||||||
public static final CreativeModeTab TAB = new CreativeModeTab(HexMod.MOD_ID) {
|
public static final CreativeModeTab TAB = new CreativeModeTab(HexMod.MOD_ID) {
|
||||||
|
@ -77,15 +79,14 @@ public class HexItems {
|
||||||
public static final RegistryObject<ItemManaBattery> BATTERY = ITEMS.register("battery",
|
public static final RegistryObject<ItemManaBattery> BATTERY = ITEMS.register("battery",
|
||||||
() -> new ItemManaBattery(new Item.Properties().stacksTo(1)));
|
() -> new ItemManaBattery(new Item.Properties().stacksTo(1)));
|
||||||
|
|
||||||
public static final RegistryObject<ItemDyeColorizer>[] DYE_COLORIZERS = new RegistryObject[16];
|
public static final EnumMap<DyeColor, RegistryObject<ItemDyeColorizer>> DYE_COLORIZERS = new EnumMap<>(
|
||||||
|
DyeColor.class);
|
||||||
public static final RegistryObject<ItemPrideColorizer>[] PRIDE_COLORIZERS = new RegistryObject[14];
|
public static final RegistryObject<ItemPrideColorizer>[] PRIDE_COLORIZERS = new RegistryObject[14];
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (int i = 0; i < DYE_COLORIZERS.length; i++) {
|
for (var dye : DyeColor.values()) {
|
||||||
var dye = DyeColor.values()[i];
|
DYE_COLORIZERS.put(dye, ITEMS.register("dye_colorizer_" + dye.getName(),
|
||||||
final var finalI = i;
|
() -> new ItemDyeColorizer(dye, unstackable())));
|
||||||
DYE_COLORIZERS[i] = ITEMS.register("dye_colorizer_" + dye.getName(),
|
|
||||||
() -> new ItemDyeColorizer(finalI, unstackable()));
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < PRIDE_COLORIZERS.length; i++) {
|
for (int i = 0; i < PRIDE_COLORIZERS.length; i++) {
|
||||||
final var finalI = i;
|
final var finalI = i;
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package at.petrak.hexcasting.common.items.colorizer;
|
package at.petrak.hexcasting.common.items.colorizer;
|
||||||
|
|
||||||
|
import net.minecraft.world.item.DyeColor;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
public class ItemDyeColorizer extends Item {
|
public class ItemDyeColorizer extends Item {
|
||||||
private final int dyeIdx;
|
private final DyeColor dyeColor;
|
||||||
|
|
||||||
public ItemDyeColorizer(int dyeIdx, Properties pProperties) {
|
public ItemDyeColorizer(DyeColor dyeColor, Properties pProperties) {
|
||||||
super(pProperties);
|
super(pProperties);
|
||||||
this.dyeIdx = dyeIdx;
|
this.dyeColor = dyeColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDyeIdx() {
|
public DyeColor getDyeColor() {
|
||||||
return dyeIdx;
|
return dyeColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,16 @@
|
||||||
"hexcasting.spell.hexcasting:const/vec/nz": "Vector Reflection -Z",
|
"hexcasting.spell.hexcasting:const/vec/nz": "Vector Reflection -Z",
|
||||||
"hexcasting.spell.hexcasting:const/vec/0": "Vector Reflection Zero",
|
"hexcasting.spell.hexcasting:const/vec/0": "Vector Reflection Zero",
|
||||||
|
|
||||||
|
"hexcasting.mishap.invalid_pattern": "That pattern isn't associated with any action.",
|
||||||
|
"hexcasting.mishap.invalid_spell_datum_type": "Tried to use a value of invalid type as a SpellDatum: %s (class %s). This is a bug in the mod.",
|
||||||
|
"hexcasting.mishap.invalid_value": "Expected %s, but got %s",
|
||||||
|
"hexcasting.mishap.invalid_value.class.entity": "entity",
|
||||||
|
"hexcasting.mishap.invalid_value.class.number": "number",
|
||||||
|
"hexcasting.mishap.invalid_value.class.number": "number",
|
||||||
|
"hexcasting.mishap.invalid_value.class.number": "number",
|
||||||
|
"hexcasting.mishap.invalid_value.class.number": "number",
|
||||||
|
"hexcasting.mishap.invalid_value.class.number": "number",
|
||||||
|
|
||||||
"hexcasting.landing": "I seem to have discovered a new method of magical arts, in which one draws patterns strange and wild onto a hexagonal grid. It fascinates me. I've decided to start a journal of my thoughts and findings.$(br2)$(l:https://discord.gg/4xxHGYteWk)Discord Server Link/$",
|
"hexcasting.landing": "I seem to have discovered a new method of magical arts, in which one draws patterns strange and wild onto a hexagonal grid. It fascinates me. I've decided to start a journal of my thoughts and findings.$(br2)$(l:https://discord.gg/4xxHGYteWk)Discord Server Link/$",
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue