rename lots of things
This commit is contained in:
parent
fb246ef883
commit
d0f43ff0d9
61 changed files with 695 additions and 545 deletions
|
@ -6,7 +6,7 @@ import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface Colorizer {
|
public interface ADColorizer {
|
||||||
int color(UUID owner, float time, Vec3 position);
|
int color(UUID owner, float time, Vec3 position);
|
||||||
|
|
||||||
static int morphBetweenColors(int[] colors, Vec3 gradientDir, float time, Vec3 position) {
|
static int morphBetweenColors(int[] colors, Vec3 gradientDir, float time, Vec3 position) {
|
|
@ -1,21 +1,21 @@
|
||||||
package at.petrak.hexcasting.api.addldata;
|
package at.petrak.hexcasting.api.addldata;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.iota.Iota;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface HexHolder {
|
public interface ADHexHolder {
|
||||||
|
|
||||||
boolean canDrawManaFromInventory();
|
boolean canDrawManaFromInventory();
|
||||||
|
|
||||||
boolean hasHex();
|
boolean hasHex();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
List<LegacySpellDatum<?>> getHex(ServerLevel level);
|
List<Iota> getHex(ServerLevel level);
|
||||||
|
|
||||||
void writeHex(List<LegacySpellDatum<?>> patterns, int mana);
|
void writeHex(List<Iota> patterns, int mana);
|
||||||
|
|
||||||
void clearHex();
|
void clearHex();
|
||||||
}
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package at.petrak.hexcasting.api.addldata;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.iota.Iota;
|
||||||
|
import at.petrak.hexcasting.common.lib.HexIotaTypes;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public interface ADIotaHolder {
|
||||||
|
@Nullable
|
||||||
|
CompoundTag readIotaTag();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
default Iota readIota(ServerLevel world) {
|
||||||
|
var tag = readIotaTag();
|
||||||
|
if (tag != null) {
|
||||||
|
return HexIotaTypes.deserialize(tag, world);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
default Iota emptyIota() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if the writing succeeded/would succeed
|
||||||
|
*/
|
||||||
|
boolean writeIota(@Nullable Iota iota, boolean simulate);
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package at.petrak.hexcasting.api.addldata;
|
||||||
|
|
||||||
|
public interface ADMediaHolder {
|
||||||
|
|
||||||
|
int getMedia();
|
||||||
|
|
||||||
|
int getMaxMedia();
|
||||||
|
|
||||||
|
void setMedia(int media);
|
||||||
|
|
||||||
|
boolean canRecharge();
|
||||||
|
|
||||||
|
boolean canProvide();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When scanning an inventory for media-containing items, the items with the highest priority will
|
||||||
|
* get their media consumed first.
|
||||||
|
*/
|
||||||
|
int getConsumptionPriority();
|
||||||
|
|
||||||
|
boolean canConstructBattery();
|
||||||
|
|
||||||
|
default int withdrawMedia(int cost, boolean simulate) {
|
||||||
|
if (!canProvide()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
var manaHere = getMedia();
|
||||||
|
if (cost < 0) {
|
||||||
|
cost = manaHere;
|
||||||
|
}
|
||||||
|
if (!simulate) {
|
||||||
|
var manaLeft = manaHere - cost;
|
||||||
|
setMedia(manaLeft);
|
||||||
|
}
|
||||||
|
return Math.min(cost, manaHere);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CHARGED_AMETHYST_PRIORITY = 1000;
|
||||||
|
public int AMETHYST_SHARD_PRIORITY = 2000;
|
||||||
|
public int AMETHYST_DUST_PRIORITY = 3000;
|
||||||
|
public int BATTERY_PRIORITY = 4000;
|
||||||
|
}
|
|
@ -1,28 +0,0 @@
|
||||||
package at.petrak.hexcasting.api.addldata;
|
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public interface DataHolder {
|
|
||||||
@Nullable
|
|
||||||
CompoundTag readRawDatum();
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
default LegacySpellDatum<?> readDatum(ServerLevel world) {
|
|
||||||
var tag = readRawDatum();
|
|
||||||
if (tag != null) {
|
|
||||||
return LegacySpellDatum.fromNBT(tag, world);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
default LegacySpellDatum<?> emptyDatum() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean writeDatum(@Nullable LegacySpellDatum<?> datum, boolean simulate);
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package at.petrak.hexcasting.api.addldata;
|
|
||||||
|
|
||||||
public interface ManaHolder {
|
|
||||||
|
|
||||||
int getMana();
|
|
||||||
|
|
||||||
int getMaxMana();
|
|
||||||
|
|
||||||
void setMana(int mana);
|
|
||||||
|
|
||||||
boolean canRecharge();
|
|
||||||
|
|
||||||
boolean canProvide();
|
|
||||||
|
|
||||||
int getConsumptionPriority();
|
|
||||||
|
|
||||||
boolean canConstructBattery();
|
|
||||||
|
|
||||||
default int withdrawMana(int cost, boolean simulate) {
|
|
||||||
if (!canProvide()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
var manaHere = getMana();
|
|
||||||
if (cost < 0) {
|
|
||||||
cost = manaHere;
|
|
||||||
}
|
|
||||||
if (!simulate) {
|
|
||||||
var manaLeft = manaHere - cost;
|
|
||||||
setMana(manaLeft);
|
|
||||||
}
|
|
||||||
return Math.min(cost, manaHere);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* An "Additional Data," or AD, is what I am calling the abstraction over capabilities on Forge and
|
||||||
|
* cardinal components on Fabric.
|
||||||
|
* <p>
|
||||||
|
* An {@code ADFooBar} in this package will be implemented by a {@code CCFooBar} on Fabric.
|
||||||
|
* On Forge, there are a set of private records that implement them.
|
||||||
|
* <p>
|
||||||
|
* The point is, this provides an interface for interacting with however whatever platform sticks extra info on stuff.
|
||||||
|
*/
|
||||||
|
package at.petrak.hexcasting.api.addldata;
|
|
@ -5,6 +5,12 @@ import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Items which can be used as a colorizer can implement this interface.
|
||||||
|
* <p>
|
||||||
|
* On both the Forge and Fabric sides, the registry will be scanned for all items which implement this interface,
|
||||||
|
* and the appropriate cap/CC will be attached.
|
||||||
|
*/
|
||||||
public interface ColorizerItem {
|
public interface ColorizerItem {
|
||||||
int color(ItemStack stack, UUID owner, float time, Vec3 position);
|
int color(ItemStack stack, UUID owner, float time, Vec3 position);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
package at.petrak.hexcasting.api.item;
|
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
|
||||||
import net.minecraft.ChatFormatting;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.NbtUtils;
|
|
||||||
import net.minecraft.network.chat.Component;
|
|
||||||
import net.minecraft.network.chat.TextComponent;
|
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.TooltipFlag;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface DataHolderItem {
|
|
||||||
String TAG_OVERRIDE_VISUALLY = "VisualOverride";
|
|
||||||
|
|
||||||
@Nullable CompoundTag readDatumTag(ItemStack stack);
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
default LegacySpellDatum<?> readDatum(ItemStack stack, ServerLevel world) {
|
|
||||||
if (!(stack.getItem() instanceof DataHolderItem dh)) {
|
|
||||||
// this should be checked via mishap beforehand
|
|
||||||
throw new IllegalArgumentException("stack's item must be an ItemDataholder but was " + stack.getItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
var tag = dh.readDatumTag(stack);
|
|
||||||
if (tag != null) {
|
|
||||||
return LegacySpellDatum.fromNBT(tag, world);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
default LegacySpellDatum<?> emptyDatum(ItemStack stack) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean canWrite(ItemStack stack, @Nullable LegacySpellDatum<?> datum);
|
|
||||||
|
|
||||||
void writeDatum(ItemStack stack, @Nullable LegacySpellDatum<?> datum);
|
|
||||||
|
|
||||||
static void appendHoverText(DataHolderItem self, ItemStack pStack, List<Component> pTooltipComponents,
|
|
||||||
TooltipFlag pIsAdvanced) {
|
|
||||||
var datumTag = self.readDatumTag(pStack);
|
|
||||||
if (datumTag != null) {
|
|
||||||
var component = LegacySpellDatum.displayFromNBT(datumTag);
|
|
||||||
pTooltipComponents.add(new TranslatableComponent("hexcasting.spelldata.onitem", component));
|
|
||||||
|
|
||||||
if (pIsAdvanced.isAdvanced()) {
|
|
||||||
pTooltipComponents.add(new TextComponent("").append(NbtUtils.toPrettyComponent(datumTag)));
|
|
||||||
}
|
|
||||||
} else if (NBTHelper.hasString(pStack, DataHolderItem.TAG_OVERRIDE_VISUALLY)) {
|
|
||||||
pTooltipComponents.add(new TranslatableComponent("hexcasting.spelldata.onitem",
|
|
||||||
new TranslatableComponent("hexcasting.spelldata.anything").withStyle(ChatFormatting.LIGHT_PURPLE)));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +1,28 @@
|
||||||
package at.petrak.hexcasting.api.item;
|
package at.petrak.hexcasting.api.item;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.iota.Iota;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface HexHolderItem extends ManaHolderItem {
|
/**
|
||||||
|
* Items which can cast a packaged Hex can implement this interface.
|
||||||
|
* <p>
|
||||||
|
* On both the Forge and Fabric sides, the registry will be scanned for all items which implement this interface,
|
||||||
|
* and the appropriate cap/CC will be attached.
|
||||||
|
*/
|
||||||
|
public interface HexHolderItem extends MediaHolderItem {
|
||||||
|
|
||||||
boolean canDrawManaFromInventory(ItemStack stack);
|
boolean canDrawManaFromInventory(ItemStack stack);
|
||||||
|
|
||||||
boolean hasHex(ItemStack stack);
|
boolean hasHex(ItemStack stack);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
List<LegacySpellDatum<?>> getHex(ItemStack stack, ServerLevel level);
|
List<Iota> getHex(ItemStack stack, ServerLevel level);
|
||||||
|
|
||||||
void writeHex(ItemStack stack, List<LegacySpellDatum<?>> patterns, int mana);
|
void writeHex(ItemStack stack, List<Iota> program, int mana);
|
||||||
|
|
||||||
void clearHex(ItemStack stack);
|
void clearHex(ItemStack stack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package at.petrak.hexcasting.api.item;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.iota.Iota;
|
||||||
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
|
import at.petrak.hexcasting.common.lib.HexIotaTypes;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.NbtUtils;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.TextComponent;
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.TooltipFlag;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Items that store an iota to their tag can implement this interface.
|
||||||
|
* <p>
|
||||||
|
* On both the Forge and Fabric sides, the registry will be scanned for all items which implement this interface,
|
||||||
|
* and the appropriate cap/CC will be attached.
|
||||||
|
*/
|
||||||
|
public interface IotaHolderItem {
|
||||||
|
String TAG_OVERRIDE_VISUALLY = "VisualOverride";
|
||||||
|
|
||||||
|
@Nullable CompoundTag readIotaTag(ItemStack stack);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
default Iota readIota(ItemStack stack, ServerLevel world) {
|
||||||
|
if (!(stack.getItem() instanceof IotaHolderItem dh)) {
|
||||||
|
// this should be checked via mishap beforehand
|
||||||
|
throw new IllegalArgumentException("stack's item must be an IotaHolderItem but was " + stack.getItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
var tag = dh.readIotaTag(stack);
|
||||||
|
if (tag != null) {
|
||||||
|
return HexIotaTypes.deserialize(tag, world);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
default Iota emptyIota(ItemStack stack) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean canWrite(ItemStack stack, @Nullable Iota iota);
|
||||||
|
|
||||||
|
void writeDatum(ItemStack stack, @Nullable Iota iota);
|
||||||
|
|
||||||
|
static void appendHoverText(IotaHolderItem self, ItemStack stack, List<Component> components,
|
||||||
|
TooltipFlag flag) {
|
||||||
|
var datumTag = self.readIotaTag(stack);
|
||||||
|
if (datumTag != null) {
|
||||||
|
var cmp = HexIotaTypes.getDisplay(datumTag);
|
||||||
|
components.add(new TranslatableComponent("hexcasting.spelldata.onitem", cmp));
|
||||||
|
|
||||||
|
if (flag.isAdvanced()) {
|
||||||
|
components.add(new TextComponent("").append(NbtUtils.toPrettyComponent(datumTag)));
|
||||||
|
}
|
||||||
|
} else if (NBTHelper.hasString(stack, IotaHolderItem.TAG_OVERRIDE_VISUALLY)) {
|
||||||
|
components.add(new TranslatableComponent("hexcasting.spelldata.onitem",
|
||||||
|
new TranslatableComponent("hexcasting.spelldata.anything").withStyle(ChatFormatting.LIGHT_PURPLE)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,35 +0,0 @@
|
||||||
package at.petrak.hexcasting.api.item;
|
|
||||||
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
|
|
||||||
public interface ManaHolderItem {
|
|
||||||
int getMana(ItemStack stack);
|
|
||||||
|
|
||||||
int getMaxMana(ItemStack stack);
|
|
||||||
|
|
||||||
void setMana(ItemStack stack, int mana);
|
|
||||||
|
|
||||||
boolean manaProvider(ItemStack stack);
|
|
||||||
|
|
||||||
boolean canRecharge(ItemStack stack);
|
|
||||||
|
|
||||||
default float getManaFullness(ItemStack stack) {
|
|
||||||
int max = getMaxMana(stack);
|
|
||||||
if (max == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return (float) getMana(stack) / (float) max;
|
|
||||||
}
|
|
||||||
|
|
||||||
default int withdrawMana(ItemStack stack, int cost, boolean simulate) {
|
|
||||||
var manaHere = getMana(stack);
|
|
||||||
if (cost < 0) {
|
|
||||||
cost = manaHere;
|
|
||||||
}
|
|
||||||
if (!simulate) {
|
|
||||||
var manaLeft = manaHere - cost;
|
|
||||||
setMana(stack, manaLeft);
|
|
||||||
}
|
|
||||||
return Math.min(cost, manaHere);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package at.petrak.hexcasting.api.item;
|
||||||
|
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Items which can store Media can implement this interface.
|
||||||
|
* <p>
|
||||||
|
* On both the Forge and Fabric sides, the registry will be scanned for all items which implement this interface,
|
||||||
|
* and the appropriate cap/CC will be attached.
|
||||||
|
*/
|
||||||
|
public interface MediaHolderItem {
|
||||||
|
int getMedia(ItemStack stack);
|
||||||
|
|
||||||
|
int getMaxMedia(ItemStack stack);
|
||||||
|
|
||||||
|
void setMedia(ItemStack stack, int media);
|
||||||
|
|
||||||
|
boolean canProvideMedia(ItemStack stack);
|
||||||
|
|
||||||
|
boolean canRecharge(ItemStack stack);
|
||||||
|
|
||||||
|
default float getManaFullness(ItemStack stack) {
|
||||||
|
int max = getMaxMedia(stack);
|
||||||
|
if (max == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (float) getMedia(stack) / (float) max;
|
||||||
|
}
|
||||||
|
|
||||||
|
default int withdrawMana(ItemStack stack, int cost, boolean simulate) {
|
||||||
|
var manaHere = getMedia(stack);
|
||||||
|
if (cost < 0) {
|
||||||
|
cost = manaHere;
|
||||||
|
}
|
||||||
|
if (!simulate) {
|
||||||
|
var manaLeft = manaHere - cost;
|
||||||
|
setMedia(stack, manaLeft);
|
||||||
|
}
|
||||||
|
return Math.min(cost, manaHere);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.api.misc;
|
package at.petrak.hexcasting.api.misc;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.Colorizer;
|
import at.petrak.hexcasting.api.addldata.ADColorizer;
|
||||||
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
|
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
|
@ -31,7 +31,8 @@ public record FrozenColorizer(ItemStack item, UUID owner) {
|
||||||
0xFF200000, 0xFF202000, 0xFF002000, 0xFF002020, 0xFF000020, 0xFF200020
|
0xFF200000, 0xFF202000, 0xFF002000, 0xFF002020, 0xFF000020, 0xFF200020
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final Map<String, Supplier<Item>> OLD_PRIDE_COLORIZERS = Arrays.stream(ItemPrideColorizer.Type.values())
|
private static final Map<String, Supplier<Item>> OLD_PRIDE_COLORIZERS = Arrays.stream(
|
||||||
|
ItemPrideColorizer.Type.values())
|
||||||
.collect(Collectors.<ItemPrideColorizer.Type, String, Supplier<Item>>toMap(
|
.collect(Collectors.<ItemPrideColorizer.Type, String, Supplier<Item>>toMap(
|
||||||
(type) -> modLoc("pride_colorizer_" + type.ordinal()).toString(),
|
(type) -> modLoc("pride_colorizer_" + type.ordinal()).toString(),
|
||||||
(type) -> (() -> HexItems.PRIDE_COLORIZERS.get(type))));
|
(type) -> (() -> HexItems.PRIDE_COLORIZERS.get(type))));
|
||||||
|
@ -85,7 +86,7 @@ public record FrozenColorizer(ItemStack item, UUID owner) {
|
||||||
double luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 0xFF; // Standard relative luminance calculation
|
double luminance = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 0xFF; // Standard relative luminance calculation
|
||||||
|
|
||||||
if (luminance < 0.05) {
|
if (luminance < 0.05) {
|
||||||
int rawMod = Colorizer.morphBetweenColors(MINIMUM_LUMINANCE_COLOR_WHEEL, new Vec3(0.1, 0.1, 0.1),
|
int rawMod = ADColorizer.morphBetweenColors(MINIMUM_LUMINANCE_COLOR_WHEEL, new Vec3(0.1, 0.1, 0.1),
|
||||||
time / 20 / 20, position);
|
time / 20 / 20, position);
|
||||||
|
|
||||||
r += FastColor.ARGB32.red(rawMod);
|
r += FastColor.ARGB32.red(rawMod);
|
||||||
|
|
|
@ -375,9 +375,9 @@ class CastingHarness private constructor(
|
||||||
val casterHexHolder = IXplatAbstractions.INSTANCE.findHexHolder(casterStack)
|
val casterHexHolder = IXplatAbstractions.INSTANCE.findHexHolder(casterStack)
|
||||||
val hexHolderDrawsFromInventory = if (casterHexHolder != null) {
|
val hexHolderDrawsFromInventory = if (casterHexHolder != null) {
|
||||||
if (casterManaHolder != null) {
|
if (casterManaHolder != null) {
|
||||||
val manaAvailable = casterManaHolder.mana
|
val manaAvailable = casterManaHolder.media
|
||||||
val manaToTake = min(costLeft, manaAvailable)
|
val manaToTake = min(costLeft, manaAvailable)
|
||||||
if (!fake) casterManaHolder.mana = manaAvailable - manaToTake
|
if (!fake) casterManaHolder.media = manaAvailable - manaToTake
|
||||||
costLeft -= manaToTake
|
costLeft -= manaToTake
|
||||||
}
|
}
|
||||||
casterHexHolder.canDrawManaFromInventory()
|
casterHexHolder.canDrawManaFromInventory()
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package at.petrak.hexcasting.api.spell.iota;
|
package at.petrak.hexcasting.api.spell.iota;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.utils.HexUtils;
|
||||||
import at.petrak.hexcasting.common.lib.HexIotaTypes;
|
import at.petrak.hexcasting.common.lib.HexIotaTypes;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -30,7 +32,7 @@ public class EntityIota extends Iota {
|
||||||
public @NotNull Tag serialize() {
|
public @NotNull Tag serialize() {
|
||||||
var out = new CompoundTag();
|
var out = new CompoundTag();
|
||||||
out.putUUID("uuid", this.getEntity().getUUID());
|
out.putUUID("uuid", this.getEntity().getUUID());
|
||||||
out.putString("name", Component.Serializer.toJson(this.getEntity().getDisplayName()));
|
out.putString("name", Component.Serializer.toJson(this.getEntity().getName()));
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +40,12 @@ public class EntityIota extends Iota {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public EntityIota deserialize(Tag tag, ServerLevel world) throws IllegalArgumentException {
|
public EntityIota deserialize(Tag tag, ServerLevel world) throws IllegalArgumentException {
|
||||||
var uuid = NbtUtils.loadUUID(tag);
|
var ctag = HexUtils.downcast(tag, CompoundTag.TYPE);
|
||||||
|
Tag uuidTag = ctag.get("uuid");
|
||||||
|
if (uuidTag == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var uuid = NbtUtils.loadUUID(uuidTag);
|
||||||
var entity = world.getEntity(uuid);
|
var entity = world.getEntity(uuid);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -48,7 +55,14 @@ public class EntityIota extends Iota {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component display(Tag tag) {
|
public Component display(Tag tag) {
|
||||||
return null;
|
if (!(tag instanceof CompoundTag ctag)) {
|
||||||
|
return new TranslatableComponent("hexcasting.spelldata.entity.whoknows");
|
||||||
|
}
|
||||||
|
if (!ctag.contains("name", Tag.TAG_STRING)) {
|
||||||
|
return new TranslatableComponent("hexcasting.spelldata.entity.whoknows");
|
||||||
|
}
|
||||||
|
var nameJson = ctag.getString("name");
|
||||||
|
return Component.Serializer.fromJsonLenient(nameJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,6 +30,11 @@ public abstract class Iota {
|
||||||
*/
|
*/
|
||||||
abstract public boolean toleratesOther(Iota that);
|
abstract public boolean toleratesOther(Iota that);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize this under the {@code data} tag.
|
||||||
|
* <p>
|
||||||
|
* You probably don't want to call this directly; use {@link HexIotaTypes#serialize}.
|
||||||
|
*/
|
||||||
abstract public @NotNull Tag serialize();
|
abstract public @NotNull Tag serialize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
@file:JvmName("ManaHelper")
|
@file:JvmName("ManaHelper")
|
||||||
|
|
||||||
package at.petrak.hexcasting.api.utils
|
package at.petrak.hexcasting.api.utils
|
||||||
|
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||||
|
@ -10,7 +11,7 @@ fun isManaItem(stack: ItemStack): Boolean {
|
||||||
val manaHolder = IXplatAbstractions.INSTANCE.findManaHolder(stack) ?: return false
|
val manaHolder = IXplatAbstractions.INSTANCE.findManaHolder(stack) ?: return false
|
||||||
if (!manaHolder.canProvide())
|
if (!manaHolder.canProvide())
|
||||||
return false
|
return false
|
||||||
return manaHolder.withdrawMana(-1, true) > 0
|
return manaHolder.withdrawMedia(-1, true) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +34,7 @@ fun extractMana(
|
||||||
if (drainForBatteries && !manaHolder.canConstructBattery())
|
if (drainForBatteries && !manaHolder.canConstructBattery())
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return manaHolder.withdrawMana(cost, simulate)
|
return manaHolder.withdrawMedia(cost, simulate)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +47,7 @@ fun compareManaItem(astack: ItemStack, bstack: ItemStack): Int {
|
||||||
return if (astack.item != bstack.item) {
|
return if (astack.item != bstack.item) {
|
||||||
(aMana?.consumptionPriority ?: 0) - (bMana?.consumptionPriority ?: 0)
|
(aMana?.consumptionPriority ?: 0) - (bMana?.consumptionPriority ?: 0)
|
||||||
} else if (aMana != null && bMana != null) {
|
} else if (aMana != null && bMana != null) {
|
||||||
aMana.mana - bMana.mana
|
aMana.media - bMana.media
|
||||||
} else {
|
} else {
|
||||||
astack.count - bstack.count
|
astack.count - bstack.count
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package at.petrak.hexcasting.client;
|
||||||
import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus;
|
import at.petrak.hexcasting.api.block.circle.BlockAbstractImpetus;
|
||||||
import at.petrak.hexcasting.api.block.circle.BlockEntityAbstractImpetus;
|
import at.petrak.hexcasting.api.block.circle.BlockEntityAbstractImpetus;
|
||||||
import at.petrak.hexcasting.api.client.ScryingLensOverlayRegistry;
|
import at.petrak.hexcasting.api.client.ScryingLensOverlayRegistry;
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
import at.petrak.hexcasting.api.item.MediaHolderItem;
|
||||||
import at.petrak.hexcasting.api.misc.ManaConstants;
|
import at.petrak.hexcasting.api.misc.ManaConstants;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
import at.petrak.hexcasting.api.spell.Widget;
|
import at.petrak.hexcasting.api.spell.Widget;
|
||||||
|
@ -20,7 +20,7 @@ import at.petrak.hexcasting.common.items.ItemFocus;
|
||||||
import at.petrak.hexcasting.common.items.ItemScroll;
|
import at.petrak.hexcasting.common.items.ItemScroll;
|
||||||
import at.petrak.hexcasting.common.items.ItemSlate;
|
import at.petrak.hexcasting.common.items.ItemSlate;
|
||||||
import at.petrak.hexcasting.common.items.ItemWand;
|
import at.petrak.hexcasting.common.items.ItemWand;
|
||||||
import at.petrak.hexcasting.common.items.magic.ItemManaBattery;
|
import at.petrak.hexcasting.common.items.magic.ItemMediaBattery;
|
||||||
import at.petrak.hexcasting.common.items.magic.ItemPackagedHex;
|
import at.petrak.hexcasting.common.items.magic.ItemPackagedHex;
|
||||||
import at.petrak.hexcasting.common.lib.HexBlockEntities;
|
import at.petrak.hexcasting.common.lib.HexBlockEntities;
|
||||||
import at.petrak.hexcasting.common.lib.HexBlocks;
|
import at.petrak.hexcasting.common.lib.HexBlocks;
|
||||||
|
@ -61,15 +61,15 @@ public class RegisterClientStuff {
|
||||||
registerPackagedSpellOverrides(HexItems.ARTIFACT);
|
registerPackagedSpellOverrides(HexItems.ARTIFACT);
|
||||||
|
|
||||||
var x = IClientXplatAbstractions.INSTANCE;
|
var x = IClientXplatAbstractions.INSTANCE;
|
||||||
x.registerItemProperty(HexItems.BATTERY, ItemManaBattery.MANA_PREDICATE,
|
x.registerItemProperty(HexItems.BATTERY, ItemMediaBattery.MANA_PREDICATE,
|
||||||
(stack, level, holder, holderID) -> {
|
(stack, level, holder, holderID) -> {
|
||||||
var item = (ManaHolderItem) stack.getItem();
|
var item = (MediaHolderItem) stack.getItem();
|
||||||
return item.getManaFullness(stack);
|
return item.getManaFullness(stack);
|
||||||
});
|
});
|
||||||
x.registerItemProperty(HexItems.BATTERY, ItemManaBattery.MAX_MANA_PREDICATE,
|
x.registerItemProperty(HexItems.BATTERY, ItemMediaBattery.MAX_MANA_PREDICATE,
|
||||||
(stack, level, holder, holderID) -> {
|
(stack, level, holder, holderID) -> {
|
||||||
var item = (ItemManaBattery) stack.getItem();
|
var item = (ItemMediaBattery) stack.getItem();
|
||||||
var max = item.getMaxMana(stack);
|
var max = item.getMaxMedia(stack);
|
||||||
return (float) Math.sqrt((float) max / ManaConstants.CRYSTAL_UNIT / 10);
|
return (float) Math.sqrt((float) max / ManaConstants.CRYSTAL_UNIT / 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -253,11 +253,11 @@ public class RegisterClientStuff {
|
||||||
(stack, level, holder, holderID) -> NBTHelper.hasString(stack, ItemScroll.TAG_OP_ID) ? 1f : 0f);
|
(stack, level, holder, holderID) -> NBTHelper.hasString(stack, ItemScroll.TAG_OP_ID) ? 1f : 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerDataHolderOverrides(DataHolderItem item) {
|
private static void registerDataHolderOverrides(IotaHolderItem item) {
|
||||||
IClientXplatAbstractions.INSTANCE.registerItemProperty((Item) item, ItemFocus.DATATYPE_PRED,
|
IClientXplatAbstractions.INSTANCE.registerItemProperty((Item) item, ItemFocus.DATATYPE_PRED,
|
||||||
(stack, level, holder, holderID) -> {
|
(stack, level, holder, holderID) -> {
|
||||||
var datum = item.readDatumTag(stack);
|
var datum = item.readIotaTag(stack);
|
||||||
String override = NBTHelper.getString(stack, DataHolderItem.TAG_OVERRIDE_VISUALLY);
|
String override = NBTHelper.getString(stack, IotaHolderItem.TAG_OVERRIDE_VISUALLY);
|
||||||
String typename = null;
|
String typename = null;
|
||||||
if (override != null) {
|
if (override != null) {
|
||||||
typename = override;
|
typename = override;
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class BlockStoredPlayerImpetus extends BlockAbstractImpetus {
|
||||||
var datumContainer = IXplatAbstractions.INSTANCE.findDataHolder(usedStack);
|
var datumContainer = IXplatAbstractions.INSTANCE.findDataHolder(usedStack);
|
||||||
if (datumContainer != null) {
|
if (datumContainer != null) {
|
||||||
if (pLevel instanceof ServerLevel level) {
|
if (pLevel instanceof ServerLevel level) {
|
||||||
var stored = datumContainer.readDatum(level);
|
var stored = datumContainer.readIota(level);
|
||||||
if (stored != null && stored.getType() == DatumType.ENTITY) {
|
if (stored != null && stored.getType() == DatumType.ENTITY) {
|
||||||
var entity = (Entity) stored.getPayload();
|
var entity = (Entity) stored.getPayload();
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
|
@ -61,7 +61,7 @@ public class BlockStoredPlayerImpetus extends BlockAbstractImpetus {
|
||||||
level.sendBlockUpdated(pPos, pState, pState, Block.UPDATE_CLIENTS);
|
level.sendBlockUpdated(pPos, pState, pState, Block.UPDATE_CLIENTS);
|
||||||
|
|
||||||
pLevel.playSound(null, pPos, HexSounds.IMPETUS_STOREDPLAYER_DING, SoundSource.BLOCKS,
|
pLevel.playSound(null, pPos, HexSounds.IMPETUS_STOREDPLAYER_DING, SoundSource.BLOCKS,
|
||||||
1f, 1f);
|
1f, 1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,14 @@ object OpRead : ConstManaOperator {
|
||||||
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
|
override fun execute(args: List<LegacySpellDatum<*>>, ctx: CastingContext): List<LegacySpellDatum<*>> {
|
||||||
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
||||||
val dataHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
val dataHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
||||||
dataHolder != null && (dataHolder.readDatum(ctx.world) != null || dataHolder.emptyDatum() != null)
|
dataHolder != null && (dataHolder.readIota(ctx.world) != null || dataHolder.emptyIota() != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
||||||
?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read")
|
?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read")
|
||||||
|
|
||||||
val datum = datumHolder.readDatum(ctx.world)
|
val datum = datumHolder.readIota(ctx.world)
|
||||||
?: datumHolder.emptyDatum()
|
?: datumHolder.emptyIota()
|
||||||
?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read")
|
?: throw MishapBadOffhandItem.of(handStack, hand, "iota.read")
|
||||||
|
|
||||||
return listOf(datum)
|
return listOf(datum)
|
||||||
|
|
|
@ -17,8 +17,8 @@ object OpReadable : ConstManaOperator {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
||||||
?: return false.asSpellResult
|
?: return false.asSpellResult
|
||||||
|
|
||||||
datumHolder.readDatum(ctx.world)
|
datumHolder.readIota(ctx.world)
|
||||||
?: datumHolder.emptyDatum()
|
?: datumHolder.emptyIota()
|
||||||
?: return false.asSpellResult
|
?: return false.asSpellResult
|
||||||
|
|
||||||
return true.asSpellResult
|
return true.asSpellResult
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package at.petrak.hexcasting.common.casting.operators
|
package at.petrak.hexcasting.common.casting.operators
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
import at.petrak.hexcasting.api.spell.ConstManaOperator
|
||||||
import at.petrak.hexcasting.api.spell.getChecked
|
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum
|
||||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||||
|
import at.petrak.hexcasting.api.spell.getChecked
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem
|
import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem
|
||||||
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
import at.petrak.hexcasting.xplat.IXplatAbstractions
|
||||||
import net.minecraft.world.entity.item.ItemEntity
|
import net.minecraft.world.entity.item.ItemEntity
|
||||||
|
@ -23,8 +23,8 @@ object OpTheCoolerRead : ConstManaOperator {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack)
|
||||||
?: throw MishapBadItem.of(target, "iota.read")
|
?: throw MishapBadItem.of(target, "iota.read")
|
||||||
|
|
||||||
val datum = datumHolder.readDatum(ctx.world)
|
val datum = datumHolder.readIota(ctx.world)
|
||||||
?: datumHolder.emptyDatum()
|
?: datumHolder.emptyIota()
|
||||||
?: throw MishapBadItem.of(target, "iota.read")
|
?: throw MishapBadItem.of(target, "iota.read")
|
||||||
return listOf(datum)
|
return listOf(datum)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ object OpTheCoolerReadable : ConstManaOperator {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(stack)
|
||||||
?: return false.asSpellResult
|
?: return false.asSpellResult
|
||||||
|
|
||||||
if (datumHolder.readDatum(ctx.world) == null && datumHolder.emptyDatum() == null)
|
if (datumHolder.readIota(ctx.world) == null && datumHolder.emptyIota() == null)
|
||||||
return false.asSpellResult
|
return false.asSpellResult
|
||||||
|
|
||||||
return true.asSpellResult
|
return true.asSpellResult
|
||||||
|
|
|
@ -16,12 +16,12 @@ object OpWritable : ConstManaOperator {
|
||||||
val (handStack) = ctx.getHeldItemToOperateOn {
|
val (handStack) = ctx.getHeldItemToOperateOn {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
||||||
|
|
||||||
datumHolder != null && datumHolder.writeDatum(datum, true)
|
datumHolder != null && datumHolder.writeIota(datum, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) ?: return false.asSpellResult
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack) ?: return false.asSpellResult
|
||||||
|
|
||||||
if (!datumHolder.writeDatum(datum, true))
|
if (!datumHolder.writeIota(datum, true))
|
||||||
return false.asSpellResult
|
return false.asSpellResult
|
||||||
|
|
||||||
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
|
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package at.petrak.hexcasting.common.casting.operators
|
package at.petrak.hexcasting.common.casting.operators
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum
|
||||||
import at.petrak.hexcasting.api.spell.ParticleSpray
|
import at.petrak.hexcasting.api.spell.ParticleSpray
|
||||||
import at.petrak.hexcasting.api.spell.RenderedSpell
|
import at.petrak.hexcasting.api.spell.RenderedSpell
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum
|
|
||||||
import at.petrak.hexcasting.api.spell.SpellOperator
|
import at.petrak.hexcasting.api.spell.SpellOperator
|
||||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
|
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
|
||||||
|
@ -21,13 +21,13 @@ object OpWrite : SpellOperator {
|
||||||
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
||||||
|
|
||||||
datumHolder != null && datumHolder.writeDatum(datum, true)
|
datumHolder != null && datumHolder.writeIota(datum, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
||||||
?: throw MishapBadOffhandItem.of(handStack, hand, "iota.write")
|
?: throw MishapBadOffhandItem.of(handStack, hand, "iota.write")
|
||||||
|
|
||||||
if (!datumHolder.writeDatum(datum, true))
|
if (!datumHolder.writeIota(datum, true))
|
||||||
throw MishapBadOffhandItem.of(handStack, hand, "iota.readonly", datum.display())
|
throw MishapBadOffhandItem.of(handStack, hand, "iota.readonly", datum.display())
|
||||||
|
|
||||||
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
|
val trueName = MishapOthersName.getTrueNameFromDatum(datum, ctx.caster)
|
||||||
|
@ -46,11 +46,11 @@ object OpWrite : SpellOperator {
|
||||||
val (handStack) = ctx.getHeldItemToOperateOn {
|
val (handStack) = ctx.getHeldItemToOperateOn {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
||||||
|
|
||||||
datumHolder != null && datumHolder.writeDatum(datum, true)
|
datumHolder != null && datumHolder.writeIota(datum, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
||||||
datumHolder?.writeDatum(datum, false)
|
datumHolder?.writeIota(datum, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package at.petrak.hexcasting.common.casting.operators.spells
|
package at.petrak.hexcasting.common.casting.operators.spells
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.misc.ManaConstants
|
import at.petrak.hexcasting.api.misc.ManaConstants
|
||||||
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum
|
||||||
import at.petrak.hexcasting.api.spell.ParticleSpray
|
import at.petrak.hexcasting.api.spell.ParticleSpray
|
||||||
import at.petrak.hexcasting.api.spell.RenderedSpell
|
import at.petrak.hexcasting.api.spell.RenderedSpell
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum
|
|
||||||
import at.petrak.hexcasting.api.spell.SpellOperator
|
import at.petrak.hexcasting.api.spell.SpellOperator
|
||||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
|
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
|
||||||
|
@ -21,13 +21,13 @@ class OpErase : SpellOperator {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
||||||
|
|
||||||
(hexHolder?.hasHex() == true) ||
|
(hexHolder?.hasHex() == true) ||
|
||||||
(datumHolder?.writeDatum(null, true) == true)
|
(datumHolder?.writeIota(null, true) == true)
|
||||||
}
|
}
|
||||||
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack)
|
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack)
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
||||||
|
|
||||||
if ((hexHolder?.hasHex() != true) &&
|
if ((hexHolder?.hasHex() != true) &&
|
||||||
(datumHolder?.writeDatum(null, true) != true)
|
(datumHolder?.writeIota(null, true) != true)
|
||||||
) {
|
) {
|
||||||
throw MishapBadOffhandItem.of(handStack, hand, "eraseable")
|
throw MishapBadOffhandItem.of(handStack, hand, "eraseable")
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class OpErase : SpellOperator {
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(it)
|
||||||
|
|
||||||
(hexHolder?.hasHex() == true) ||
|
(hexHolder?.hasHex() == true) ||
|
||||||
(datumHolder?.writeDatum(null, true) == true)
|
(datumHolder?.writeIota(null, true) == true)
|
||||||
}
|
}
|
||||||
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack)
|
val hexHolder = IXplatAbstractions.INSTANCE.findHexHolder(handStack)
|
||||||
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
val datumHolder = IXplatAbstractions.INSTANCE.findDataHolder(handStack)
|
||||||
|
@ -53,8 +53,8 @@ class OpErase : SpellOperator {
|
||||||
if (hexHolder?.hasHex() == true)
|
if (hexHolder?.hasHex() == true)
|
||||||
hexHolder.clearHex()
|
hexHolder.clearHex()
|
||||||
|
|
||||||
if (datumHolder != null && datumHolder.writeDatum(null, true))
|
if (datumHolder != null && datumHolder.writeIota(null, true))
|
||||||
datumHolder.writeDatum(null, false)
|
datumHolder.writeIota(null, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,13 @@ package at.petrak.hexcasting.common.casting.operators.spells
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.misc.ManaConstants
|
import at.petrak.hexcasting.api.misc.ManaConstants
|
||||||
import at.petrak.hexcasting.api.mod.HexItemTags
|
import at.petrak.hexcasting.api.mod.HexItemTags
|
||||||
import at.petrak.hexcasting.api.spell.getChecked
|
import at.petrak.hexcasting.api.spell.*
|
||||||
import at.petrak.hexcasting.api.spell.ParticleSpray
|
|
||||||
import at.petrak.hexcasting.api.spell.RenderedSpell
|
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum
|
|
||||||
import at.petrak.hexcasting.api.spell.SpellOperator
|
|
||||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem
|
import at.petrak.hexcasting.api.spell.mishaps.MishapBadItem
|
||||||
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
|
import at.petrak.hexcasting.api.spell.mishaps.MishapBadOffhandItem
|
||||||
import at.petrak.hexcasting.api.utils.extractMana
|
import at.petrak.hexcasting.api.utils.extractMana
|
||||||
import at.petrak.hexcasting.api.utils.isManaItem
|
import at.petrak.hexcasting.api.utils.isManaItem
|
||||||
import at.petrak.hexcasting.common.items.magic.ItemManaHolder
|
import at.petrak.hexcasting.common.items.magic.ItemMediaHolder
|
||||||
import at.petrak.hexcasting.common.lib.HexItems
|
import at.petrak.hexcasting.common.lib.HexItems
|
||||||
import net.minecraft.world.entity.item.ItemEntity
|
import net.minecraft.world.entity.item.ItemEntity
|
||||||
import net.minecraft.world.item.ItemStack
|
import net.minecraft.world.item.ItemStack
|
||||||
|
@ -59,8 +55,10 @@ object OpMakeBattery : SpellOperator {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Triple(Spell(entity),
|
return Triple(
|
||||||
ManaConstants.CRYSTAL_UNIT, listOf(ParticleSpray.burst(entity.position(), 0.5)))
|
Spell(entity),
|
||||||
|
ManaConstants.CRYSTAL_UNIT, listOf(ParticleSpray.burst(entity.position(), 0.5))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class Spell(val itemEntity: ItemEntity) : RenderedSpell {
|
private data class Spell(val itemEntity: ItemEntity) : RenderedSpell {
|
||||||
|
@ -72,7 +70,7 @@ object OpMakeBattery : SpellOperator {
|
||||||
if (manaAmt > 0) {
|
if (manaAmt > 0) {
|
||||||
ctx.caster.setItemInHand(
|
ctx.caster.setItemInHand(
|
||||||
hand,
|
hand,
|
||||||
ItemManaHolder.withMana(ItemStack(HexItems.BATTERY), manaAmt, manaAmt)
|
ItemMediaHolder.withMana(ItemStack(HexItems.BATTERY), manaAmt, manaAmt)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ object OpRecharge : SpellOperator {
|
||||||
): Triple<RenderedSpell, Int, List<ParticleSpray>>? {
|
): Triple<RenderedSpell, Int, List<ParticleSpray>>? {
|
||||||
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
val (handStack, hand) = ctx.getHeldItemToOperateOn {
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
||||||
mana != null && mana.canRecharge() && mana.mana /* doo doo da do doo */ < mana.maxMana
|
mana != null && mana.canRecharge() && mana.media /* doo doo da do doo */ < mana.maxMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
||||||
|
@ -40,7 +40,7 @@ object OpRecharge : SpellOperator {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mana.mana >= mana.maxMana)
|
if (mana.media >= mana.maxMedia)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
return Triple(
|
return Triple(
|
||||||
|
@ -54,19 +54,19 @@ object OpRecharge : SpellOperator {
|
||||||
override fun cast(ctx: CastingContext) {
|
override fun cast(ctx: CastingContext) {
|
||||||
val (handStack) = ctx.getHeldItemToOperateOn {
|
val (handStack) = ctx.getHeldItemToOperateOn {
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(it)
|
||||||
mana != null && mana.canRecharge() && mana.mana < mana.maxMana
|
mana != null && mana.canRecharge() && mana.media < mana.maxMedia
|
||||||
}
|
}
|
||||||
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
val mana = IXplatAbstractions.INSTANCE.findManaHolder(handStack)
|
||||||
|
|
||||||
if (mana != null && itemEntity.isAlive) {
|
if (mana != null && itemEntity.isAlive) {
|
||||||
val entityStack = itemEntity.item.copy()
|
val entityStack = itemEntity.item.copy()
|
||||||
|
|
||||||
val maxMana = mana.maxMana
|
val maxMana = mana.maxMedia
|
||||||
val existingMana = mana.mana
|
val existingMana = mana.media
|
||||||
|
|
||||||
val manaAmt = extractMana(entityStack, maxMana - existingMana)
|
val manaAmt = extractMana(entityStack, maxMana - existingMana)
|
||||||
|
|
||||||
mana.mana = manaAmt + existingMana
|
mana.media = manaAmt + existingMana
|
||||||
|
|
||||||
itemEntity.item = entityStack
|
itemEntity.item = entityStack
|
||||||
if (entityStack.isEmpty)
|
if (entityStack.isEmpty)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items;
|
package at.petrak.hexcasting.common.items;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
import at.petrak.hexcasting.common.lib.HexSounds;
|
import at.petrak.hexcasting.common.lib.HexSounds;
|
||||||
|
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemAbacus extends Item implements DataHolderItem {
|
public class ItemAbacus extends Item implements IotaHolderItem {
|
||||||
public static final String TAG_VALUE = "value";
|
public static final String TAG_VALUE = "value";
|
||||||
|
|
||||||
public ItemAbacus(Properties pProperties) {
|
public ItemAbacus(Properties pProperties) {
|
||||||
|
@ -26,7 +26,7 @@ public class ItemAbacus extends Item implements DataHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable CompoundTag readDatumTag(ItemStack stack) {
|
public @Nullable CompoundTag readIotaTag(ItemStack stack) {
|
||||||
var datum = LegacySpellDatum.make(NBTHelper.getDouble(stack, TAG_VALUE));
|
var datum = LegacySpellDatum.make(NBTHelper.getDouble(stack, TAG_VALUE));
|
||||||
return datum.serializeToNBT();
|
return datum.serializeToNBT();
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,6 @@ public class ItemAbacus extends Item implements DataHolderItem {
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
|
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
|
||||||
TooltipFlag pIsAdvanced) {
|
TooltipFlag pIsAdvanced) {
|
||||||
DataHolderItem.appendHoverText(this, pStack, pTooltipComponents, pIsAdvanced);
|
IotaHolderItem.appendHoverText(this, pStack, pTooltipComponents, pIsAdvanced);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items;
|
package at.petrak.hexcasting.common.items;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
import at.petrak.hexcasting.api.spell.Widget;
|
import at.petrak.hexcasting.api.spell.Widget;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||||
|
|
||||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
|
|
||||||
public class ItemFocus extends Item implements DataHolderItem {
|
public class ItemFocus extends Item implements IotaHolderItem {
|
||||||
public static final ResourceLocation DATATYPE_PRED = modLoc("datatype");
|
public static final ResourceLocation DATATYPE_PRED = modLoc("datatype");
|
||||||
public static final ResourceLocation SEALED_PRED = modLoc("sealed");
|
public static final ResourceLocation SEALED_PRED = modLoc("sealed");
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class ItemFocus extends Item implements DataHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable CompoundTag readDatumTag(ItemStack stack) {
|
public @Nullable CompoundTag readIotaTag(ItemStack stack) {
|
||||||
return NBTHelper.getCompound(stack, TAG_DATA);
|
return NBTHelper.getCompound(stack, TAG_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class ItemFocus extends Item implements DataHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable LegacySpellDatum<?> emptyDatum(ItemStack stack) {
|
public @Nullable LegacySpellDatum<?> emptyIota(ItemStack stack) {
|
||||||
return LegacySpellDatum.make(Widget.NULL);
|
return LegacySpellDatum.make(Widget.NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,6 @@ public class ItemFocus extends Item implements DataHolderItem {
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
|
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
|
||||||
TooltipFlag pIsAdvanced) {
|
TooltipFlag pIsAdvanced) {
|
||||||
DataHolderItem.appendHoverText(this, pStack, pTooltipComponents, pIsAdvanced);
|
IotaHolderItem.appendHoverText(this, pStack, pTooltipComponents, pIsAdvanced);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items;
|
package at.petrak.hexcasting.common.items;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.spell.DatumType;
|
import at.petrak.hexcasting.api.spell.DatumType;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
import at.petrak.hexcasting.api.spell.math.HexPattern;
|
import at.petrak.hexcasting.api.spell.math.HexPattern;
|
||||||
|
@ -36,7 +36,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
* <br>
|
* <br>
|
||||||
* TAG_OP_ID: invalid
|
* TAG_OP_ID: invalid
|
||||||
*/
|
*/
|
||||||
public class ItemScroll extends Item implements DataHolderItem {
|
public class ItemScroll extends Item implements IotaHolderItem {
|
||||||
public static final String TAG_OP_ID = "op_id";
|
public static final String TAG_OP_ID = "op_id";
|
||||||
public static final String TAG_PATTERN = "pattern";
|
public static final String TAG_PATTERN = "pattern";
|
||||||
public static final ResourceLocation ANCIENT_PREDICATE = modLoc("ancient");
|
public static final ResourceLocation ANCIENT_PREDICATE = modLoc("ancient");
|
||||||
|
@ -49,7 +49,7 @@ public class ItemScroll extends Item implements DataHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable CompoundTag readDatumTag(ItemStack stack) {
|
public @Nullable CompoundTag readIotaTag(ItemStack stack) {
|
||||||
CompoundTag pattern = NBTHelper.getCompound(stack, TAG_PATTERN);
|
CompoundTag pattern = NBTHelper.getCompound(stack, TAG_PATTERN);
|
||||||
if (pattern == null) {
|
if (pattern == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -2,12 +2,12 @@ package at.petrak.hexcasting.common.items;
|
||||||
|
|
||||||
import at.petrak.hexcasting.annotations.SoftImplement;
|
import at.petrak.hexcasting.annotations.SoftImplement;
|
||||||
import at.petrak.hexcasting.api.HexAPI;
|
import at.petrak.hexcasting.api.HexAPI;
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.spell.DatumType;
|
import at.petrak.hexcasting.api.spell.DatumType;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
import at.petrak.hexcasting.api.spell.math.HexPattern;
|
import at.petrak.hexcasting.api.spell.math.HexPattern;
|
||||||
import at.petrak.hexcasting.client.gui.PatternTooltipGreeble;
|
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
|
import at.petrak.hexcasting.client.gui.PatternTooltipGreeble;
|
||||||
import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate;
|
import at.petrak.hexcasting.common.blocks.circles.BlockEntitySlate;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
|
@ -27,7 +27,7 @@ import java.util.Optional;
|
||||||
|
|
||||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
|
|
||||||
public class ItemSlate extends BlockItem implements DataHolderItem {
|
public class ItemSlate extends BlockItem implements IotaHolderItem {
|
||||||
public static final ResourceLocation WRITTEN_PRED = modLoc("written");
|
public static final ResourceLocation WRITTEN_PRED = modLoc("written");
|
||||||
|
|
||||||
public ItemSlate(Block pBlock, Properties pProperties) {
|
public ItemSlate(Block pBlock, Properties pProperties) {
|
||||||
|
@ -51,19 +51,21 @@ public class ItemSlate extends BlockItem implements DataHolderItem {
|
||||||
|
|
||||||
@SoftImplement("IForgeItem")
|
@SoftImplement("IForgeItem")
|
||||||
public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) {
|
public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) {
|
||||||
if (!hasPattern(stack))
|
if (!hasPattern(stack)) {
|
||||||
NBTHelper.remove(stack, "BlockEntityTag");
|
NBTHelper.remove(stack, "BlockEntityTag");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) {
|
public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) {
|
||||||
if (!hasPattern(pStack))
|
if (!hasPattern(pStack)) {
|
||||||
NBTHelper.remove(pStack, "BlockEntityTag");
|
NBTHelper.remove(pStack, "BlockEntityTag");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable CompoundTag readDatumTag(ItemStack stack) {
|
public @Nullable CompoundTag readIotaTag(ItemStack stack) {
|
||||||
var bet = NBTHelper.getCompound(stack, "BlockEntityTag");
|
var bet = NBTHelper.getCompound(stack, "BlockEntityTag");
|
||||||
|
|
||||||
if (bet == null || !bet.contains(BlockEntitySlate.TAG_PATTERN, Tag.TAG_COMPOUND)) {
|
if (bet == null || !bet.contains(BlockEntitySlate.TAG_PATTERN, Tag.TAG_COMPOUND)) {
|
||||||
|
@ -90,8 +92,9 @@ public class ItemSlate extends BlockItem implements DataHolderItem {
|
||||||
if (datum == null) {
|
if (datum == null) {
|
||||||
var beTag = NBTHelper.getOrCreateCompound(stack, "BlockEntityTag");
|
var beTag = NBTHelper.getOrCreateCompound(stack, "BlockEntityTag");
|
||||||
beTag.remove(BlockEntitySlate.TAG_PATTERN);
|
beTag.remove(BlockEntitySlate.TAG_PATTERN);
|
||||||
if (beTag.isEmpty())
|
if (beTag.isEmpty()) {
|
||||||
NBTHelper.remove(stack, "BlockEntityTag");
|
NBTHelper.remove(stack, "BlockEntityTag");
|
||||||
|
}
|
||||||
} else if (datum.getPayload() instanceof HexPattern pat) {
|
} else if (datum.getPayload() instanceof HexPattern pat) {
|
||||||
var beTag = NBTHelper.getOrCreateCompound(stack, "BlockEntityTag");
|
var beTag = NBTHelper.getOrCreateCompound(stack, "BlockEntityTag");
|
||||||
beTag.put(BlockEntitySlate.TAG_PATTERN, pat.serializeToNBT());
|
beTag.put(BlockEntitySlate.TAG_PATTERN, pat.serializeToNBT());
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items;
|
package at.petrak.hexcasting.common.items;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
import at.petrak.hexcasting.api.spell.Widget;
|
import at.petrak.hexcasting.api.spell.Widget;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
|
@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ItemSpellbook extends Item implements DataHolderItem {
|
public class ItemSpellbook extends Item implements IotaHolderItem {
|
||||||
public static String TAG_SELECTED_PAGE = "page_idx";
|
public static String TAG_SELECTED_PAGE = "page_idx";
|
||||||
// this is a CompoundTag of string numerical keys to SpellData
|
// this is a CompoundTag of string numerical keys to SpellData
|
||||||
// it is 1-indexed, so that 0/0 can be the special case of "it is empty"
|
// it is 1-indexed, so that 0/0 can be the special case of "it is empty"
|
||||||
|
@ -86,7 +86,7 @@ public class ItemSpellbook extends Item implements DataHolderItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataHolderItem.appendHoverText(this, stack, tooltip, isAdvanced);
|
IotaHolderItem.appendHoverText(this, stack, tooltip, isAdvanced);
|
||||||
|
|
||||||
super.appendHoverText(stack, level, tooltip, isAdvanced);
|
super.appendHoverText(stack, level, tooltip, isAdvanced);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ public class ItemSpellbook extends Item implements DataHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable CompoundTag readDatumTag(ItemStack stack) {
|
public @Nullable CompoundTag readIotaTag(ItemStack stack) {
|
||||||
int idx = GetPage(stack, 1);
|
int idx = GetPage(stack, 1);
|
||||||
var key = String.valueOf(idx);
|
var key = String.valueOf(idx);
|
||||||
var tag = NBTHelper.getCompound(stack, TAG_PAGES);
|
var tag = NBTHelper.getCompound(stack, TAG_PAGES);
|
||||||
|
@ -124,7 +124,7 @@ public class ItemSpellbook extends Item implements DataHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable LegacySpellDatum<?> emptyDatum(ItemStack stack) {
|
public @Nullable LegacySpellDatum<?> emptyIota(ItemStack stack) {
|
||||||
return LegacySpellDatum.make(Widget.NULL);
|
return LegacySpellDatum.make(Widget.NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items.colorizer;
|
package at.petrak.hexcasting.common.items.colorizer;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.Colorizer;
|
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 net.minecraft.Util;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
@ -44,7 +44,7 @@ public class ItemPrideColorizer extends Item implements ColorizerItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int color(ItemStack stack, UUID owner, float time, Vec3 position) {
|
public int color(ItemStack stack, UUID owner, float time, Vec3 position) {
|
||||||
return Colorizer.morphBetweenColors(getColors(), new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position);
|
return ADColorizer.morphBetweenColors(getColors(), new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getColors() {
|
public int[] getColors() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items.colorizer;
|
package at.petrak.hexcasting.common.items.colorizer;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.Colorizer;
|
import at.petrak.hexcasting.api.addldata.ADColorizer;
|
||||||
import at.petrak.hexcasting.api.item.ColorizerItem;
|
import at.petrak.hexcasting.api.item.ColorizerItem;
|
||||||
import at.petrak.paucal.api.PaucalAPI;
|
import at.petrak.paucal.api.PaucalAPI;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
@ -35,7 +35,7 @@ public class ItemUUIDColorizer extends Item implements ColorizerItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ok) {
|
if (ok) {
|
||||||
return Colorizer.morphBetweenColors(colors, new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position);
|
return ADColorizer.morphBetweenColors(colors, new Vec3(0.1, 0.1, 0.1), time / 20 / 20, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items.magic;
|
package at.petrak.hexcasting.common.items.magic;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
import at.petrak.hexcasting.api.item.MediaHolderItem;
|
||||||
import at.petrak.hexcasting.api.misc.ManaConstants;
|
import at.petrak.hexcasting.api.misc.ManaConstants;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
|
@ -27,7 +27,7 @@ import java.util.Locale;
|
||||||
|
|
||||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
|
|
||||||
public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
public class ItemCreativeUnlocker extends Item implements MediaHolderItem {
|
||||||
|
|
||||||
public static boolean isDebug(ItemStack stack) {
|
public static boolean isDebug(ItemStack stack) {
|
||||||
return stack.is(HexItems.CREATIVE_UNLOCKER)
|
return stack.is(HexItems.CREATIVE_UNLOCKER)
|
||||||
|
@ -42,22 +42,22 @@ public class ItemCreativeUnlocker extends Item implements ManaHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMana(ItemStack stack) {
|
public int getMedia(ItemStack stack) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxMana(ItemStack stack) {
|
public int getMaxMedia(ItemStack stack) {
|
||||||
return Integer.MAX_VALUE - 1;
|
return Integer.MAX_VALUE - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMana(ItemStack stack, int mana) {
|
public void setMedia(ItemStack stack, int media) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean manaProvider(ItemStack stack) {
|
public boolean canProvideMedia(ItemStack stack) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,16 +9,16 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
|
|
||||||
public class ItemManaBattery extends ItemManaHolder {
|
public class ItemMediaBattery extends ItemMediaHolder {
|
||||||
public static final ResourceLocation MANA_PREDICATE = modLoc("mana");
|
public static final ResourceLocation MANA_PREDICATE = modLoc("mana");
|
||||||
public static final ResourceLocation MAX_MANA_PREDICATE = modLoc("max_mana");
|
public static final ResourceLocation MAX_MANA_PREDICATE = modLoc("max_mana");
|
||||||
|
|
||||||
public ItemManaBattery(Properties pProperties) {
|
public ItemMediaBattery(Properties pProperties) {
|
||||||
super(pProperties);
|
super(pProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean manaProvider(ItemStack stack) {
|
public boolean canProvideMedia(ItemStack stack) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class ItemManaBattery extends ItemManaHolder {
|
||||||
};
|
};
|
||||||
for (int manamount : manamounts) {
|
for (int manamount : manamounts) {
|
||||||
var stack = new ItemStack(this);
|
var stack = new ItemStack(this);
|
||||||
items.add(ItemManaHolder.withMana(stack, manamount, manamount));
|
items.add(ItemMediaHolder.withMana(stack, manamount, manamount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.items.magic;
|
package at.petrak.hexcasting.common.items.magic;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
import at.petrak.hexcasting.api.item.MediaHolderItem;
|
||||||
import at.petrak.hexcasting.api.utils.ManaHelper;
|
import at.petrak.hexcasting.api.utils.ManaHelper;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
|
@ -15,17 +15,17 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class ItemManaHolder extends Item implements ManaHolderItem {
|
public abstract class ItemMediaHolder extends Item implements MediaHolderItem {
|
||||||
public static final String TAG_MANA = "hexcasting:mana";
|
public static final String TAG_MANA = "hexcasting:mana";
|
||||||
public static final String TAG_MAX_MANA = "hexcasting:start_mana";
|
public static final String TAG_MAX_MANA = "hexcasting:start_mana";
|
||||||
|
|
||||||
public ItemManaHolder(Properties pProperties) {
|
public ItemMediaHolder(Properties pProperties) {
|
||||||
super(pProperties);
|
super(pProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack withMana(ItemStack stack, int mana, int maxMana) {
|
public static ItemStack withMana(ItemStack stack, int mana, int maxMana) {
|
||||||
Item item = stack.getItem();
|
Item item = stack.getItem();
|
||||||
if (item instanceof ItemManaHolder) {
|
if (item instanceof ItemMediaHolder) {
|
||||||
NBTHelper.putInt(stack, TAG_MANA, mana);
|
NBTHelper.putInt(stack, TAG_MANA, mana);
|
||||||
NBTHelper.putInt(stack, TAG_MAX_MANA, maxMana);
|
NBTHelper.putInt(stack, TAG_MAX_MANA, maxMana);
|
||||||
}
|
}
|
||||||
|
@ -34,36 +34,36 @@ public abstract class ItemManaHolder extends Item implements ManaHolderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMana(ItemStack stack) {
|
public int getMedia(ItemStack stack) {
|
||||||
return NBTHelper.getInt(stack, TAG_MANA);
|
return NBTHelper.getInt(stack, TAG_MANA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxMana(ItemStack stack) {
|
public int getMaxMedia(ItemStack stack) {
|
||||||
return NBTHelper.getInt(stack, TAG_MAX_MANA);
|
return NBTHelper.getInt(stack, TAG_MAX_MANA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMana(ItemStack stack, int mana) {
|
public void setMedia(ItemStack stack, int media) {
|
||||||
NBTHelper.putInt(stack, TAG_MANA, Mth.clamp(mana, 0, getMaxMana(stack)));
|
NBTHelper.putInt(stack, TAG_MANA, Mth.clamp(media, 0, getMaxMedia(stack)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBarVisible(ItemStack pStack) {
|
public boolean isBarVisible(ItemStack pStack) {
|
||||||
return getMaxMana(pStack) > 0;
|
return getMaxMedia(pStack) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarColor(ItemStack pStack) {
|
public int getBarColor(ItemStack pStack) {
|
||||||
var mana = getMana(pStack);
|
var mana = getMedia(pStack);
|
||||||
var maxMana = getMaxMana(pStack);
|
var maxMana = getMaxMedia(pStack);
|
||||||
return ManaHelper.manaBarColor(mana, maxMana);
|
return ManaHelper.manaBarColor(mana, maxMana);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBarWidth(ItemStack pStack) {
|
public int getBarWidth(ItemStack pStack) {
|
||||||
var mana = getMana(pStack);
|
var mana = getMedia(pStack);
|
||||||
var maxMana = getMaxMana(pStack);
|
var maxMana = getMaxMedia(pStack);
|
||||||
return ManaHelper.manaBarWidth(mana, maxMana);
|
return ManaHelper.manaBarWidth(mana, maxMana);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,11 +75,11 @@ public abstract class ItemManaHolder extends Item implements ManaHolderItem {
|
||||||
@Override
|
@Override
|
||||||
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
|
public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents,
|
||||||
TooltipFlag pIsAdvanced) {
|
TooltipFlag pIsAdvanced) {
|
||||||
if (pIsAdvanced.isAdvanced() && getMaxMana(pStack) > 0) {
|
if (pIsAdvanced.isAdvanced() && getMaxMedia(pStack) > 0) {
|
||||||
pTooltipComponents.add(
|
pTooltipComponents.add(
|
||||||
new TranslatableComponent("item.hexcasting.manaholder.amount",
|
new TranslatableComponent("item.hexcasting.manaholder.amount",
|
||||||
String.format("%,d", getMana(pStack)),
|
String.format("%,d", getMedia(pStack)),
|
||||||
String.format("%,d", getMaxMana(pStack)),
|
String.format("%,d", getMaxMedia(pStack)),
|
||||||
100f * getManaFullness(pStack)).withStyle(ChatFormatting.GRAY));
|
100f * getManaFullness(pStack)).withStyle(ChatFormatting.GRAY));
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
/**
|
/**
|
||||||
* Item that holds a list of patterns in it ready to be cast
|
* Item that holds a list of patterns in it ready to be cast
|
||||||
*/
|
*/
|
||||||
public abstract class ItemPackagedHex extends ItemManaHolder implements HexHolderItem {
|
public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHolderItem {
|
||||||
public static final String TAG_PATTERNS = "patterns";
|
public static final String TAG_PATTERNS = "patterns";
|
||||||
public static final ResourceLocation HAS_PATTERNS_PRED = modLoc("has_patterns");
|
public static final ResourceLocation HAS_PATTERNS_PRED = modLoc("has_patterns");
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public abstract class ItemPackagedHex extends ItemManaHolder implements HexHolde
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean manaProvider(ItemStack stack) {
|
public boolean canProvideMedia(ItemStack stack) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ public abstract class ItemPackagedHex extends ItemManaHolder implements HexHolde
|
||||||
var harness = new CastingHarness(ctx);
|
var harness = new CastingHarness(ctx);
|
||||||
var info = harness.executeIotas(instrs, sPlayer.getLevel());
|
var info = harness.executeIotas(instrs, sPlayer.getLevel());
|
||||||
|
|
||||||
boolean broken = breakAfterDepletion() && getMana(stack) == 0;
|
boolean broken = breakAfterDepletion() && getMedia(stack) == 0;
|
||||||
|
|
||||||
Stat<?> stat;
|
Stat<?> stat;
|
||||||
if (broken) {
|
if (broken) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
@ -26,6 +27,21 @@ public class HexIotaTypes {
|
||||||
KEY_TYPE = HexAPI.MOD_ID + ":type",
|
KEY_TYPE = HexAPI.MOD_ID + ":type",
|
||||||
KEY_DATA = HexAPI.MOD_ID + ":data";
|
KEY_DATA = HexAPI.MOD_ID + ":data";
|
||||||
|
|
||||||
|
public static CompoundTag serialize(Iota iota) {
|
||||||
|
var type = iota.getType();
|
||||||
|
var typeId = REGISTRY.getKey(type);
|
||||||
|
if (typeId == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Tried to serialize an unregistered iota type. Iota: " + iota
|
||||||
|
+ " ; Type" + type.getClass().getTypeName());
|
||||||
|
}
|
||||||
|
var dataTag = iota.serialize();
|
||||||
|
var out = new CompoundTag();
|
||||||
|
out.putString(KEY_TYPE, typeId.toString());
|
||||||
|
out.put(KEY_DATA, dataTag);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method attempts to find the type from the {@code type} key.
|
* This method attempts to find the type from the {@code type} key.
|
||||||
* See {@link HexIotaTypes#getTypeFromTag} for the storage format.
|
* See {@link HexIotaTypes#getTypeFromTag} for the storage format.
|
||||||
|
@ -69,6 +85,19 @@ public class HexIotaTypes {
|
||||||
return type.deserialize(tag, world);
|
return type.deserialize(tag, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static Component getDisplay(CompoundTag tag) {
|
||||||
|
var type = getTypeFromTag(tag);
|
||||||
|
if (type == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var dataKey = tag.get(KEY_DATA);
|
||||||
|
if (dataKey == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return type.display(tag);
|
||||||
|
}
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public static void registerTypes() {
|
public static void registerTypes() {
|
||||||
BiConsumer<IotaType<?>, ResourceLocation> r = (type, id) -> Registry.register(REGISTRY, id, type);
|
BiConsumer<IotaType<?>, ResourceLocation> r = (type, id) -> Registry.register(REGISTRY, id, type);
|
||||||
|
|
|
@ -64,8 +64,8 @@ public class HexItems {
|
||||||
|
|
||||||
public static final ItemSlate SLATE = make("slate", new ItemSlate(HexBlocks.SLATE, props()));
|
public static final ItemSlate SLATE = make("slate", new ItemSlate(HexBlocks.SLATE, props()));
|
||||||
|
|
||||||
public static final ItemManaBattery BATTERY = make("battery",
|
public static final ItemMediaBattery BATTERY = make("battery",
|
||||||
new ItemManaBattery(new Item.Properties().stacksTo(1)));
|
new ItemMediaBattery(new Item.Properties().stacksTo(1)));
|
||||||
|
|
||||||
public static final EnumMap<DyeColor, ItemDyeColorizer> DYE_COLORIZERS = Util.make(() -> {
|
public static final EnumMap<DyeColor, ItemDyeColorizer> DYE_COLORIZERS = Util.make(() -> {
|
||||||
var out = new EnumMap<DyeColor, ItemDyeColorizer>(DyeColor.class);
|
var out = new EnumMap<DyeColor, ItemDyeColorizer>(DyeColor.class);
|
||||||
|
|
|
@ -121,7 +121,7 @@ public record MsgShiftScrollSyn(InteractionHand hand, double scrollDelta, boolea
|
||||||
sender.level.playSound(null, sender.getX(), sender.getY(), sender.getZ(),
|
sender.level.playSound(null, sender.getX(), sender.getY(), sender.getZ(),
|
||||||
HexSounds.ABACUS, SoundSource.PLAYERS, 0.5f, pitch);
|
HexSounds.ABACUS, SoundSource.PLAYERS, 0.5f, pitch);
|
||||||
|
|
||||||
var datumTag = HexItems.ABACUS.readDatumTag(stack);
|
var datumTag = HexItems.ABACUS.readIotaTag(stack);
|
||||||
if (datumTag != null) {
|
if (datumTag != null) {
|
||||||
var popup = LegacySpellDatum.displayFromNBT(datumTag);
|
var popup = LegacySpellDatum.displayFromNBT(datumTag);
|
||||||
sender.displayClientMessage(
|
sender.displayClientMessage(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.recipe;
|
package at.petrak.hexcasting.common.recipe;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
import at.petrak.hexcasting.common.items.ItemFocus;
|
import at.petrak.hexcasting.common.items.ItemFocus;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
|
@ -23,7 +23,7 @@ public class SealFocusRecipe extends ShapelessRecipe {
|
||||||
private static ItemStack getSealedStack() {
|
private static ItemStack getSealedStack() {
|
||||||
ItemStack output = new ItemStack(HexItems.FOCUS);
|
ItemStack output = new ItemStack(HexItems.FOCUS);
|
||||||
NBTHelper.putBoolean(output, ItemFocus.TAG_SEALED, true);
|
NBTHelper.putBoolean(output, ItemFocus.TAG_SEALED, true);
|
||||||
NBTHelper.putString(output, DataHolderItem.TAG_OVERRIDE_VISUALLY, "any");
|
NBTHelper.putString(output, IotaHolderItem.TAG_OVERRIDE_VISUALLY, "any");
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.common.recipe;
|
package at.petrak.hexcasting.common.recipe;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
import at.petrak.hexcasting.common.items.ItemSpellbook;
|
import at.petrak.hexcasting.common.items.ItemSpellbook;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
|
@ -23,7 +23,7 @@ public class SealSpellbookRecipe extends ShapelessRecipe {
|
||||||
private static ItemStack getSealedStack() {
|
private static ItemStack getSealedStack() {
|
||||||
ItemStack output = new ItemStack(HexItems.SPELLBOOK);
|
ItemStack output = new ItemStack(HexItems.SPELLBOOK);
|
||||||
ItemSpellbook.SetSealed(output, true);
|
ItemSpellbook.SetSealed(output, true);
|
||||||
NBTHelper.putString(output, DataHolderItem.TAG_OVERRIDE_VISUALLY, "any");
|
NBTHelper.putString(output, IotaHolderItem.TAG_OVERRIDE_VISUALLY, "any");
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package at.petrak.hexcasting.xplat;
|
package at.petrak.hexcasting.xplat;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.HexAPI;
|
import at.petrak.hexcasting.api.HexAPI;
|
||||||
import at.petrak.hexcasting.api.addldata.DataHolder;
|
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.HexHolder;
|
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
|
||||||
import at.petrak.hexcasting.api.misc.FrozenColorizer;
|
import at.petrak.hexcasting.api.misc.FrozenColorizer;
|
||||||
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;
|
||||||
|
@ -96,13 +96,13 @@ public interface IXplatAbstractions {
|
||||||
void clearCastingData(ServerPlayer player);
|
void clearCastingData(ServerPlayer player);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ManaHolder findManaHolder(ItemStack stack);
|
ADMediaHolder findManaHolder(ItemStack stack);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
DataHolder findDataHolder(ItemStack stack);
|
ADIotaHolder findDataHolder(ItemStack stack);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
HexHolder findHexHolder(ItemStack stack);
|
ADHexHolder findHexHolder(ItemStack stack);
|
||||||
|
|
||||||
// coooollooorrrs
|
// coooollooorrrs
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@
|
||||||
"hexcasting.spelldata.onitem": "Contains: %s",
|
"hexcasting.spelldata.onitem": "Contains: %s",
|
||||||
"hexcasting.spelldata.anything": "Anything",
|
"hexcasting.spelldata.anything": "Anything",
|
||||||
"hexcasting.spelldata.unknown": "Unknown data (this is a bug)",
|
"hexcasting.spelldata.unknown": "Unknown data (this is a bug)",
|
||||||
"hexcasting.spelldata.entity.whoknows": "An Entity (this should only show up if this was stored before the 0.5.0 update, use Scribe's Reflection, Scribe's Gambit to fix)",
|
"hexcasting.spelldata.entity.whoknows": "An Unknown Entity",
|
||||||
"hexcasting.spelldata.akashic.nopos": "The owning record does not know of any iota here (this is a bug)",
|
"hexcasting.spelldata.akashic.nopos": "The owning record does not know of any iota here (this is a bug)",
|
||||||
|
|
||||||
"gui.hexcasting.spellcasting": "Hex Grid",
|
"gui.hexcasting.spellcasting": "Hex Grid",
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
package at.petrak.hexcasting.fabric.cc;
|
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.DataHolder;
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
|
||||||
import dev.onyxstudios.cca.api.v3.item.ItemComponent;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public abstract class CCDataHolder extends ItemComponent implements DataHolder {
|
|
||||||
public CCDataHolder(ItemStack stack) {
|
|
||||||
super(stack, HexCardinalComponents.DATA_HOLDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ItemBased extends CCDataHolder {
|
|
||||||
private final DataHolderItem dataHolder;
|
|
||||||
|
|
||||||
public ItemBased(ItemStack stack) {
|
|
||||||
super(stack);
|
|
||||||
if (!(stack.getItem() instanceof DataHolderItem data)) {
|
|
||||||
throw new IllegalStateException("item is not a data holder: " + stack);
|
|
||||||
}
|
|
||||||
this.dataHolder = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable CompoundTag readRawDatum() {
|
|
||||||
return this.dataHolder.readDatumTag(this.stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean writeDatum(@Nullable LegacySpellDatum<?> datum, boolean simulate) {
|
|
||||||
var canWrite = this.dataHolder.canWrite(this.stack, datum);
|
|
||||||
if (!canWrite) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!simulate) {
|
|
||||||
this.dataHolder.writeDatum(this.stack, datum);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Static extends CCDataHolder {
|
|
||||||
private final Function<ItemStack, LegacySpellDatum<?>> provider;
|
|
||||||
|
|
||||||
public Static(ItemStack stack, Function<ItemStack, LegacySpellDatum<?>> provider) {
|
|
||||||
super(stack);
|
|
||||||
this.provider = provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable CompoundTag readRawDatum() {
|
|
||||||
LegacySpellDatum<?> datum = this.provider.apply(this.stack);
|
|
||||||
return datum == null ? null : datum.serializeToNBT();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean writeDatum(@Nullable LegacySpellDatum<?> datum, boolean simulate) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,17 @@
|
||||||
package at.petrak.hexcasting.fabric.cc;
|
package at.petrak.hexcasting.fabric.cc;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
|
||||||
import at.petrak.hexcasting.api.item.ColorizerItem;
|
import at.petrak.hexcasting.api.item.ColorizerItem;
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
|
||||||
import at.petrak.hexcasting.api.item.HexHolderItem;
|
import at.petrak.hexcasting.api.item.HexHolderItem;
|
||||||
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
|
import at.petrak.hexcasting.api.item.MediaHolderItem;
|
||||||
import at.petrak.hexcasting.api.mod.HexConfig;
|
import at.petrak.hexcasting.api.mod.HexConfig;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.iota.DoubleIota;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
|
import at.petrak.hexcasting.fabric.cc.adimpl.CCColorizer;
|
||||||
|
import at.petrak.hexcasting.fabric.cc.adimpl.CCHexHolder;
|
||||||
|
import at.petrak.hexcasting.fabric.cc.adimpl.CCIotaHolder;
|
||||||
|
import at.petrak.hexcasting.fabric.cc.adimpl.CCMediaHolder;
|
||||||
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
|
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
|
||||||
import dev.onyxstudios.cca.api.v3.component.ComponentRegistry;
|
import dev.onyxstudios.cca.api.v3.component.ComponentRegistry;
|
||||||
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry;
|
import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry;
|
||||||
|
@ -37,10 +42,10 @@ public class HexCardinalComponents implements EntityComponentInitializer, ItemCo
|
||||||
|
|
||||||
public static final ComponentKey<CCColorizer> COLORIZER = ComponentRegistry.getOrCreate(modLoc("colorizer"),
|
public static final ComponentKey<CCColorizer> COLORIZER = ComponentRegistry.getOrCreate(modLoc("colorizer"),
|
||||||
CCColorizer.class);
|
CCColorizer.class);
|
||||||
public static final ComponentKey<CCDataHolder> DATA_HOLDER = ComponentRegistry.getOrCreate(modLoc("data_holder"),
|
public static final ComponentKey<CCIotaHolder> DATA_HOLDER = ComponentRegistry.getOrCreate(modLoc("data_holder"),
|
||||||
CCDataHolder.class);
|
CCIotaHolder.class);
|
||||||
public static final ComponentKey<CCManaHolder> MANA_HOLDER = ComponentRegistry.getOrCreate(modLoc("mana_holder"),
|
public static final ComponentKey<CCMediaHolder> MEDIA_HOLDER = ComponentRegistry.getOrCreate(modLoc("mana_holder"),
|
||||||
CCManaHolder.class);
|
CCMediaHolder.class);
|
||||||
public static final ComponentKey<CCHexHolder> HEX_HOLDER = ComponentRegistry.getOrCreate(modLoc("hex_holder"),
|
public static final ComponentKey<CCHexHolder> HEX_HOLDER = ComponentRegistry.getOrCreate(modLoc("hex_holder"),
|
||||||
CCHexHolder.class);
|
CCHexHolder.class);
|
||||||
|
|
||||||
|
@ -59,21 +64,21 @@ public class HexCardinalComponents implements EntityComponentInitializer, ItemCo
|
||||||
public void registerItemComponentFactories(ItemComponentFactoryRegistry registry) {
|
public void registerItemComponentFactories(ItemComponentFactoryRegistry registry) {
|
||||||
registry.register(i -> i instanceof ColorizerItem, COLORIZER, CCColorizer.ItemBased::new);
|
registry.register(i -> i instanceof ColorizerItem, COLORIZER, CCColorizer.ItemBased::new);
|
||||||
|
|
||||||
registry.register(i -> i instanceof DataHolderItem, DATA_HOLDER, CCDataHolder.ItemBased::new);
|
registry.register(i -> i instanceof IotaHolderItem, DATA_HOLDER, CCIotaHolder.ItemBased::new);
|
||||||
// oh havoc, you think you're so funny
|
// oh havoc, you think you're so funny
|
||||||
// the worst part is you're /right/
|
// the worst part is you're /right/
|
||||||
registry.register(Items.PUMPKIN_PIE, DATA_HOLDER, stack -> new CCDataHolder.Static(stack,
|
registry.register(Items.PUMPKIN_PIE, DATA_HOLDER, stack ->
|
||||||
s -> LegacySpellDatum.make(Math.PI * s.getCount())));
|
new CCIotaHolder.Static(stack, s -> new DoubleIota(Math.PI * s.getCount())));
|
||||||
|
|
||||||
registry.register(i -> i instanceof ManaHolderItem, MANA_HOLDER, CCManaHolder.ItemBased::new);
|
registry.register(i -> i instanceof MediaHolderItem, MEDIA_HOLDER, CCMediaHolder.ItemBased::new);
|
||||||
registry.register(HexItems.AMETHYST_DUST, MANA_HOLDER, s -> new CCManaHolder.Static(
|
registry.register(HexItems.AMETHYST_DUST, MEDIA_HOLDER, s -> new CCMediaHolder.Static(
|
||||||
() -> HexConfig.common().dustManaAmount(), 30, s
|
() -> HexConfig.common().dustManaAmount(), ADMediaHolder.AMETHYST_DUST_PRIORITY, s
|
||||||
));
|
));
|
||||||
registry.register(Items.AMETHYST_SHARD, MANA_HOLDER, s -> new CCManaHolder.Static(
|
registry.register(Items.AMETHYST_SHARD, MEDIA_HOLDER, s -> new CCMediaHolder.Static(
|
||||||
() -> HexConfig.common().shardManaAmount(), 20, s
|
() -> HexConfig.common().shardManaAmount(), ADMediaHolder.AMETHYST_SHARD_PRIORITY, s
|
||||||
));
|
));
|
||||||
registry.register(HexItems.CHARGED_AMETHYST, MANA_HOLDER, s -> new CCManaHolder.Static(
|
registry.register(HexItems.CHARGED_AMETHYST, MEDIA_HOLDER, s -> new CCMediaHolder.Static(
|
||||||
() -> HexConfig.common().chargedCrystalManaAmount(), 10, s
|
() -> HexConfig.common().chargedCrystalManaAmount(), ADMediaHolder.CHARGED_AMETHYST_PRIORITY, s
|
||||||
));
|
));
|
||||||
|
|
||||||
registry.register(i -> i instanceof HexHolderItem, HEX_HOLDER, CCHexHolder.ItemBased::new);
|
registry.register(i -> i instanceof HexHolderItem, HEX_HOLDER, CCHexHolder.ItemBased::new);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package at.petrak.hexcasting.fabric.cc;
|
package at.petrak.hexcasting.fabric.cc.adimpl;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.Colorizer;
|
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.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 net.minecraft.world.phys.Vec3;
|
||||||
|
@ -11,7 +12,7 @@ import java.util.UUID;
|
||||||
/**
|
/**
|
||||||
* The colorizer itself
|
* The colorizer itself
|
||||||
*/
|
*/
|
||||||
public abstract class CCColorizer extends ItemComponent implements Colorizer {
|
public abstract class CCColorizer extends ItemComponent implements ADColorizer {
|
||||||
public CCColorizer(ItemStack stack) {
|
public CCColorizer(ItemStack stack) {
|
||||||
super(stack, HexCardinalComponents.COLORIZER);
|
super(stack, HexCardinalComponents.COLORIZER);
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
package at.petrak.hexcasting.fabric.cc;
|
package at.petrak.hexcasting.fabric.cc.adimpl;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.HexHolder;
|
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||||
import at.petrak.hexcasting.api.item.HexHolderItem;
|
import at.petrak.hexcasting.api.item.HexHolderItem;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
|
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.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -10,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class CCHexHolder extends ItemComponent implements HexHolder {
|
public abstract class CCHexHolder extends ItemComponent implements ADHexHolder {
|
||||||
public CCHexHolder(ItemStack stack) {
|
public CCHexHolder(ItemStack stack) {
|
||||||
super(stack, HexCardinalComponents.HEX_HOLDER);
|
super(stack, HexCardinalComponents.HEX_HOLDER);
|
||||||
}
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package at.petrak.hexcasting.fabric.cc.adimpl;
|
||||||
|
|
||||||
|
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
|
||||||
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
|
import at.petrak.hexcasting.api.spell.iota.Iota;
|
||||||
|
import at.petrak.hexcasting.common.lib.HexIotaTypes;
|
||||||
|
import at.petrak.hexcasting.fabric.cc.HexCardinalComponents;
|
||||||
|
import dev.onyxstudios.cca.api.v3.item.ItemComponent;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public abstract class CCIotaHolder extends ItemComponent implements ADIotaHolder {
|
||||||
|
public CCIotaHolder(ItemStack stack) {
|
||||||
|
super(stack, HexCardinalComponents.DATA_HOLDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ItemBased extends CCIotaHolder {
|
||||||
|
private final IotaHolderItem iotaHolder;
|
||||||
|
|
||||||
|
public ItemBased(ItemStack stack) {
|
||||||
|
super(stack);
|
||||||
|
if (!(stack.getItem() instanceof IotaHolderItem data)) {
|
||||||
|
throw new IllegalStateException("item is not a data holder: " + stack);
|
||||||
|
}
|
||||||
|
this.iotaHolder = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable CompoundTag readIotaTag() {
|
||||||
|
return this.iotaHolder.readIotaTag(this.stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean writeIota(@Nullable Iota iota, boolean simulate) {
|
||||||
|
var canWrite = this.iotaHolder.canWrite(this.stack, iota);
|
||||||
|
if (!canWrite) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!simulate) {
|
||||||
|
this.iotaHolder.writeDatum(this.stack, iota);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Static extends CCIotaHolder {
|
||||||
|
private final Function<ItemStack, Iota> provider;
|
||||||
|
|
||||||
|
public Static(ItemStack stack, Function<ItemStack, Iota> provider) {
|
||||||
|
super(stack);
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable CompoundTag readIotaTag() {
|
||||||
|
var iota = this.provider.apply(this.stack);
|
||||||
|
return iota == null ? null : HexIotaTypes.serialize(iota);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean writeIota(@Nullable Iota datum, boolean simulate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,56 +1,57 @@
|
||||||
package at.petrak.hexcasting.fabric.cc;
|
package at.petrak.hexcasting.fabric.cc.adimpl;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
|
||||||
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
import at.petrak.hexcasting.api.item.MediaHolderItem;
|
||||||
|
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 java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public abstract class CCManaHolder extends ItemComponent implements ManaHolder {
|
public abstract class CCMediaHolder extends ItemComponent implements ADMediaHolder {
|
||||||
public CCManaHolder(ItemStack stack) {
|
public CCMediaHolder(ItemStack stack) {
|
||||||
super(stack, HexCardinalComponents.MANA_HOLDER);
|
super(stack, HexCardinalComponents.MEDIA_HOLDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ItemBased extends CCManaHolder {
|
public static class ItemBased extends CCMediaHolder {
|
||||||
private final ManaHolderItem manaHolder;
|
private final MediaHolderItem mediaHolder;
|
||||||
|
|
||||||
public ItemBased(ItemStack stack) {
|
public ItemBased(ItemStack stack) {
|
||||||
super(stack);
|
super(stack);
|
||||||
if (!(stack.getItem() instanceof ManaHolderItem mana)) {
|
if (!(stack.getItem() instanceof MediaHolderItem mana)) {
|
||||||
throw new IllegalStateException("item is not a mana holder: " + stack);
|
throw new IllegalStateException("item is not a media holder: " + stack);
|
||||||
}
|
}
|
||||||
this.manaHolder = mana;
|
this.mediaHolder = mana;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMana() {
|
public int getMedia() {
|
||||||
return this.manaHolder.getMana(this.stack);
|
return this.mediaHolder.getMedia(this.stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxMana() {
|
public int getMaxMedia() {
|
||||||
return this.manaHolder.getMaxMana(this.stack);
|
return this.mediaHolder.getMaxMedia(this.stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMana(int mana) {
|
public void setMedia(int media) {
|
||||||
this.manaHolder.setMana(this.stack, mana);
|
this.mediaHolder.setMedia(this.stack, media);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canRecharge() {
|
public boolean canRecharge() {
|
||||||
return this.manaHolder.canRecharge(this.stack);
|
return this.mediaHolder.canRecharge(this.stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canProvide() {
|
public boolean canProvide() {
|
||||||
return this.manaHolder.manaProvider(this.stack);
|
return this.mediaHolder.canProvideMedia(this.stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getConsumptionPriority() {
|
public int getConsumptionPriority() {
|
||||||
return 40;
|
return ADMediaHolder.BATTERY_PRIORITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,12 +60,12 @@ public abstract class CCManaHolder extends ItemComponent implements ManaHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int withdrawMana(int cost, boolean simulate) {
|
public int withdrawMedia(int cost, boolean simulate) {
|
||||||
return this.manaHolder.withdrawMana(this.stack, cost, simulate);
|
return this.mediaHolder.withdrawMana(this.stack, cost, simulate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Static extends CCManaHolder {
|
public static class Static extends CCMediaHolder {
|
||||||
private final Supplier<Integer> baseWorth;
|
private final Supplier<Integer> baseWorth;
|
||||||
private final int consumptionPriority;
|
private final int consumptionPriority;
|
||||||
|
|
||||||
|
@ -75,17 +76,17 @@ public abstract class CCManaHolder extends ItemComponent implements ManaHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMana() {
|
public int getMedia() {
|
||||||
return baseWorth.get() * stack.getCount();
|
return baseWorth.get() * stack.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxMana() {
|
public int getMaxMedia() {
|
||||||
return getMana();
|
return getMedia();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMana(int mana) {
|
public void setMedia(int media) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ public abstract class CCManaHolder extends ItemComponent implements ManaHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int withdrawMana(int cost, boolean simulate) {
|
public int withdrawMedia(int cost, boolean simulate) {
|
||||||
int worth = baseWorth.get();
|
int worth = baseWorth.get();
|
||||||
if (cost < 0) {
|
if (cost < 0) {
|
||||||
cost = worth * stack.getCount();
|
cost = worth * stack.getCount();
|
|
@ -0,0 +1,8 @@
|
||||||
|
/**
|
||||||
|
* Some Cardinal Components in the mod are substitutes for Forge's ability to store arbitrary data on an entity;
|
||||||
|
* some are implementations of the Additional Data abstraction.
|
||||||
|
* <p>
|
||||||
|
* In the root of this folder are the substitutes for entitydata;
|
||||||
|
* in the {@link at.petrak.hexcasting.fabric.cc.adimpl adimpl} folder are the implementations of additional datas.
|
||||||
|
*/
|
||||||
|
package at.petrak.hexcasting.fabric.cc;
|
|
@ -1,6 +1,6 @@
|
||||||
package at.petrak.hexcasting.fabric.recipe;
|
package at.petrak.hexcasting.fabric.recipe;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
@ -30,7 +30,7 @@ public class FabricUnsealedIngredient extends BaseCustomIngredient {
|
||||||
.filter((it) -> it != DatumType.EMPTY && it != DatumType.OTHER)
|
.filter((it) -> it != DatumType.EMPTY && it != DatumType.OTHER)
|
||||||
.map((type) -> {
|
.map((type) -> {
|
||||||
ItemStack newStack = stack.copy();
|
ItemStack newStack = stack.copy();
|
||||||
NBTHelper.putString(newStack, DataHolderItem.TAG_OVERRIDE_VISUALLY, SpellDatum.tagForType(type));
|
NBTHelper.putString(newStack, IotaHolderItem.TAG_OVERRIDE_VISUALLY, SpellDatum.tagForType(type));
|
||||||
return new Ingredient.ItemValue(newStack);
|
return new Ingredient.ItemValue(newStack);
|
||||||
}));
|
}));
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package at.petrak.hexcasting.fabric.xplat;
|
package at.petrak.hexcasting.fabric.xplat;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.HexAPI;
|
import at.petrak.hexcasting.api.HexAPI;
|
||||||
import at.petrak.hexcasting.api.addldata.DataHolder;
|
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.HexHolder;
|
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
|
||||||
import at.petrak.hexcasting.api.misc.FrozenColorizer;
|
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.HexItemTags;
|
import at.petrak.hexcasting.api.mod.HexItemTags;
|
||||||
|
@ -213,21 +213,21 @@ public class FabricXplatImpl implements IXplatAbstractions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
ManaHolder findManaHolder(ItemStack stack) {
|
ADMediaHolder findManaHolder(ItemStack stack) {
|
||||||
var cc = HexCardinalComponents.MANA_HOLDER.maybeGet(stack);
|
var cc = HexCardinalComponents.MEDIA_HOLDER.maybeGet(stack);
|
||||||
return cc.orElse(null);
|
return cc.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
DataHolder findDataHolder(ItemStack stack) {
|
ADIotaHolder findDataHolder(ItemStack stack) {
|
||||||
var cc = HexCardinalComponents.DATA_HOLDER.maybeGet(stack);
|
var cc = HexCardinalComponents.DATA_HOLDER.maybeGet(stack);
|
||||||
return cc.orElse(null);
|
return cc.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
HexHolder findHexHolder(ItemStack stack) {
|
ADHexHolder findHexHolder(ItemStack stack) {
|
||||||
var cc = HexCardinalComponents.HEX_HOLDER.maybeGet(stack);
|
var cc = HexCardinalComponents.HEX_HOLDER.maybeGet(stack);
|
||||||
return cc.orElse(null);
|
return cc.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
package at.petrak.hexcasting.forge.cap;
|
package at.petrak.hexcasting.forge.cap;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.Colorizer;
|
import at.petrak.hexcasting.api.addldata.ADColorizer;
|
||||||
import at.petrak.hexcasting.api.addldata.DataHolder;
|
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.HexHolder;
|
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
|
||||||
import at.petrak.hexcasting.api.block.circle.BlockEntityAbstractImpetus;
|
import at.petrak.hexcasting.api.block.circle.BlockEntityAbstractImpetus;
|
||||||
import at.petrak.hexcasting.api.item.ColorizerItem;
|
import at.petrak.hexcasting.api.item.ColorizerItem;
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
|
||||||
import at.petrak.hexcasting.api.item.HexHolderItem;
|
import at.petrak.hexcasting.api.item.HexHolderItem;
|
||||||
import at.petrak.hexcasting.api.item.ManaHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
|
import at.petrak.hexcasting.api.item.MediaHolderItem;
|
||||||
import at.petrak.hexcasting.api.mod.HexConfig;
|
import at.petrak.hexcasting.api.mod.HexConfig;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.iota.DoubleIota;
|
||||||
|
import at.petrak.hexcasting.api.spell.iota.Iota;
|
||||||
|
import at.petrak.hexcasting.common.lib.HexIotaTypes;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
@ -36,69 +38,100 @@ import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ForgeCapabilityHandler {
|
import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
private static final ResourceLocation DATA_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "data_holder");
|
|
||||||
private static final ResourceLocation DATA_ITEM_CAPABILITY = new ResourceLocation("hexcasting", "data_item");
|
|
||||||
private static final ResourceLocation MANA_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "mana_holder");
|
|
||||||
private static final ResourceLocation MANA_ITEM_CAPABILITY = new ResourceLocation("hexcasting", "mana_item");
|
|
||||||
private static final ResourceLocation SPELL_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "spell_item");
|
|
||||||
private static final ResourceLocation COLORIZER_CAPABILITY = new ResourceLocation("hexcasting", "colorizer");
|
|
||||||
|
|
||||||
private static final ResourceLocation IMPETUS_HANDLER = new ResourceLocation("hexcasting", "impetus_items");
|
public class ForgeCapabilityHandler {
|
||||||
|
/**
|
||||||
|
* Items that store an iota to their tag.
|
||||||
|
*/
|
||||||
|
public static final ResourceLocation IOTA_STORAGE_CAP = modLoc("data_holder");
|
||||||
|
/**
|
||||||
|
* Items that intrinsically store an iota.
|
||||||
|
*/
|
||||||
|
public static final ResourceLocation IOTA_STATIC_CAP = modLoc("data_item");
|
||||||
|
/**
|
||||||
|
* Items that store a variable amount of media to their tag.
|
||||||
|
*/
|
||||||
|
public static final ResourceLocation MEDIA_STORAGE_CAP = modLoc("mana_holder");
|
||||||
|
/**
|
||||||
|
* Items that statically provide media.
|
||||||
|
*/
|
||||||
|
public static final ResourceLocation MEDIA_STATIC_CAP = modLoc("mana_item");
|
||||||
|
/**
|
||||||
|
* Items that store a packaged Hex.
|
||||||
|
*/
|
||||||
|
public static final ResourceLocation HEX_HOLDER_CAP = modLoc("spell_item");
|
||||||
|
/**
|
||||||
|
* Items that work as pigments.
|
||||||
|
*/
|
||||||
|
public static final ResourceLocation PIGMENT_CAP = modLoc("colorizer");
|
||||||
|
|
||||||
|
private static final ResourceLocation IMPETUS_HANDLER = modLoc("impetus_items");
|
||||||
|
|
||||||
public static void registerCaps(RegisterCapabilitiesEvent evt) {
|
public static void registerCaps(RegisterCapabilitiesEvent evt) {
|
||||||
evt.register(ManaHolder.class);
|
evt.register(ADMediaHolder.class);
|
||||||
evt.register(DataHolder.class);
|
evt.register(ADIotaHolder.class);
|
||||||
evt.register(HexHolder.class);
|
evt.register(ADHexHolder.class);
|
||||||
evt.register(Colorizer.class);
|
evt.register(ADColorizer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void attachItemCaps(AttachCapabilitiesEvent<ItemStack> evt) {
|
public static void attachItemCaps(AttachCapabilitiesEvent<ItemStack> evt) {
|
||||||
ItemStack stack = evt.getObject();
|
ItemStack stack = evt.getObject();
|
||||||
if (stack.getItem() instanceof ManaHolderItem holder)
|
|
||||||
evt.addCapability(MANA_HOLDER_CAPABILITY, provide(stack, HexCapabilities.MANA,
|
|
||||||
() -> new ItemBasedManaHolder(holder, stack)));
|
|
||||||
else if (stack.is(HexItems.AMETHYST_DUST))
|
|
||||||
evt.addCapability(MANA_ITEM_CAPABILITY, provide(stack, HexCapabilities.MANA,
|
|
||||||
() -> new StaticManaHolder(HexConfig.common()::dustManaAmount, 3, stack)));
|
|
||||||
else if (stack.is(Items.AMETHYST_SHARD))
|
|
||||||
evt.addCapability(MANA_ITEM_CAPABILITY, provide(stack, HexCapabilities.MANA,
|
|
||||||
() -> new StaticManaHolder(HexConfig.common()::shardManaAmount, 2, stack)));
|
|
||||||
else if (stack.is(HexItems.CHARGED_AMETHYST))
|
|
||||||
evt.addCapability(MANA_ITEM_CAPABILITY, provide(stack, HexCapabilities.MANA,
|
|
||||||
() -> new StaticManaHolder(HexConfig.common()::chargedCrystalManaAmount, 1, stack)));
|
|
||||||
|
|
||||||
if (stack.getItem() instanceof DataHolderItem holder)
|
if (stack.getItem() instanceof MediaHolderItem holder) {
|
||||||
evt.addCapability(DATA_HOLDER_CAPABILITY, provide(stack, HexCapabilities.DATUM,
|
evt.addCapability(MEDIA_STORAGE_CAP,
|
||||||
() -> new ItemBasedDataHolder(holder, stack)));
|
provide(stack, HexCapabilities.MANA, () -> new ItemBasedManaHolder(holder, stack)));
|
||||||
else if (stack.is(Items.PUMPKIN_PIE)) // haha yes
|
} else if (stack.is(HexItems.AMETHYST_DUST)) {
|
||||||
evt.addCapability(DATA_ITEM_CAPABILITY, provide(stack, HexCapabilities.DATUM,
|
evt.addCapability(MEDIA_STATIC_CAP, provide(stack, HexCapabilities.MANA, () ->
|
||||||
() -> new StaticDatumHolder((s) -> LegacySpellDatum.make(Math.PI * s.getCount()), stack)));
|
new StaticManaHolder(HexConfig.common()::dustManaAmount, ADMediaHolder.AMETHYST_DUST_PRIORITY, stack)));
|
||||||
|
} else if (stack.is(Items.AMETHYST_SHARD)) {
|
||||||
|
evt.addCapability(MEDIA_STATIC_CAP, provide(stack, HexCapabilities.MANA, () -> new StaticManaHolder(
|
||||||
|
HexConfig.common()::shardManaAmount, ADMediaHolder.AMETHYST_SHARD_PRIORITY, stack)));
|
||||||
|
} else if (stack.is(HexItems.CHARGED_AMETHYST)) {
|
||||||
|
evt.addCapability(MEDIA_STATIC_CAP,
|
||||||
|
provide(stack, HexCapabilities.MANA, () -> new StaticManaHolder(
|
||||||
|
HexConfig.common()::chargedCrystalManaAmount, ADMediaHolder.CHARGED_AMETHYST_PRIORITY, stack)));
|
||||||
|
}
|
||||||
|
|
||||||
if (stack.getItem() instanceof HexHolderItem holder)
|
if (stack.getItem() instanceof IotaHolderItem holder) {
|
||||||
evt.addCapability(SPELL_HOLDER_CAPABILITY, provide(stack, HexCapabilities.STORED_HEX,
|
evt.addCapability(IOTA_STORAGE_CAP,
|
||||||
() -> new ItemBasedHexHolder(holder, stack)));
|
provide(stack, HexCapabilities.DATUM, () -> new ItemBasedDataHolder(holder, stack)));
|
||||||
|
} else if (stack.is(Items.PUMPKIN_PIE)) {
|
||||||
|
// haha yes
|
||||||
|
evt.addCapability(IOTA_STATIC_CAP, provide(stack, HexCapabilities.DATUM, () ->
|
||||||
|
new StaticDatumHolder((s) -> new DoubleIota(Math.PI * s.getCount()), stack)));
|
||||||
|
}
|
||||||
|
|
||||||
if (stack.getItem() instanceof ColorizerItem colorizer)
|
if (stack.getItem() instanceof HexHolderItem holder) {
|
||||||
evt.addCapability(COLORIZER_CAPABILITY, provide(stack, HexCapabilities.COLOR,
|
evt.addCapability(HEX_HOLDER_CAP,
|
||||||
() -> new ItemBasedColorizer(colorizer, stack)));
|
provide(stack, HexCapabilities.STORED_HEX, () -> new ItemBasedHexHolder(holder, stack)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.getItem() instanceof ColorizerItem colorizer) {
|
||||||
|
evt.addCapability(PIGMENT_CAP,
|
||||||
|
provide(stack, HexCapabilities.COLOR, () -> new ItemBasedColorizer(colorizer, stack)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void attachBlockEntityCaps(AttachCapabilitiesEvent<BlockEntity> evt) {
|
public static void attachBlockEntityCaps(AttachCapabilitiesEvent<BlockEntity> evt) {
|
||||||
if (evt.getObject() instanceof BlockEntityAbstractImpetus impetus)
|
if (evt.getObject() instanceof BlockEntityAbstractImpetus impetus) {
|
||||||
evt.addCapability(IMPETUS_HANDLER, provide(impetus, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
|
evt.addCapability(IMPETUS_HANDLER, provide(impetus, CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
|
||||||
() -> new ForgeImpetusCapability(impetus)));
|
() -> new ForgeImpetusCapability(impetus)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <CAP> SimpleProvider<CAP> provide(BlockEntity be, Capability<CAP> capability, NonNullSupplier<CAP> supplier) {
|
private static <CAP> SimpleProvider<CAP> provide(BlockEntity be, Capability<CAP> capability,
|
||||||
|
NonNullSupplier<CAP> supplier) {
|
||||||
return provide(be::isRemoved, capability, supplier);
|
return provide(be::isRemoved, capability, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <CAP> SimpleProvider<CAP> provide(ItemStack stack, Capability<CAP> capability, NonNullSupplier<CAP> supplier) {
|
private static <CAP> SimpleProvider<CAP> provide(ItemStack stack, Capability<CAP> capability,
|
||||||
|
NonNullSupplier<CAP> supplier) {
|
||||||
return provide(stack::isEmpty, capability, supplier);
|
return provide(stack::isEmpty, capability, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <CAP> SimpleProvider<CAP> provide(BooleanSupplier invalidated, Capability<CAP> capability, NonNullSupplier<CAP> supplier) {
|
private static <CAP> SimpleProvider<CAP> provide(BooleanSupplier invalidated, Capability<CAP> capability,
|
||||||
|
NonNullSupplier<CAP> supplier) {
|
||||||
return new SimpleProvider<>(invalidated, capability, LazyOptional.of(supplier));
|
return new SimpleProvider<>(invalidated, capability, LazyOptional.of(supplier));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,8 +142,9 @@ public class ForgeCapabilityHandler {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
|
||||||
if (invalidated.getAsBoolean())
|
if (invalidated.getAsBoolean()) {
|
||||||
return LazyOptional.empty();
|
return LazyOptional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
return cap == capability ? instance.cast() : LazyOptional.empty();
|
return cap == capability ? instance.cast() : LazyOptional.empty();
|
||||||
}
|
}
|
||||||
|
@ -118,19 +152,19 @@ public class ForgeCapabilityHandler {
|
||||||
|
|
||||||
private record StaticManaHolder(Supplier<Integer> baseWorth,
|
private record StaticManaHolder(Supplier<Integer> baseWorth,
|
||||||
int consumptionPriority,
|
int consumptionPriority,
|
||||||
ItemStack stack) implements ManaHolder {
|
ItemStack stack) implements ADMediaHolder {
|
||||||
@Override
|
@Override
|
||||||
public int getMana() {
|
public int getMedia() {
|
||||||
return baseWorth.get() * stack.getCount();
|
return baseWorth.get() * stack.getCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxMana() {
|
public int getMaxMedia() {
|
||||||
return getMana();
|
return getMedia();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMana(int mana) {
|
public void setMedia(int media) {
|
||||||
// NO-OP
|
// NO-OP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +189,7 @@ public class ForgeCapabilityHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int withdrawMana(int cost, boolean simulate) {
|
public int withdrawMedia(int cost, boolean simulate) {
|
||||||
int worth = baseWorth.get();
|
int worth = baseWorth.get();
|
||||||
if (cost < 0) {
|
if (cost < 0) {
|
||||||
cost = worth * stack.getCount();
|
cost = worth * stack.getCount();
|
||||||
|
@ -169,22 +203,22 @@ public class ForgeCapabilityHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ItemBasedManaHolder(ManaHolderItem holder,
|
private record ItemBasedManaHolder(MediaHolderItem holder,
|
||||||
ItemStack stack) implements ManaHolder {
|
ItemStack stack) implements ADMediaHolder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMana() {
|
public int getMedia() {
|
||||||
return holder.getMana(stack);
|
return holder.getMedia(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxMana() {
|
public int getMaxMedia() {
|
||||||
return holder.getMaxMana(stack);
|
return holder.getMaxMedia(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMana(int mana) {
|
public void setMedia(int media) {
|
||||||
holder.setMana(stack, mana);
|
holder.setMedia(stack, media);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -194,7 +228,7 @@ public class ForgeCapabilityHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canProvide() {
|
public boolean canProvide() {
|
||||||
return holder.manaProvider(stack);
|
return holder.canProvideMedia(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -208,68 +242,68 @@ public class ForgeCapabilityHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int withdrawMana(int cost, boolean simulate) {
|
public int withdrawMedia(int cost, boolean simulate) {
|
||||||
return holder.withdrawMana(stack, cost, simulate);
|
return holder.withdrawMana(stack, cost, simulate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record StaticDatumHolder(Function<ItemStack, LegacySpellDatum<?>> provider,
|
private record StaticDatumHolder(Function<ItemStack, Iota> provider,
|
||||||
ItemStack stack) implements DataHolder {
|
ItemStack stack) implements ADIotaHolder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
CompoundTag readRawDatum() {
|
CompoundTag readIotaTag() {
|
||||||
LegacySpellDatum<?> datum = provider.apply(stack);
|
var iota = provider.apply(stack);
|
||||||
return datum == null ? null : datum.serializeToNBT();
|
return iota == null ? null : HexIotaTypes.serialize(iota);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
LegacySpellDatum<?> readDatum(ServerLevel world) {
|
Iota readIota(ServerLevel world) {
|
||||||
return provider.apply(stack);
|
return provider.apply(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean writeDatum(@Nullable LegacySpellDatum<?> datum, boolean simulate) {
|
public boolean writeIota(@Nullable Iota iota, boolean simulate) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ItemBasedDataHolder(DataHolderItem holder,
|
private record ItemBasedDataHolder(IotaHolderItem holder,
|
||||||
ItemStack stack) implements DataHolder {
|
ItemStack stack) implements ADIotaHolder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
CompoundTag readRawDatum() {
|
CompoundTag readIotaTag() {
|
||||||
return holder.readDatumTag(stack);
|
return holder.readIotaTag(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
LegacySpellDatum<?> readDatum(ServerLevel world) {
|
Iota readIota(ServerLevel world) {
|
||||||
return holder.readDatum(stack, world);
|
return holder.readIota(stack, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
LegacySpellDatum<?> emptyDatum() {
|
Iota emptyIota() {
|
||||||
return holder.emptyDatum(stack);
|
return holder.emptyIota(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean writeDatum(@Nullable LegacySpellDatum<?> datum, boolean simulate) {
|
public boolean writeIota(@Nullable Iota iota, boolean simulate) {
|
||||||
if (!holder.canWrite(stack, datum)) {
|
if (!holder.canWrite(stack, iota)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
holder.writeDatum(stack, datum);
|
holder.writeDatum(stack, iota);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ItemBasedHexHolder(HexHolderItem holder,
|
private record ItemBasedHexHolder(HexHolderItem holder,
|
||||||
ItemStack stack) implements HexHolder {
|
ItemStack stack) implements ADHexHolder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canDrawManaFromInventory() {
|
public boolean canDrawManaFromInventory() {
|
||||||
|
@ -282,12 +316,12 @@ public class ForgeCapabilityHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<LegacySpellDatum<?>> getHex(ServerLevel level) {
|
public @Nullable List<Iota> getHex(ServerLevel level) {
|
||||||
return holder.getHex(stack, level);
|
return holder.getHex(stack, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeHex(List<LegacySpellDatum<?>> patterns, int mana) {
|
public void writeHex(List<Iota> patterns, int mana) {
|
||||||
holder.writeHex(stack, patterns, mana);
|
holder.writeHex(stack, patterns, mana);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,7 +332,7 @@ public class ForgeCapabilityHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ItemBasedColorizer(ColorizerItem holder,
|
private record ItemBasedColorizer(ColorizerItem holder,
|
||||||
ItemStack stack) implements Colorizer {
|
ItemStack stack) implements ADColorizer {
|
||||||
@Override
|
@Override
|
||||||
public int color(UUID owner, float time, Vec3 position) {
|
public int color(UUID owner, float time, Vec3 position) {
|
||||||
return holder.color(stack, owner, time, position);
|
return holder.color(stack, owner, time, position);
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
package at.petrak.hexcasting.forge.cap;
|
package at.petrak.hexcasting.forge.cap;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.Colorizer;
|
import at.petrak.hexcasting.api.addldata.ADColorizer;
|
||||||
import at.petrak.hexcasting.api.addldata.DataHolder;
|
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.HexHolder;
|
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||||
import net.minecraftforge.common.capabilities.CapabilityToken;
|
import net.minecraftforge.common.capabilities.CapabilityToken;
|
||||||
|
|
||||||
public final class HexCapabilities {
|
public final class HexCapabilities {
|
||||||
|
|
||||||
public static final Capability<ManaHolder> MANA = CapabilityManager.get(new CapabilityToken<>() {
|
public static final Capability<ADMediaHolder> MANA = CapabilityManager.get(new CapabilityToken<>() {
|
||||||
});
|
});
|
||||||
public static final Capability<DataHolder> DATUM = CapabilityManager.get(new CapabilityToken<>() {
|
public static final Capability<ADIotaHolder> DATUM = CapabilityManager.get(new CapabilityToken<>() {
|
||||||
});
|
});
|
||||||
public static final Capability<HexHolder> STORED_HEX = CapabilityManager.get(new CapabilityToken<>() {
|
public static final Capability<ADHexHolder> STORED_HEX = CapabilityManager.get(new CapabilityToken<>() {
|
||||||
});
|
});
|
||||||
public static final Capability<Colorizer> COLOR = CapabilityManager.get(new CapabilityToken<>() {
|
public static final Capability<ADColorizer> COLOR = CapabilityManager.get(new CapabilityToken<>() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import at.petrak.hexcasting.common.items.ItemScroll;
|
||||||
import at.petrak.hexcasting.common.items.ItemSlate;
|
import at.petrak.hexcasting.common.items.ItemSlate;
|
||||||
import at.petrak.hexcasting.common.items.ItemWand;
|
import at.petrak.hexcasting.common.items.ItemWand;
|
||||||
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
|
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
|
||||||
import at.petrak.hexcasting.common.items.magic.ItemManaBattery;
|
import at.petrak.hexcasting.common.items.magic.ItemMediaBattery;
|
||||||
import at.petrak.hexcasting.common.items.magic.ItemPackagedHex;
|
import at.petrak.hexcasting.common.items.magic.ItemPackagedHex;
|
||||||
import at.petrak.hexcasting.common.lib.HexBlocks;
|
import at.petrak.hexcasting.common.lib.HexBlocks;
|
||||||
import at.petrak.hexcasting.common.lib.HexItems;
|
import at.petrak.hexcasting.common.lib.HexItems;
|
||||||
|
@ -122,8 +122,8 @@ public class HexItemModels extends PaucalItemModelProvider {
|
||||||
|
|
||||||
float fillProp = (float) fill / maxFill;
|
float fillProp = (float) fill / maxFill;
|
||||||
getBuilder(HexItems.BATTERY.getRegistryName().getPath()).override()
|
getBuilder(HexItems.BATTERY.getRegistryName().getPath()).override()
|
||||||
.predicate(ItemManaBattery.MANA_PREDICATE, fillProp)
|
.predicate(ItemMediaBattery.MANA_PREDICATE, fillProp)
|
||||||
.predicate(ItemManaBattery.MAX_MANA_PREDICATE, size)
|
.predicate(ItemMediaBattery.MAX_MANA_PREDICATE, size)
|
||||||
.model(new ModelFile.UncheckedModelFile(modLoc("item/" + name)))
|
.model(new ModelFile.UncheckedModelFile(modLoc("item/" + name)))
|
||||||
.end();
|
.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package at.petrak.hexcasting.forge.recipe;
|
package at.petrak.hexcasting.forge.recipe;
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.addldata.DataHolder;
|
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
|
||||||
import at.petrak.hexcasting.api.item.DataHolderItem;
|
import at.petrak.hexcasting.api.item.IotaHolderItem;
|
||||||
import at.petrak.hexcasting.api.spell.DatumType;
|
import at.petrak.hexcasting.api.spell.DatumType;
|
||||||
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
import at.petrak.hexcasting.api.spell.LegacySpellDatum;
|
||||||
import at.petrak.hexcasting.api.spell.Widget;
|
import at.petrak.hexcasting.api.spell.Widget;
|
||||||
|
@ -30,7 +30,7 @@ public class ForgeUnsealedIngredient extends AbstractIngredient {
|
||||||
.filter((it) -> it != DatumType.EMPTY && it != DatumType.OTHER)
|
.filter((it) -> it != DatumType.EMPTY && it != DatumType.OTHER)
|
||||||
.map((type) -> {
|
.map((type) -> {
|
||||||
ItemStack newStack = stack.copy();
|
ItemStack newStack = stack.copy();
|
||||||
NBTHelper.putString(newStack, DataHolderItem.TAG_OVERRIDE_VISUALLY, LegacySpellDatum.tagForType(type));
|
NBTHelper.putString(newStack, IotaHolderItem.TAG_OVERRIDE_VISUALLY, LegacySpellDatum.tagForType(type));
|
||||||
return new Ingredient.ItemValue(newStack);
|
return new Ingredient.ItemValue(newStack);
|
||||||
}));
|
}));
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
|
@ -45,13 +45,13 @@ public class ForgeUnsealedIngredient extends AbstractIngredient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(@Nullable ItemStack input) {
|
public boolean test(@Nullable ItemStack input) {
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.stack.getItem() == input.getItem() && this.stack.getDamageValue() == input.getDamageValue()) {
|
if (this.stack.getItem() == input.getItem() && this.stack.getDamageValue() == input.getDamageValue()) {
|
||||||
DataHolder holder = IXplatAbstractions.INSTANCE.findDataHolder(this.stack);
|
ADIotaHolder holder = IXplatAbstractions.INSTANCE.findDataHolder(this.stack);
|
||||||
if (holder != null) {
|
if (holder != null) {
|
||||||
return holder.readRawDatum() != null && holder.writeDatum(LegacySpellDatum.make(Widget.NULL), true);
|
return holder.readIotaTag() != null && holder.writeIota(LegacySpellDatum.make(Widget.NULL), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
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.Colorizer;
|
import at.petrak.hexcasting.api.addldata.ADColorizer;
|
||||||
import at.petrak.hexcasting.api.addldata.DataHolder;
|
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.HexHolder;
|
import at.petrak.hexcasting.api.addldata.ADIotaHolder;
|
||||||
import at.petrak.hexcasting.api.addldata.ManaHolder;
|
import at.petrak.hexcasting.api.addldata.ADMediaHolder;
|
||||||
import at.petrak.hexcasting.api.misc.FrozenColorizer;
|
import at.petrak.hexcasting.api.misc.FrozenColorizer;
|
||||||
import at.petrak.hexcasting.api.mod.HexItemTags;
|
import at.petrak.hexcasting.api.mod.HexItemTags;
|
||||||
import at.petrak.hexcasting.api.player.FlightAbility;
|
import at.petrak.hexcasting.api.player.FlightAbility;
|
||||||
|
@ -253,21 +253,21 @@ public class ForgeXplatImpl implements IXplatAbstractions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
ManaHolder findManaHolder(ItemStack stack) {
|
ADMediaHolder findManaHolder(ItemStack stack) {
|
||||||
var maybeCap = stack.getCapability(HexCapabilities.MANA).resolve();
|
var maybeCap = stack.getCapability(HexCapabilities.MANA).resolve();
|
||||||
return maybeCap.orElse(null);
|
return maybeCap.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
DataHolder findDataHolder(ItemStack stack) {
|
ADIotaHolder findDataHolder(ItemStack stack) {
|
||||||
var maybeCap = stack.getCapability(HexCapabilities.DATUM).resolve();
|
var maybeCap = stack.getCapability(HexCapabilities.DATUM).resolve();
|
||||||
return maybeCap.orElse(null);
|
return maybeCap.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable
|
public @Nullable
|
||||||
HexHolder findHexHolder(ItemStack stack) {
|
ADHexHolder findHexHolder(ItemStack stack) {
|
||||||
var maybeCap = stack.getCapability(HexCapabilities.STORED_HEX).resolve();
|
var maybeCap = stack.getCapability(HexCapabilities.STORED_HEX).resolve();
|
||||||
return maybeCap.orElse(null);
|
return maybeCap.orElse(null);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ public class ForgeXplatImpl implements IXplatAbstractions {
|
||||||
public int getRawColor(FrozenColorizer colorizer, float time, Vec3 position) {
|
public int getRawColor(FrozenColorizer colorizer, float time, Vec3 position) {
|
||||||
var maybeColorizer = colorizer.item().getCapability(HexCapabilities.COLOR).resolve();
|
var maybeColorizer = colorizer.item().getCapability(HexCapabilities.COLOR).resolve();
|
||||||
if (maybeColorizer.isPresent()) {
|
if (maybeColorizer.isPresent()) {
|
||||||
Colorizer col = maybeColorizer.get();
|
ADColorizer col = maybeColorizer.get();
|
||||||
return col.color(colorizer.owner(), time, position);
|
return col.color(colorizer.owner(), time, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue