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
Expand Up @@ -16,7 +16,7 @@ public interface ADHexHolder {
@Nullable
List<Iota> getHex(ServerLevel level);

void writeHex(List<Iota> patterns, @Nullable FrozenPigment pigment, long media);
void writeHex(List<Iota> patterns, FrozenPigment pigment, long media);

void clearHex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public enum StackDiscoveryMode {

public abstract FrozenPigment getPigment();

public abstract @Nullable FrozenPigment setPigment(@Nullable FrozenPigment pigment);
public abstract FrozenPigment setPigment(FrozenPigment pigment);

public abstract void produceParticles(ParticleSpray particles, FrozenPigment colorizer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public FrozenPigment getPigment() {
}

@Override
public @Nullable FrozenPigment setPigment(@Nullable FrozenPigment pigment) {
public FrozenPigment setPigment(FrozenPigment pigment) {
var impetus = this.getImpetus();
if (impetus == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ protected boolean canOvercast() {
}

@Override
public @Nullable FrozenPigment setPigment(@Nullable FrozenPigment pigment) {
public FrozenPigment setPigment(FrozenPigment pigment) {
return IXplatAbstractions.INSTANCE.setPigment(caster, pigment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface HexHolderItem extends MediaHolderItem {
@Nullable
List<Iota> getHex(ItemStack stack, ServerLevel level);

void writeHex(ItemStack stack, List<Iota> program, @Nullable FrozenPigment pigment, long media);
void writeHex(ItemStack stack, List<Iota> program, FrozenPigment pigment, long media);

void clearHex(ItemStack stack);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import java.util.List;

public class ItemAncientCypher extends ItemCypher {
public static final String TAG_HEX_NAME = "hex_name";

public ItemAncientCypher(Properties pProperties) {
super(pProperties);
}
Expand All @@ -37,13 +35,12 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
// display media fullness as usual
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);

var patterns = stack.get(HexDataComponents.HEX_HOLDER_PATTERNS.get());

// also show contained spell
if(patterns != null) {
var hexHolder = stack.get(HexDataComponents.HEX_HOLDER.get());
if(hexHolder != null) {
var storedHex = Component.translatable("hexcasting.tooltip.stored_hex");

for(var iota : patterns) {
for(var iota : hexHolder.hex()) {
storedHex.append(iota.display().plainCopy().withStyle(ChatFormatting.DARK_PURPLE));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ public static Component infiniteMedia(Level level) {
return emphasized;
}

public static final String TAG_EXTRACTIONS = "extractions";
public static final String TAG_INSERTIONS = "insertions";

public ItemCreativeUnlocker(Properties properties) {
super(properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
import java.util.List;

public abstract class ItemMediaHolder extends Item implements MediaHolderItem {
public static final String TAG_MEDIA = "hexcasting:media";
public static final String TAG_MAX_MEDIA = "hexcasting:start_media";

public static final TextColor HEX_COLOR = TextColor.fromRgb(0xb38ef3);

private static final DecimalFormat PERCENTAGE = new DecimalFormat("####");
Expand All @@ -37,7 +34,7 @@ public static ItemStack withMedia(ItemStack stack, long media, long maxMedia) {
Item item = stack.getItem();
if (item instanceof ItemMediaHolder) {
stack.set(HexDataComponents.MEDIA.get(), media);
stack.set(HexDataComponents.MEDIA_MAX.get(), media);
stack.set(HexDataComponents.MEDIA_MAX.get(), maxMedia);
}

return stack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import at.petrak.hexcasting.api.casting.eval.env.PackagedItemCastEnv;
import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
import at.petrak.hexcasting.api.casting.iota.Iota;
import at.petrak.hexcasting.api.casting.iota.PatternIota;
import at.petrak.hexcasting.api.casting.iota.IotaType;
import at.petrak.hexcasting.api.item.HexHolderItem;
import at.petrak.hexcasting.api.pigment.FrozenPigment;
import at.petrak.hexcasting.common.lib.HexDataComponents;
import at.petrak.hexcasting.common.msgs.MsgNewSpiralPatternsS2C;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand All @@ -24,6 +27,7 @@
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -34,8 +38,6 @@
* Item that holds a list of patterns in it ready to be cast
*/
public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHolderItem {
public static final String TAG_PROGRAM = "patterns";
public static final String TAG_PIGMENT = "pigment";
public static final ResourceLocation HAS_PATTERNS_PRED = modLoc("has_patterns");

public ItemPackagedHex(Properties pProperties) {
Expand All @@ -58,34 +60,32 @@ public boolean canProvideMedia(ItemStack stack) {

@Override
public boolean hasHex(ItemStack stack) {
return stack.has(HexDataComponents.HEX_HOLDER_PATTERNS.get());
return stack.has(HexDataComponents.HEX_HOLDER.get());
}

@Override
public @Nullable List<Iota> getHex(ItemStack stack, ServerLevel level) {
return stack.get(HexDataComponents.HEX_HOLDER_PATTERNS.get());
var hexHolder = stack.get(HexDataComponents.HEX_HOLDER.get());
return (hexHolder != null) ? hexHolder.hex() : null;
}

@Override
public void writeHex(ItemStack stack, List<Iota> program, @Nullable FrozenPigment pigment, long media) {
stack.set(HexDataComponents.HEX_HOLDER_PATTERNS.get(), program);
if (pigment != null)
stack.set(HexDataComponents.PIGMENT.get(), pigment);

public void writeHex(ItemStack stack, List<Iota> program, FrozenPigment pigment, long media) {
stack.set(HexDataComponents.HEX_HOLDER.get(), new HexHolder(program, pigment));
withMedia(stack, media, media);
}

@Override
public void clearHex(ItemStack stack) {
stack.remove(HexDataComponents.HEX_HOLDER_PATTERNS.get());
stack.remove(HexDataComponents.PIGMENT.get());
stack.remove(HexDataComponents.HEX_HOLDER.get());
stack.remove(HexDataComponents.MEDIA.get());
stack.remove(HexDataComponents.MEDIA_MAX.get());
}

@Override
public @Nullable FrozenPigment getPigment(ItemStack stack) {
return stack.get(HexDataComponents.PIGMENT.get());
var hexHolder = stack.get(HexDataComponents.HEX_HOLDER.get());
return (hexHolder != null) ? hexHolder.pigment() : null;
}

@Override
Expand Down Expand Up @@ -147,4 +147,18 @@ public InteractionResultHolder<ItemStack> use(Level world, Player player, Intera
public UseAnim getUseAnimation(ItemStack pStack) {
return UseAnim.BLOCK;
}

public record HexHolder(@NotNull List<Iota> hex, @NotNull FrozenPigment pigment) {
public static final Codec<HexHolder> CODEC = RecordCodecBuilder.create(inst ->
inst.group(
IotaType.TYPED_CODEC.listOf().fieldOf("hex").forGetter(HexHolder::hex),
FrozenPigment.CODEC.fieldOf("pigment").forGetter(HexHolder::pigment)
).apply(inst, HexHolder::new)
);
public static final StreamCodec<RegistryFriendlyByteBuf, HexHolder> STREAM_CODEC = StreamCodec.composite(
IotaType.TYPED_STREAM_CODEC.apply(ByteBufCodecs.list()), HexHolder::hex,
FrozenPigment.STREAM_CODEC, HexHolder::pigment,
HexHolder::new
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import at.petrak.hexcasting.common.lib.HexDataComponents;
import at.petrak.hexcasting.common.misc.PatternTooltip;
import at.petrak.hexcasting.interop.inline.InlinePatternData;
import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -36,11 +37,11 @@
import static at.petrak.hexcasting.api.HexAPI.modLoc;

/**
* TAG_OP_ID and TAG_PATTERN: "Ancient Scroll of %s" (per-world pattern preloaded)
* ACTION and PATTERN components: "Ancient Scroll of %s" (per-world pattern preloaded)
* <br>
* TAG_OP_ID: "Ancient Scroll of %s" (per-world pattern loaded on inv tick)
* Only ACTION component: "Ancient Scroll of %s" (per-world pattern loaded on inv tick)
* <br>
* TAG_PATTERN: "Scroll" (custom)
* Only PATTERN component: "Scroll" (custom)
* <br>
* (none): "Empty Scroll"
*/
Expand Down Expand Up @@ -146,21 +147,21 @@ public Component getName(ItemStack pStack) {

@Override
public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) {
// the needs_purchase tag is used so you can't see the pattern on scrolls sold by a wandering trader
// once you put the scroll into your inventory, this removes the tag to reveal the pattern
// the NEEDS_PURCHASE component is used so you can't see the pattern on scrolls sold by a wandering trader
// once you put the scroll into your inventory, this removes the component to reveal the pattern
if(pStack.has(HexDataComponents.NEEDS_PURCHASE.get()))
pStack.remove(HexDataComponents.NEEDS_PURCHASE.get());
// if op_id is set but there's no stored pattern, attempt to load the pattern on inv tick
// if ACTION is present but PATTERN is not present, attempt to load the pattern on inv tick
if (pStack.has(HexDataComponents.ACTION.get()) && !pStack.has(HexDataComponents.PATTERN.get()) && pEntity.getServer() != null) {
var action = pStack.get(HexDataComponents.ACTION.get());
if (action == null) {
// if the provided op_id is invalid, remove it so we don't keep trying every tick
if (!IXplatAbstractions.INSTANCE.getActionRegistry().containsKey(action)) {
// if the specified Action doesn't actually exist, remove the component so we don't keep trying every tick
pStack.remove(HexDataComponents.ACTION.get());
return;
}
var pat = PatternRegistryManifest.getCanonicalStrokesPerWorld(action, pEntity.getServer().overworld());
if (pat == null) {
// if pat is null, the per-world order hasn't been registered; remove the op_id and warn the player
// if pat is null, the per-world order hasn't been registered; remove the ACTION component and warn the player
pStack.set(HexDataComponents.RECALC_WARNING.get(), action);
pStack.remove(HexDataComponents.ACTION.get());
return;
Expand All @@ -175,7 +176,7 @@ public void appendHoverText(ItemStack stack, TooltipContext context, List<Compon
var needsPurchase = Component.translatable("hexcasting.tooltip.scroll.needs_purchase");
tooltipComponents.add(needsPurchase.withStyle(ChatFormatting.GRAY));
} else if (stack.has(HexDataComponents.RECALC_WARNING.get())) {
var spellName = Component.translatable("hexcasting.action." + stack.get(HexDataComponents.RECALC_WARNING.get()));
var spellName = Component.translatable("hexcasting.action." + stack.get(HexDataComponents.RECALC_WARNING.get()).location());
var line1 = Component.translatable("hexcasting.tooltip.scroll.recalc_warning.line1", spellName);
var line2 = Component.translatable("hexcasting.tooltip.scroll.recalc_warning.line2");
tooltipComponents.add(line1.withStyle(ChatFormatting.RED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,22 @@ public void inventoryTick(ItemStack stack, Level level, Entity pEntity, int pSlo
var savedNames = stack.get(HexDataComponents.SPELLBOOK_PAGE_NAMES.get());

if(customName != null) {
// the stack has been given a custom name (ie via anvil)
if(savedNames != null) {
if(!savedNames.containsKey(nameKey) || !savedNames.get(nameKey).equals(customName)) {
// if this page doesn' have a name mapping, or it doesn't match, create/update the name mapping
var mutNames = new HashMap<>(savedNames);
mutNames.put(nameKey, customName);
stack.set(HexDataComponents.SPELLBOOK_PAGE_NAMES.get(), mutNames);
}
} else {
var mutNames = new HashMap<String, Component>();
mutNames.put(nameKey, customName);
// if the savedNames map doesn't exist at all, create it and map the stack's current name to this page
stack.set(HexDataComponents.SPELLBOOK_PAGE_NAMES.get(), mutNames);
}
} else if(savedNames != null) {
// the stack does not have a custom name, or it has been removed
var mutNames = new HashMap<>(savedNames);
mutNames.remove(nameKey);
if(mutNames.isEmpty()) {
Expand Down Expand Up @@ -151,10 +155,12 @@ public void writeDatum(ItemStack stack, Iota datum) {
var pages = stack.get(HexDataComponents.SPELLBOOK_PAGES.get());

if (pages != null) {
// if the pages map exists, modify it accordingly
var pagesMut = new HashMap<>(pages);

if (datum == null) {
pagesMut.remove(key);
// erasing the current page (needs to unseal as well, if possible)
var seals = stack.get(HexDataComponents.SPELLBOOK_PAGE_SEALS.get());
if(seals != null) {
var sealsMut = new HashMap<>(seals);
Expand All @@ -169,6 +175,7 @@ public void writeDatum(ItemStack stack, Iota datum) {
}
} else {
pagesMut.put(key, datum);
// updating the current page
}

if (pagesMut.isEmpty()) {
Expand All @@ -179,8 +186,11 @@ public void writeDatum(ItemStack stack, Iota datum) {
} else if (datum != null) {
var map = new HashMap<String, Iota>();
map.put(key, datum);
// if the pages map doesn't exist and you're trying to update a page, create the map first
stack.set(HexDataComponents.SPELLBOOK_PAGES.get(), map);
} else {
// if the pages map doesn't exist and you're trying to erase a page, check for a seal to remove
// this can happen if somebody seals an empty book for some reason
var seals = stack.get(HexDataComponents.SPELLBOOK_PAGE_SEALS.get());
if(seals != null) {
var sealsMut = new HashMap<>(seals);
Expand Down
Loading
Loading