Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
package at.petrak.hexcasting.api.addldata;

import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.item.HexHolderItem;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface ADHexHolder {
public record ADHexHolder(HexHolderItem holder, ItemStack stack) {
public boolean canDrawMediaFromInventory() {
return holder.canDrawMediaFromInventory(stack);
}

boolean canDrawMediaFromInventory();
public boolean hasHex() {
return holder.hasHex(stack);
}

boolean hasHex();
public @Nullable List<Iota> getHex(ServerLevel level) {
return holder.getHex(stack, level);
}

@Nullable
List<Iota> getHex(ServerLevel level);
public void writeHex(List<Iota> patterns, @Nullable FrozenPigment pigment, long media) {
holder.writeHex(stack, patterns, pigment, media);
}

void writeHex(List<Iota> patterns, @Nullable FrozenPigment pigment, long media);
public void clearHex() {
holder.clearHex(stack);
}

void clearHex();

@Nullable FrozenPigment getPigment();
public @Nullable FrozenPigment getPigment() {
return holder.getPigment(stack);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package at.petrak.hexcasting.api.addldata;

import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.item.IotaHolderItem;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.function.Function;

public interface ADIotaHolder {

@Nullable
Expand All @@ -22,4 +26,58 @@ default Iota emptyIota() {
* @return whether it is possible to write to this IotaHolder
*/
boolean writeable();

/**
* Things that read/write an arbitrary iota onto an itemstack, like foci
*/
record Dynamic(IotaHolderItem holder, ItemStack stack) implements ADIotaHolder {
@Override
public @Nullable
Iota readIota() {
return holder.readIota(stack);
}

@Override
public @Nullable
Iota emptyIota() {
return holder.emptyIota(stack);
}

@Override
public boolean writeIota(@Nullable Iota iota, boolean simulate) {
if (!holder.canWrite(stack, iota)) {
return false;
}
if (!simulate) {
holder.writeDatum(stack, iota);
}
return true;
}

@Override
public boolean writeable() {
return holder.writeable(stack);
}
}

/**
* Things that always provide a specific iota when read, like pumpkin pie
*/
record Static(Function<ItemStack, Iota> provider, ItemStack stack) implements ADIotaHolder {
@Override
public @Nullable
Iota readIota() {
return provider.apply(stack);
}

@Override
public boolean writeable() {
return false;
}

@Override
public boolean writeIota(@Nullable Iota iota, boolean simulate) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package at.petrak.hexcasting.api.addldata;

import at.petrak.hexcasting.api.item.MediaHolderItem;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;

import java.util.function.Supplier;

public interface ADMediaHolder {

/**
Expand Down Expand Up @@ -108,4 +112,107 @@ default long insertMedia(long amount, boolean simulate) {
int AMETHYST_SHARD_PRIORITY = 2000;
int AMETHYST_DUST_PRIORITY = 3000;
int BATTERY_PRIORITY = 4000;

/**
* Things that read/write media amounts from an itemstack
*/
record Dynamic(MediaHolderItem holder, ItemStack stack) implements ADMediaHolder {
public long getMedia() {
return holder.getMedia(stack);
}

@Override
public long getMaxMedia() {
return holder.getMaxMedia(stack);
}

@Override
public void setMedia(long media) {
holder.setMedia(stack, media);
}

@Override
public boolean canRecharge() {
return holder.canRecharge(stack);
}

@Override
public boolean canProvide() {
return holder.canProvideMedia(stack);
}

@Override
public int getConsumptionPriority() {
return holder.getConsumptionPriority(stack);
}

@Override
public boolean canConstructBattery() {
return false;
}

@Override
public long withdrawMedia(long cost, boolean simulate) {
return holder.withdrawMedia(stack, cost, simulate);
}

@Override
public long insertMedia(long amount, boolean simulate) {
return holder.insertMedia(stack, amount, simulate);
}
}

/**
* Things that always hold a constant amount of media, like amethyst
*/
record Static(Supplier<Long> baseWorth, int consumptionPriority, ItemStack stack) implements ADMediaHolder {
@Override
public long getMedia() {
return baseWorth.get() * stack.getCount();
}

@Override
public long getMaxMedia() {
return getMedia();
}

@Override
public void setMedia(long media) {
// NO-OP
}

@Override
public boolean canRecharge() {
return false;
}

@Override
public boolean canProvide() {
return true;
}

@Override
public int getConsumptionPriority() {
return consumptionPriority;
}

@Override
public boolean canConstructBattery() {
return true;
}

@Override
public long withdrawMedia(long cost, boolean simulate) {
long worth = baseWorth.get();
if (cost < 0) {
cost = worth * stack.getCount();
}
double itemsRequired = cost / (double) worth;
int itemsUsed = Math.min((int) Math.ceil(itemsRequired), stack.getCount());
if (!simulate) {
stack.shrink(itemsUsed);
}
return itemsUsed * worth;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package at.petrak.hexcasting.api.addldata;

import at.petrak.hexcasting.api.item.PigmentItem;
import at.petrak.hexcasting.api.pigment.ColorProvider;
import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;

import java.util.UUID;

public interface ADPigment {
ColorProvider provideColor(UUID owner);
public record ADPigment(PigmentItem holder, ItemStack stack) {
public ColorProvider provideColor(UUID owner) {
return holder.provideColor(this.stack, owner);
}

static int morphBetweenColors(int[] colors, Vec3 gradientDir, float time, Vec3 position) {
public static int morphBetweenColors(int[] colors, Vec3 gradientDir, float time, Vec3 position) {
float fIdx = Mth.positiveModulo(time + (float) gradientDir.dot(position), 1f) * colors.length;

int baseIdx = Mth.floor(fIdx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package at.petrak.hexcasting.api.addldata;

public interface ADVariantItem {
int numVariants();
int getVariant();
import at.petrak.hexcasting.api.item.VariantItem;
import net.minecraft.world.item.ItemStack;

public record ADVariantItem(VariantItem variantItem, ItemStack stack) {
public int numVariants() {
return variantItem.numVariants();
}

void setVariant(int variant);
public int getVariant() {
return variantItem.getVariant(stack);
}

public void setVariant(int variant) {
variantItem.setVariant(stack, variant);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
/**
* 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.
* On both the NeoForge and Fabric sides, the registry will be scanned for all items which implement this interface,
* and the appropriate ItemCapability/ItemApiLookup will be attached.
*/
@ApiStatus.OverrideOnly
public interface HexHolderItem extends MediaHolderItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
/**
* 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.
* On both the NeoForge and Fabric sides, the registry will be scanned for all items which implement this interface,
* and the appropriate ItemCapability/ItemApiLookup will be attached.
*/
public interface IotaHolderItem {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/**
* 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.
* On both the NeoForge and Fabric sides, the registry will be scanned for all items which implement this interface,
* and the appropriate ItemCapability/ItemApiLookup will be attached.
*/
@ApiStatus.OverrideOnly
public interface MediaHolderItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/**
* 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.
* On both the NeoForge and Fabric sides, the registry will be scanned for all items which implement this interface,
* and the appropriate ItemCapability/ItemApiLookup will be attached.
*/
@ApiStatus.OverrideOnly
public interface PigmentItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
/**
* Items that have multiple different otherwise identical visual variants 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.
* On both the NeoForge and Fabric sides, the registry will be scanned for all items which implement this interface,
* and the appropriate ItemCapability/ItemApiLookup will be attached.
*/
public interface VariantItem {

Expand Down
Loading
Loading