swapped over to using longs for media amounts everywhere. Added CircleMishapEnv. Setup CircleCastEnv more.

This commit is contained in:
Talia-12 2023-04-01 22:59:59 +10:00
parent 72efd81285
commit 7c712adac6
24 changed files with 212 additions and 104 deletions

View file

@ -15,7 +15,7 @@ public interface ADHexHolder {
@Nullable
List<Iota> getHex(ServerLevel level);
void writeHex(List<Iota> patterns, int media);
void writeHex(List<Iota> patterns, long media);
void clearHex();
}

View file

@ -7,28 +7,28 @@ public interface ADMediaHolder {
/**
* Use {@code withdrawMedia(-1, true)}
*
* @see ADMediaHolder#withdrawMedia(int, boolean)
* @see ADMediaHolder#withdrawMedia(long, boolean)
*/
@ApiStatus.OverrideOnly
int getMedia();
long getMedia();
/**
* Use {@code withdrawMedia(-1, true) + insertMedia(-1, true)} where possible
*
* @see ADMediaHolder#insertMedia(int, boolean)
* @see ADMediaHolder#withdrawMedia(int, boolean)
* @see ADMediaHolder#insertMedia(long, boolean)
* @see ADMediaHolder#withdrawMedia(long, boolean)
*/
@ApiStatus.OverrideOnly
int getMaxMedia();
long getMaxMedia();
/**
* Use {@code insertMedia(media - withdrawMedia(-1, true), false)} where possible
*
* @see ADMediaHolder#insertMedia(int, boolean)
* @see ADMediaHolder#withdrawMedia(int, boolean)
* @see ADMediaHolder#insertMedia(long, boolean)
* @see ADMediaHolder#withdrawMedia(long, boolean)
*/
@ApiStatus.OverrideOnly
void setMedia(int media);
void setMedia(long media);
/**
* Whether this media holder can have media inserted into it.
@ -63,7 +63,7 @@ public interface ADMediaHolder {
* <p>
* Withdrawing a negative amount will act as though you attempted to withdraw as much media as the holder contains.
*/
default int withdrawMedia(int cost, boolean simulate) {
default long withdrawMedia(long cost, boolean simulate) {
var mediaHere = getMedia();
if (cost < 0) {
cost = mediaHere;
@ -83,9 +83,9 @@ public interface ADMediaHolder {
* Inserting a negative amount will act as though you attempted to insert exactly as much media as the holder was
* missing.
*/
default int insertMedia(int amount, boolean simulate) {
default long insertMedia(long amount, boolean simulate) {
var mediaHere = getMedia();
int emptySpace = getMaxMedia() - mediaHere;
long emptySpace = getMaxMedia() - mediaHere;
if (emptySpace <= 0) {
return 0;
}
@ -93,7 +93,7 @@ public interface ADMediaHolder {
amount = emptySpace;
}
int inserting = Math.min(amount, emptySpace);
long inserting = Math.min(amount, emptySpace);
if (!simulate) {
var newMedia = mediaHere + inserting;

View file

@ -39,7 +39,7 @@ import java.util.List;
*/
public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implements WorldlyContainer {
private static final DecimalFormat DUST_AMOUNT = new DecimalFormat("###,###.##");
private static final int MAX_CAPACITY = 2_000_000_000;
private static final long MAX_CAPACITY = 9_000_000_000_000_000_000L;
public static final String
TAG_EXECUTION_STATE = "executor",
@ -53,7 +53,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
@Nullable
protected CircleExecutionState executionState;
protected int media = 0;
protected long media = 0;
// these are null together
@Nullable
@ -155,15 +155,15 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
//region media handling
public int getMedia() {
public long getMedia() {
return this.media;
}
public void setMedia(int media) {
public void setMedia(long media) {
this.media = media;
}
public int extractMediaFromInsertedItem(ItemStack stack, boolean simulate) {
public long extractMediaFromInsertedItem(ItemStack stack, boolean simulate) {
if (this.media < 0) {
return 0;
}
@ -188,7 +188,7 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
this.sync();
}
public int remainingMediaCapacity() {
public long remainingMediaCapacity() {
if (this.media < 0) {
return 0;
}
@ -203,7 +203,8 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
tag.put(TAG_EXECUTION_STATE, this.executionState.save());
}
tag.putInt(TAG_MEDIA, this.media);
tag.putLong(TAG_MEDIA, this.media);
if (this.errorMsg != null && this.errorDisplay != null) {
tag.putString(TAG_ERROR_MSG, Component.Serializer.toJson(this.errorMsg));
var itemTag = new CompoundTag();
@ -220,6 +221,12 @@ public abstract class BlockEntityAbstractImpetus extends HexBlockEntity implemen
} else {
this.lazyExecutionState = null;
}
if (tag.contains(TAG_MEDIA, Tag.TAG_INT)) {
this.media = tag.getInt(TAG_MEDIA);
} else if (tag.contains(TAG_MEDIA, Tag.TAG_LONG)) {
this.media = tag.getLong(TAG_MEDIA);
}
}
public void applyScryingLensOverlay(List<Pair<ItemStack, Component>> lines,

View file

@ -15,6 +15,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@ -38,6 +39,8 @@ public class CircleExecutionState {
public Direction enteredFrom;
public CastingImage currentImage;
public final AABB bounds;
protected CircleExecutionState(Set<BlockPos> knownPositions, BlockPos currentPos, Direction enteredFrom,
CastingImage currentImage) {
@ -45,12 +48,17 @@ public class CircleExecutionState {
this.currentPos = currentPos;
this.enteredFrom = enteredFrom;
this.currentImage = currentImage;
this.bounds = BlockEntityAbstractImpetus.getBounds(new ArrayList<>(this.knownPositions));
}
// Return null if the circle does not close.
public static @Nullable CircleExecutionState createNew(BlockEntityAbstractImpetus impetus) {
var level = (ServerLevel) impetus.getLevel();
if (level == null)
return null;
// Flood fill! Just like VCC all over again.
// this contains tentative positions and directions entered from
var todo = new Stack<Pair<Direction, BlockPos>>();
@ -129,6 +137,9 @@ public class CircleExecutionState {
public boolean tick(BlockEntityAbstractImpetus impetus) {
var world = (ServerLevel) impetus.getLevel();
if (world == null)
return true; // if the world is null, try again next tick.
var env = new CircleCastEnv(world, impetus.getBlockPos(), impetus.getStartDirection());
var executorBlock = world.getBlockState(this.currentPos);
@ -165,7 +176,7 @@ public class CircleExecutionState {
}
if (found == null) {
// will never enter here if there were too manu because found will have been set
// will never enter here if there were too many because found will have been set
impetus.postError(
Component.translatable("hexcasting.circles.no_exits",
Component.literal(this.currentPos.toShortString()).withStyle(ChatFormatting.RED)),

View file

@ -7,19 +7,26 @@ import at.petrak.hexcasting.api.casting.eval.CastingEnvironment;
import at.petrak.hexcasting.api.casting.eval.MishapEnvironment;
import at.petrak.hexcasting.api.casting.eval.sideeffects.EvalSound;
import at.petrak.hexcasting.api.misc.FrozenColorizer;
import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.common.lib.hex.HexEvalSounds;
import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class CircleCastEnv extends CastingEnvironment {
protected EvalSound sound = HexEvalSounds.NOTHING;
protected final BlockPos impetusLoc;
protected final Direction startDir;
@ -52,27 +59,39 @@ public class CircleCastEnv extends CastingEnvironment {
@Override
public MishapEnvironment getMishapEnvironment() {
return null;
return new CircleMishapEnv(this.world, this.impetusLoc, this.startDir);
}
@Override
public EvalSound getSoundType() {
return null;
return sound;
}
@Override
public void postExecution(CastResult result) {
this.sound = this.sound.greaterOf(result.getSound());
}
@Override
public Vec3 mishapSprayPos() {
return null;
return Vec3.atCenterOf(impetusLoc);
}
@Override
public long extractMedia(long cost) {
return 0;
var entity = this.getCircle();
if (entity == null)
return cost;
var mediaAvailable = entity.getMedia();
if (mediaAvailable < 0)
return 0;
long mediaToTake = Math.min(cost, mediaAvailable);
cost -= mediaToTake;
entity.setMedia(mediaAvailable - mediaToTake);
return cost;
}
@Override
@ -82,26 +101,26 @@ public class CircleCastEnv extends CastingEnvironment {
@Override
public InteractionHand castingHand() {
return null;
return InteractionHand.MAIN_HAND;
}
@Override
public ItemStack getAlternateItem() {
return null;
return ItemStack.EMPTY.copy();
}
@Override
protected List<ItemStack> getUsableStacks(StackDiscoveryMode mode) {
return null;
return new ArrayList<>(); // TODO: Could do something like get items in inventories adjacent to the circle?
}
@Override
public FrozenColorizer getColorizer() {
return null;
return new FrozenColorizer(new ItemStack(HexItems.DYE_COLORIZERS.get(DyeColor.PURPLE)), Util.NIL_UUID);
}
@Override
public void produceParticles(ParticleSpray particles, FrozenColorizer colorizer) {
particles.sprayParticles(this.world, colorizer);
}
}

View file

@ -0,0 +1,48 @@
package at.petrak.hexcasting.api.casting.eval.env;
import at.petrak.hexcasting.api.casting.eval.MishapEnvironment;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.phys.Vec3;
public class CircleMishapEnv extends MishapEnvironment {
protected final BlockPos impetusLoc;
protected final Direction startDir;
protected CircleMishapEnv(ServerLevel world, BlockPos impetusLoc, Direction startDir) {
super(world, null);
this.impetusLoc = impetusLoc;
this.startDir = startDir;
}
@Override
public void yeetHeldItemsTowards(Vec3 targetPos) {
}
@Override
public void dropHeldItems() {
}
@Override
public void drown() {
}
@Override
public void damage(float healthProportion) {
}
@Override
public void removeXp(int amount) {
}
@Override
public void blind(int ticks) {
}
}

View file

@ -24,7 +24,7 @@ public interface HexHolderItem extends MediaHolderItem {
@Nullable
List<Iota> getHex(ItemStack stack, ServerLevel level);
void writeHex(ItemStack stack, List<Iota> program, int media);
void writeHex(ItemStack stack, List<Iota> program, long media);
void clearHex(ItemStack stack);
}

View file

@ -11,25 +11,25 @@ import org.jetbrains.annotations.ApiStatus;
*/
@ApiStatus.OverrideOnly
public interface MediaHolderItem {
int getMedia(ItemStack stack);
long getMedia(ItemStack stack);
int getMaxMedia(ItemStack stack);
long getMaxMedia(ItemStack stack);
void setMedia(ItemStack stack, int media);
void setMedia(ItemStack stack, long media);
boolean canProvideMedia(ItemStack stack);
boolean canRecharge(ItemStack stack);
default float getMediaFullness(ItemStack stack) {
int max = getMaxMedia(stack);
long max = getMaxMedia(stack);
if (max == 0) {
return 0;
}
return (float) getMedia(stack) / (float) max;
}
default int withdrawMedia(ItemStack stack, int cost, boolean simulate) {
default long withdrawMedia(ItemStack stack, long cost, boolean simulate) {
var mediaHere = getMedia(stack);
if (cost < 0) {
cost = mediaHere;
@ -41,9 +41,9 @@ public interface MediaHolderItem {
return Math.min(cost, mediaHere);
}
default int insertMedia(ItemStack stack, int amount, boolean simulate) {
default long insertMedia(ItemStack stack, long amount, boolean simulate) {
var mediaHere = getMedia(stack);
int emptySpace = getMaxMedia(stack) - mediaHere;
long emptySpace = getMaxMedia(stack) - mediaHere;
if (emptySpace <= 0) {
return 0;
}
@ -51,7 +51,7 @@ public interface MediaHolderItem {
amount = emptySpace;
}
int inserting = Math.min(amount, emptySpace);
long inserting = Math.min(amount, emptySpace);
if (!simulate) {
var newMedia = mediaHere + inserting;

View file

@ -28,10 +28,10 @@ fun isMediaItem(stack: ItemStack): Boolean {
@JvmOverloads
fun extractMedia(
stack: ItemStack,
cost: Int = -1,
cost: Long = -1,
drainForBatteries: Boolean = false,
simulate: Boolean = false
): Int {
): Long {
val mediaHolder = IXplatAbstractions.INSTANCE.findMediaHolder(stack) ?: return 0
return extractMedia(mediaHolder, cost, drainForBatteries, simulate)
@ -47,10 +47,10 @@ fun extractMedia(
*/
fun extractMedia(
holder: ADMediaHolder,
cost: Int = -1,
cost: Long = -1,
drainForBatteries: Boolean = false,
simulate: Boolean = false
): Int {
): Long {
if (drainForBatteries && !holder.canConstructBattery())
return 0
@ -84,11 +84,12 @@ fun compareMediaItem(aMedia: ADMediaHolder, bMedia: ADMediaHolder): Int {
if (priority != 0)
return priority
return aMedia.withdrawMedia(-1, true) - bMedia.withdrawMedia(-1, true)
return (aMedia.withdrawMedia(-1, true) - bMedia.withdrawMedia(-1, true))
.coerceIn(Int.MIN_VALUE.toLong(), Int.MAX_VALUE.toLong()).toInt()
}
fun mediaBarColor(media: Int, maxMedia: Int): Int {
val amt = if (maxMedia == 0) {
fun mediaBarColor(media: Long, maxMedia: Long): Int {
val amt = if (maxMedia == 0L) {
0f
} else {
media.toFloat() / maxMedia.toFloat()
@ -100,8 +101,8 @@ fun mediaBarColor(media: Int, maxMedia: Int): Int {
return Mth.color(r / 255f, g / 255f, b / 255f)
}
fun mediaBarWidth(media: Int, maxMedia: Int): Int {
val amt = if (maxMedia == 0) {
fun mediaBarWidth(media: Long, maxMedia: Long): Int {
val amt = if (maxMedia == 0L) {
0f
} else {
media.toFloat() / maxMedia.toFloat()

View file

@ -16,7 +16,7 @@ class OpCircleBounds(val max: Boolean) : ConstMediaAction {
throw MishapNoSpellCircle()
val circle = ctx.circle ?: throw MishapNoSpellCircle()
val aabb = circle.getBounds(listOf())
val aabb = circle.executionState!!.bounds // the circle should have an execution state since it's executing this.
return if (max)
Vec3(aabb.maxX - 0.5, aabb.maxY - 0.5, aabb.maxZ - 0.5).asActionResult

View file

@ -18,6 +18,7 @@ import net.minecraft.world.InteractionHand
import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.ItemStack
// TODO: how to handle in cirles
object OpMakeBattery : SpellAction {
override val argc = 1

View file

@ -14,6 +14,7 @@ import at.petrak.hexcasting.xplat.IXplatAbstractions
import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.item.ItemStack
// TODO: How to handle in circles
class OpMakePackagedSpell<T : ItemPackagedHex>(val itemType: T, val cost: Int) : SpellAction {
override val argc = 2
override fun execute(

View file

@ -21,6 +21,7 @@ import net.minecraft.world.item.context.UseOnContext
import net.minecraft.world.phys.BlockHitResult
import net.minecraft.world.phys.Vec3
// TODO: how to handle in cirles
object OpPlaceBlock : SpellAction {
override val argc: Int
get() = 1

View file

@ -31,7 +31,7 @@ object OpPrint : Action {
private data class Spell(val datum: Iota) : RenderedSpell {
override fun cast(ctx: CastingEnvironment) {
ctx.caster?.sendSystemMessage(datum.display())
ctx.caster?.sendSystemMessage(datum.display()) // TODO: how to handle in cirles
}
}
}

View file

@ -25,7 +25,7 @@ object OpRecharge : SpellAction {
val (handStack, hand) = ctx.getHeldItemToOperateOn {
val media = IXplatAbstractions.INSTANCE.findMediaHolder(it)
media != null && media.canRecharge() && media.insertMedia(-1, true) != 0
media != null && media.canRecharge() && media.insertMedia(-1, true) != 0L
}
val media = IXplatAbstractions.INSTANCE.findMediaHolder(handStack)
@ -46,7 +46,7 @@ object OpRecharge : SpellAction {
)
}
if (media.insertMedia(-1, true) == 0)
if (media.insertMedia(-1, true) == 0L)
return null
return Triple(

View file

@ -5,17 +5,17 @@ import net.minecraft.world.item.ItemStack;
public record DebugUnlockerHolder(ItemStack creativeUnlocker) implements ADMediaHolder {
@Override
public int getMedia() {
public long getMedia() {
return Integer.MAX_VALUE;
}
@Override
public int getMaxMedia() {
public long getMaxMedia() {
return Integer.MAX_VALUE - 1;
}
@Override
public void setMedia(int media) {
public void setMedia(long media) {
// NO-OP
}
@ -40,15 +40,15 @@ public record DebugUnlockerHolder(ItemStack creativeUnlocker) implements ADMedia
}
@Override
public int withdrawMedia(int cost, boolean simulate) {
ItemCreativeUnlocker.addToIntArray(creativeUnlocker, ItemCreativeUnlocker.TAG_EXTRACTIONS, cost);
public long withdrawMedia(long cost, boolean simulate) {
ItemCreativeUnlocker.addToLongArray(creativeUnlocker, ItemCreativeUnlocker.TAG_EXTRACTIONS, cost);
return cost < 0 ? getMedia() : cost;
}
@Override
public int insertMedia(int amount, boolean simulate) {
ItemCreativeUnlocker.addToIntArray(creativeUnlocker, ItemCreativeUnlocker.TAG_INSERTIONS, amount);
public long insertMedia(long amount, boolean simulate) {
ItemCreativeUnlocker.addToLongArray(creativeUnlocker, ItemCreativeUnlocker.TAG_INSERTIONS, amount);
return amount;
}

View file

@ -65,7 +65,10 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem {
});
DiscoveryHandlers.addMediaHolderDiscoverer(harness -> {
var player = harness.getCtx().getCaster();
var player = harness.getEnv().getCaster();
if (player == null)
return List.of();
if (!player.isCreative())
return List.of();
@ -117,12 +120,12 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem {
}
@Override
public int getMaxMedia(ItemStack stack) {
return Integer.MAX_VALUE - 1;
public long getMaxMedia(ItemStack stack) {
return Long.MAX_VALUE - 1;
}
@Override
public void setMedia(ItemStack stack, int media) {
public void setMedia(ItemStack stack, long media) {
// NO-OP
}
@ -146,21 +149,31 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem {
NBTHelper.putIntArray(stack, tag, newArr);
}
public static void addToLongArray(ItemStack stack, String tag, long n) {
long[] arr = NBTHelper.getLongArray(stack, tag);
if (arr == null) {
arr = new long[0];
}
long[] newArr = Arrays.copyOf(arr, arr.length + 1);
newArr[newArr.length - 1] = n;
NBTHelper.putLongArray(stack, tag, newArr);
}
@Override
public int withdrawMedia(ItemStack stack, int cost, boolean simulate) {
public long withdrawMedia(ItemStack stack, long cost, boolean simulate) {
// In case it's withdrawn through other means
if (!simulate && isDebug(stack, DISPLAY_MEDIA)) {
addToIntArray(stack, TAG_EXTRACTIONS, cost);
addToLongArray(stack, TAG_EXTRACTIONS, cost);
}
return cost < 0 ? getMedia(stack) : cost;
}
@Override
public int insertMedia(ItemStack stack, int amount, boolean simulate) {
public long insertMedia(ItemStack stack, long amount, boolean simulate) {
// In case it's inserted through other means
if (!simulate && isDebug(stack, DISPLAY_MEDIA)) {
addToIntArray(stack, TAG_INSERTIONS, amount);
addToLongArray(stack, TAG_INSERTIONS, amount);
}
return amount < 0 ? getMaxMedia(stack) : amount;
@ -180,10 +193,10 @@ public class ItemCreativeUnlocker extends Item implements MediaHolderItem {
}
private void debugDisplay(ItemStack stack, String tag, String langKey, String allKey, Entity entity) {
int[] arr = NBTHelper.getIntArray(stack, tag);
long[] arr = NBTHelper.getLongArray(stack, tag);
if (arr != null) {
NBTHelper.remove(stack, tag);
for (int i : arr) {
for (long i : arr) {
if (i < 0) {
entity.sendSystemMessage(Component.translatable("hexcasting.debug.media_" + langKey,
stack.getDisplayName(),

View file

@ -35,29 +35,35 @@ public abstract class ItemMediaHolder extends Item implements MediaHolderItem {
super(pProperties);
}
public static ItemStack withMedia(ItemStack stack, int media, int maxMedia) {
public static ItemStack withMedia(ItemStack stack, long media, long maxMedia) {
Item item = stack.getItem();
if (item instanceof ItemMediaHolder) {
NBTHelper.putInt(stack, TAG_MEDIA, media);
NBTHelper.putInt(stack, TAG_MAX_MEDIA, maxMedia);
NBTHelper.putLong(stack, TAG_MEDIA, media);
NBTHelper.putLong(stack, TAG_MAX_MEDIA, maxMedia);
}
return stack;
}
@Override
public int getMedia(ItemStack stack) {
return NBTHelper.getInt(stack, TAG_MEDIA);
public long getMedia(ItemStack stack) {
if (NBTHelper.hasInt(stack, TAG_MEDIA))
return NBTHelper.getInt(stack, TAG_MEDIA);
return NBTHelper.getLong(stack, TAG_MEDIA);
}
@Override
public int getMaxMedia(ItemStack stack) {
return NBTHelper.getInt(stack, TAG_MAX_MEDIA);
public long getMaxMedia(ItemStack stack) {
if (NBTHelper.hasInt(stack, TAG_MAX_MEDIA))
return NBTHelper.getInt(stack, TAG_MAX_MEDIA);
return NBTHelper.getLong(stack, TAG_MAX_MEDIA);
}
@Override
public void setMedia(ItemStack stack, int media) {
NBTHelper.putInt(stack, TAG_MEDIA, Mth.clamp(media, 0, getMaxMedia(stack)));
public void setMedia(ItemStack stack, long media) {
NBTHelper.putLong(stack, TAG_MEDIA, Mth.clamp(media, 0, getMaxMedia(stack)));
}
@Override

View file

@ -74,7 +74,7 @@ public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHold
}
@Override
public void writeHex(ItemStack stack, List<Iota> program, int media) {
public void writeHex(ItemStack stack, List<Iota> program, long media) {
ListTag patsTag = new ListTag();
for (Iota pat : program) {
patsTag.add(IotaType.serialize(pat));

View file

@ -45,7 +45,7 @@ public abstract class CCHexHolder extends ItemComponent implements ADHexHolder {
}
@Override
public void writeHex(List<Iota> patterns, int media) {
public void writeHex(List<Iota> patterns, long media) {
this.hexHolder.writeHex(this.stack, patterns, media);
}

View file

@ -25,17 +25,17 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold
}
@Override
public int getMedia() {
public long getMedia() {
return this.mediaHolder.getMedia(this.stack);
}
@Override
public int getMaxMedia() {
public long getMaxMedia() {
return this.mediaHolder.getMaxMedia(this.stack);
}
@Override
public void setMedia(int media) {
public void setMedia(long media) {
this.mediaHolder.setMedia(this.stack, media);
}
@ -60,12 +60,12 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold
}
@Override
public int withdrawMedia(int cost, boolean simulate) {
public long withdrawMedia(long cost, boolean simulate) {
return this.mediaHolder.withdrawMedia(this.stack, cost, simulate);
}
@Override
public int insertMedia(int amount, boolean simulate) {
public long insertMedia(long amount, boolean simulate) {
return this.mediaHolder.insertMedia(this.stack, amount, simulate);
}
}
@ -81,17 +81,17 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold
}
@Override
public int getMedia() {
return baseWorth.get() * stack.getCount();
public long getMedia() {
return (long) baseWorth.get() * stack.getCount();
}
@Override
public int getMaxMedia() {
public long getMaxMedia() {
return getMedia();
}
@Override
public void setMedia(int media) {
public void setMedia(long media) {
// NO-OP
}
@ -116,8 +116,8 @@ public abstract class CCMediaHolder extends ItemComponent implements ADMediaHold
}
@Override
public int withdrawMedia(int cost, boolean simulate) {
int worth = baseWorth.get();
public long withdrawMedia(long cost, boolean simulate) {
long worth = baseWorth.get();
if (cost < 0) {
cost = worth * stack.getCount();
}

View file

@ -28,7 +28,7 @@ public record CapItemHexHolder(HexHolderItem holder,
}
@Override
public void writeHex(List<Iota> patterns, int media) {
public void writeHex(List<Iota> patterns, long media) {
holder.writeHex(stack, patterns, media);
}

View file

@ -11,17 +11,17 @@ public record CapItemMediaHolder(MediaHolderItem holder,
ItemStack stack) implements ADMediaHolder {
@Override
public int getMedia() {
public long getMedia() {
return holder.getMedia(stack);
}
@Override
public int getMaxMedia() {
public long getMaxMedia() {
return holder.getMaxMedia(stack);
}
@Override
public void setMedia(int media) {
public void setMedia(long media) {
holder.setMedia(stack, media);
}
@ -46,12 +46,12 @@ public record CapItemMediaHolder(MediaHolderItem holder,
}
@Override
public int withdrawMedia(int cost, boolean simulate) {
public long withdrawMedia(long cost, boolean simulate) {
return holder.withdrawMedia(stack, cost, simulate);
}
@Override
public int insertMedia(int amount, boolean simulate) {
public long insertMedia(long amount, boolean simulate) {
return holder.insertMedia(stack, amount, simulate);
}
}

View file

@ -12,17 +12,17 @@ public record CapStaticMediaHolder(Supplier<Integer> baseWorth,
int consumptionPriority,
ItemStack stack) implements ADMediaHolder {
@Override
public int getMedia() {
return baseWorth.get() * stack.getCount();
public long getMedia() {
return (long) baseWorth.get() * stack.getCount();
}
@Override
public int getMaxMedia() {
public long getMaxMedia() {
return getMedia();
}
@Override
public void setMedia(int media) {
public void setMedia(long media) {
// NO-OP
}
@ -47,8 +47,8 @@ public record CapStaticMediaHolder(Supplier<Integer> baseWorth,
}
@Override
public int withdrawMedia(int cost, boolean simulate) {
int worth = baseWorth.get();
public long withdrawMedia(long cost, boolean simulate) {
long worth = baseWorth.get();
if (cost < 0) {
cost = worth * stack.getCount();
}