Compare commits

...
2 Commits
Author SHA1 Message Date
dnorberg 68db795216 Cover panel-only book modifiers with regression test
Build / build (push) Canceled after 0s
2026-10-03 07:46:49 -04:00
dnorberg b86e855907 Add Link Panel modifiers and legacy Ink Mixer presentation (#36)
Build / build (push) Canceled after 0s
2026-10-03 07:36:46 -04:00
30 changed files with 753 additions and 68 deletions

No files matched your search

+4 -2
View File
@@ -22,8 +22,10 @@ and link-panel costs in the `writing` section of `rivencraft-server.toml`.
The Ink Mixer now offers a Legacy-style station for producing Link Panels: The Ink Mixer now offers a Legacy-style station for producing Link Panels:
insert paper and Ink Vials, then take a Link Panel from the result slot. Each insert paper and Ink Vials, then take a Link Panel from the result slot. Each
vial fills its 16-unit basin and returns a glass bottle; no server tick is vial fills its 16-unit basin and returns a glass bottle; no server tick is
needed. The earlier paper-in-one-hand method remains available. Ink modifier needed. The earlier paper-in-one-hand method remains available. Ink Mixer
ingredients and link properties are planned for Milestone 5. additives can roll Disarm, Maintain Momentum, and Intra Linking onto a Link
Panel. Descriptive Books retain Disarm and Momentum; Intra Linking is only
meaningful for same-dimension travel with a Linking Book.
The Writing Desk can copy a selected written page from its collection tabs. The Writing Desk can copy a selected written page from its collection tabs.
The Writing Desk is now craftable from planks, a glass bottle, and a feather. The Writing Desk is now craftable from planks, a glass bottle, and a feather.
It occupies two adjacent blocks, with one shared inventory; loaded paper and It occupies two adjacent blocks, with one shared inventory; loaded paper and
+41
View File
@@ -47,6 +47,47 @@ automated check, and hand its exact scenario to the player for in-game
verification. Do not keep retrying a stalled test or leave its process running. verification. Do not keep retrying a stalled test or leave its process running.
Keep the narrower non-stalling plan, persistence, and runtime checks automated. Keep the narrower non-stalling plan, persistence, and runtime checks automated.
## Manual Ink Mixer modifier check (Milestone 5, issue #36)
With optional JEI installed, search for the Ink Mixer category. It should show
the base paper/ink/vial operation and separate entries for Gunpowder, Mushroom
Stew, Experience Bottle, Ender Pearl, Feather, and Fire Charge,
with their property chances. Black Dye and Clay Ball should not appear: the
former had no working Legacy effect, while Generate Platform is redundant
with default Age arrival. Without JEI, Rivencraft should still
start and the mixer should work normally.
Put paper and an Ink Vial in the mixer. Hold Gunpowder on the cursor and
right-click the ink basin once; one Gunpowder should be consumed, and hovering
the basin should show a 20% Disarm chance. Black Dye, Clay Balls, and an
unrelated item such as Stone should remain untouched.
Closing and reopening the mixer should retain the chance. Taking a Link Panel
should consume one paper and the configured ink cost, clear the current
mixture, and possibly give a panel with Disarm on its tooltip. Repeat until
a property-bearing panel appears, craft it with leather, and confirm the
unwritten Linking Book preserves the property tooltip. After binding it,
link to another dimension; inventory items should drop at the departure point.
With twenty Ender Pearls added to a fresh mixture, both Disarm and Intra
Linking should show about 96.1%, and the basin should animate both property
colors. Taking a panel should reset all three percentages and clear the color
effect; a near-certain modifier should show the brighter outer animation.
Also bind a Descriptive Book with a Disarm panel and check the same drop behavior.
Bind a Descriptive Book with both Intra Linking and Maintain Momentum on its
panel: the assembled book should retain Maintain Momentum but omit Intra
Linking. For Linking Books, try an unmodified book whose destination is the
current dimension: it should refuse travel. A Linking Book with Intra Linking
should work in the same dimension. A Descriptive Book does not require or use
Intra Linking, even if an older book retained that flag.
Automatic Return Links should still appear according to the existing setting
and work from an Age back to the Overworld. A full player inventory or blocked glass-bottle slot
must not duplicate or consume materials for an output that cannot be taken.
Link Panels should not enter Notebooks (folders) or Writing Desk tabs, whether
clicked, shift-clicked, or dragged onto the page surface. An old Notebook or
Desk already holding a Link Panel should still let the player take it out,
but the Desk must not offer a copy of it. The Desk should continue to copy
ordinary symbol Pages; JEI should show that example instead of Link Panel copying.
## Manual Age unload/reload check ## Manual Age unload/reload check
The automated suite does not unload a freshly generated Age. Minecraft can The automated suite does not unload a freshly generated Age. Minecraft can
+30
View File
@@ -0,0 +1,30 @@
# Ink Mixer and Link Panel modifiers (Milestone 5, issue #36)
Legacy source: [`InkEffects`](https://github.com/Mystcraft/Mystcraft-Legacy/blob/9bc8ddc061845df0cd5ea47f4fdef773cff786ae/src/main/java/com/xcompwiz/mystcraft/data/InkEffects.java), [`TileEntityInkMixer`](https://github.com/Mystcraft/Mystcraft-Legacy/blob/9bc8ddc061845df0cd5ea47f4fdef773cff786ae/src/main/java/com/xcompwiz/mystcraft/tileentity/TileEntityInkMixer.java), and [`LinkPropertyAPI`](https://github.com/Mystcraft/Mystcraft-Legacy/blob/9bc8ddc061845df0cd5ea47f4fdef773cff786ae/src/api/java/com/xcompwiz/mystcraft/api/hook/LinkPropertyAPI.java).
Legacy does **not** use a conventional ingredient slot: the player clicks the ink basin with a carried item. Each accepted item is consumed immediately, changing the basin's property probabilities. A Link Panel is a virtual result; taking it consumes paper and ink, rolls each property independently using a saved next-seed, writes the selected flags to the Page, then resets that basin's mixture. The Link Panel passes those flags to a Linking Book made with leather. The preview must not roll or consume anything.
| Ingredient | Property | Chance per item |
| --- | --- | ---: |
| Gunpowder | Disarm | 20% |
| Mushroom Stew | Disarm | 5% |
| Clay Ball | Generate Platform | 25% |
| Experience Bottle | Intra Linking | 15% |
| Ender Pearl | Intra Linking + Disarm | 15% each |
| Feather | Maintain Momentum | 15% |
| Fire Charge | Disarm | 25% |
| Black dye | Empty effect key; ignored by Legacy's mixer | None in practice |
Legacy also has optional ore-dictionary dusts: brass, bronze, tin, iron, lead, silver, diamond, and gold. Their effect combinations are in `InkEffects.init()`. Forge's ore dictionary does not exist in NeoForge 1.21.1, so these should be mapped through item tags only when a suitable tag and item exist; none should become a hard dependency. The `Relative` and `Intra Linking Only` properties are registered but have no built-in ingredient. `Natural`, `External`, `Offensive`, `Op-TP`, and `Following` are internal link flags, not mixer ingredients.
For each additive, Legacy scales each existing probability by `1 - sum(additive chances)` and then adds the additive's probabilities. Properties are rolled independently on the final Page. The Legacy link effects are: Disarm drops carried inventory before travel; Generate Platform places a single arrival block if a drop exists; Maintain Momentum retains velocity; Intra Linking permits a same-dimension link.
Rivencraft deliberately diverges from Legacy's shared-probability dilution here: each supported modifier accumulates independently as `new = 1 - (1 - old) × (1 - item chance)^item count`. Twenty Ender Pearls therefore produce about 96.1% each for Disarm and Intra Linking, and a panel can receive both. Taking the panel resets every probability to zero. The GUI uses Legacy's empty-basin atlas sprite, fills the basin dark when ink is present, and projects its colored rotating D'ni effect over the ink (red Disarm, blue Momentum, green Intra); the effect intensifies as a modifier approaches certainty and disappears after output is taken.
Implementation requirements: keep the mixer server-authoritative; persist mixture probabilities and next-seed; show a deterministic virtual result; consume exact inputs once; prevent duplicate output on shift-click; preserve inputs when output cannot be taken; copy the Page's link properties into a Linking Book; apply supported properties only after destination validation; retain unmodified books' current safe-link behavior; and expose both base and modifier sequences to optional JEI. Tests should cover persistence, multiple additives, invalid items, full inventory/bottle output, and panel-to-book transfer.
## Rivencraft 0.4.7.x implementation scope
The built-in vanilla-item rows above are supported except black dye and clay balls. Legacy ignores black dye's empty effect key, so Rivencraft does not consume or advertise it in JEI. Clay Balls are omitted because Age arrival already builds a safe platform by default and a separate Generate Platform link modifier would be redundant. Right-clicking the Ink Mixer basin with a carried item adds one; left-clicking adds the carried stack. The mixture is persistent and its next panel is deterministic. The visual basin tooltip shows current probabilities. Only taking the virtual Link Panel consumes paper/ink and clears the mixture. The Link Panel's property component is copied to a Linking Book by the leather recipe or a Descriptive Book by the Binder. JEI's optional Ink Mixer category lists the base panel and each supported additive interaction with its per-property chance; Rivencraft does not require JEI to run.
Disarm and Maintain Momentum are applied by the server after confirming a safe destination. Disarm spawns each inventory stack as an item entity at the departure point, including for Descriptive Books. Intra Linking is required only for a Linking Book whose destination is in the player's current dimension; ordinary cross-dimensional Linking Books still work. The Binder treats an Intra Linking panel as an ordinary Link Panel and omits that flag from the resulting Descriptive Book, while retaining Disarm and Maintain Momentum. Automatic Return Links remain enabled under the existing configuration, as requested. The old Generate Platform bit remains readable on pre-0.4.7.1 test items but is neither rolled nor applied. Optional dust-tag mappings remain outside this built-in subset until their cross-mod tags and gameplay meaning are agreed.
+1 -1
View File
@@ -36,7 +36,7 @@ mod_name=Rivencraft
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=LGPL-3.0-or-later mod_license=LGPL-3.0-or-later
# The mod version. Rivencraft uses the x.y.z.b policy documented in README.md. # The mod version. Rivencraft uses the x.y.z.b policy documented in README.md.
mod_version=0.4.6.9 mod_version=0.4.7.4
immersive_portals_version=6.0.7 immersive_portals_version=6.0.7
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources. # This should match the base package used for the mod sources.
@@ -238,6 +238,11 @@ public final class BookBinderBlockEntity extends BlockEntity implements Containe
ItemStack book = new ItemStack(ModItems.DESCRIPTIVE_BOOK.get()); ItemStack book = new ItemStack(ModItems.DESCRIPTIVE_BOOK.get());
book.set(ModDataComponents.AGE_REFERENCE.get(), new AgeReference(pendingAgeId, title)); book.set(ModDataComponents.AGE_REFERENCE.get(), new AgeReference(pendingAgeId, title));
book.set(ModDataComponents.BOOK_WRITING.get(), currentWriting()); book.set(ModDataComponents.BOOK_WRITING.get(), currentWriting());
if (items.get(LINK_PANEL).has(ModDataComponents.LINK_PROPERTIES.get())) {
var properties = items.get(LINK_PANEL).get(ModDataComponents.LINK_PROPERTIES.get())
.forDescriptiveBook();
if (properties.flags() != 0) book.set(ModDataComponents.LINK_PROPERTIES.get(), properties);
}
book.set(DataComponents.CUSTOM_NAME, Component.literal(title)); book.set(DataComponents.CUSTOM_NAME, Component.literal(title));
return book; return book;
} }
@@ -1,8 +1,13 @@
package net.dnorberg.rivencraft.block.entity; package net.dnorberg.rivencraft.block.entity;
import java.util.Random;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.item.InkVialItem; import net.dnorberg.rivencraft.item.InkVialItem;
import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.writing.InkVialExchange; import net.dnorberg.rivencraft.writing.InkVialExchange;
import net.dnorberg.rivencraft.writing.InkModifierIngredients;
import net.dnorberg.rivencraft.registry.ModBlockEntities; import net.dnorberg.rivencraft.registry.ModBlockEntities;
import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.writing.WritingInkService; import net.dnorberg.rivencraft.writing.WritingInkService;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@@ -18,7 +23,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
/** Baseline Link Panel mixer. Modifier ingredients belong to the symbol/ink-effects milestone. */ /** Server-owned Link Panel mixer with a persistent, Legacy-style additive mixture. */
public final class InkMixerBlockEntity extends BlockEntity implements Container { public final class InkMixerBlockEntity extends BlockEntity implements Container {
public static final int INK = 0; public static final int INK = 0;
public static final int PAPER = 1; public static final int PAPER = 1;
@@ -27,6 +32,12 @@ public final class InkMixerBlockEntity extends BlockEntity implements Container
private NonNullList<ItemStack> items = NonNullList.withSize(SIZE, ItemStack.EMPTY); private NonNullList<ItemStack> items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
private int inkRemaining; private int inkRemaining;
private long nextModifierSeed = new Random().nextLong();
private final double[] modifierChances = new double[3];
private static final int[] FLAGS = {LinkProperties.DISARM,
LinkProperties.MAINTAIN_MOMENTUM, LinkProperties.INTRA_LINKING};
private static final String[] CHANCE_KEYS = {"DisarmChance", "MomentumChance", "IntraLinkingChance"};
private static final int[] OLD_CHANCE_INDEX = {0, 2, 3};
public InkMixerBlockEntity(BlockPos pos, BlockState state) { public InkMixerBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.INK_MIXER.get(), pos, state); super(ModBlockEntities.INK_MIXER.get(), pos, state);
@@ -34,6 +45,44 @@ public final class InkMixerBlockEntity extends BlockEntity implements Container
public int inkRemaining() { return inkRemaining; } public int inkRemaining() { return inkRemaining; }
public int modifierChancePermille(int index) {
return Math.clamp((int) Math.round(modifierChances[index] * 1000), 0, 1000);
}
/** Infuses a carried ingredient into the current ink pool; only the server calls this. */
public boolean addModifier(ItemStack carried, int amount) {
InkModifierIngredients.Ingredient ingredient = InkModifierIngredients.find(carried);
if (ingredient == null || inkRemaining == 0 || amount <= 0 || carried.getCount() < amount)
return false;
for (InkModifierIngredients.Effect effect : ingredient.effects())
for (int index = 0; index < FLAGS.length; index++)
if (FLAGS[index] == effect.flag())
modifierChances[index] = 1.0 - (1.0 - modifierChances[index])
* Math.pow(1.0 - effect.chance(), amount);
carried.shrink(amount);
setChanged();
return true;
}
public ItemStack previewLinkPanel() {
if (!canCreateLinkPanel()) return ItemStack.EMPTY;
ItemStack panel = PageItem.createLinkPanelPage();
LinkProperties properties = rollProperties(nextModifierSeed).properties();
if (properties.flags() != 0) panel.set(ModDataComponents.LINK_PROPERTIES.get(), properties);
return panel;
}
private record Roll(LinkProperties properties, long nextSeed) {}
private Roll rollProperties(long seed) {
Random random = new Random(seed);
int selected = 0;
for (int index = 0; index < FLAGS.length; index++)
if (modifierChances[index] > 0 && random.nextDouble() < modifierChances[index])
selected |= FLAGS[index];
return new Roll(new LinkProperties(selected), random.nextLong());
}
@Override public int getContainerSize() { return SIZE; } @Override public int getContainerSize() { return SIZE; }
@Override public boolean isEmpty() { return items.stream().allMatch(ItemStack::isEmpty); } @Override public boolean isEmpty() { return items.stream().allMatch(ItemStack::isEmpty); }
@Override public ItemStack getItem(int slot) { return items.get(slot); } @Override public ItemStack getItem(int slot) { return items.get(slot); }
@@ -92,6 +141,8 @@ public final class InkMixerBlockEntity extends BlockEntity implements Container
inkRemaining -= cost; inkRemaining -= cost;
items.get(PAPER).shrink(1); items.get(PAPER).shrink(1);
if (items.get(PAPER).isEmpty()) items.set(PAPER, ItemStack.EMPTY); if (items.get(PAPER).isEmpty()) items.set(PAPER, ItemStack.EMPTY);
nextModifierSeed = rollProperties(nextModifierSeed).nextSeed();
java.util.Arrays.fill(modifierChances, 0);
setChanged(); setChanged();
if (inkRemaining == 0) refillEmptyBasin(); if (inkRemaining == 0) refillEmptyBasin();
return true; return true;
@@ -104,6 +155,7 @@ public final class InkMixerBlockEntity extends BlockEntity implements Container
@Override public void clearContent() { @Override public void clearContent() {
items = NonNullList.withSize(SIZE, ItemStack.EMPTY); items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
inkRemaining = 0; inkRemaining = 0;
java.util.Arrays.fill(modifierChances, 0);
setChanged(); setChanged();
} }
@Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) { @Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
@@ -111,11 +163,20 @@ public final class InkMixerBlockEntity extends BlockEntity implements Container
items = NonNullList.withSize(SIZE, ItemStack.EMPTY); items = NonNullList.withSize(SIZE, ItemStack.EMPTY);
ContainerHelper.loadAllItems(tag, items, registries); ContainerHelper.loadAllItems(tag, items, registries);
inkRemaining = Math.clamp(tag.getInt("InkRemaining"), 0, InkVialItem.CAPACITY); inkRemaining = Math.clamp(tag.getInt("InkRemaining"), 0, InkVialItem.CAPACITY);
if (tag.contains("NextModifierSeed")) nextModifierSeed = tag.getLong("NextModifierSeed");
for (int index = 0; index < modifierChances.length; index++) {
double chance = tag.contains(CHANCE_KEYS[index]) ? tag.getDouble(CHANCE_KEYS[index])
: tag.getDouble("ModifierChance" + OLD_CHANCE_INDEX[index]);
modifierChances[index] = Math.clamp(chance, 0.0, 1.0);
}
refillEmptyBasin(); refillEmptyBasin();
} }
@Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { @Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
super.saveAdditional(tag, registries); super.saveAdditional(tag, registries);
ContainerHelper.saveAllItems(tag, items, registries); ContainerHelper.saveAllItems(tag, items, registries);
tag.putInt("InkRemaining", inkRemaining); tag.putInt("InkRemaining", inkRemaining);
tag.putLong("NextModifierSeed", nextModifierSeed);
for (int index = 0; index < modifierChances.length; index++)
tag.putDouble(CHANCE_KEYS[index], modifierChances[index]);
} }
} }
@@ -1,8 +1,12 @@
package net.dnorberg.rivencraft.block.entity; package net.dnorberg.rivencraft.block.entity;
import net.dnorberg.rivencraft.item.InkVialItem; import net.dnorberg.rivencraft.item.InkVialItem;
import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.writing.InkVialExchange; import net.dnorberg.rivencraft.writing.InkVialExchange;
import net.dnorberg.rivencraft.writing.WritingInkService; import net.dnorberg.rivencraft.writing.WritingInkService;
import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.writing.NotebookContents;
import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModBlockEntities; import net.dnorberg.rivencraft.registry.ModBlockEntities;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@@ -83,7 +87,11 @@ public final class WritingDeskBlockEntity extends BlockEntity implements Contain
worldPosition.getZ() + 0.5) <= 64.0; worldPosition.getZ() + 0.5) <= 64.0;
} }
@Override public boolean canPlaceItem(int slot, ItemStack stack) { @Override public boolean canPlaceItem(int slot, ItemStack stack) {
if (slot < COLLECTIONS) return stack.is(ModItems.NOTEBOOK.get()) || stack.is(ModItems.PAGE.get()); if (slot < COLLECTIONS) return stack.is(ModItems.NOTEBOOK.get())
&& stack.getOrDefault(ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY)
.pages().stream().noneMatch(page -> PageItem.content(page).kind() == PageContent.Kind.LINK_PANEL)
|| stack.is(ModItems.PAGE.get())
&& PageItem.content(stack).kind() != PageContent.Kind.LINK_PANEL;
return switch (slot) { return switch (slot) {
case INK -> stack.is(ModItems.INK_VIAL.get()); case INK -> stack.is(ModItems.INK_VIAL.get());
case RETURN -> false; case RETURN -> false;
@@ -0,0 +1,60 @@
package net.dnorberg.rivencraft.book;
import com.mojang.serialization.Codec;
import io.netty.buffer.ByteBuf;
import java.util.List;
import net.minecraft.ChatFormatting;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.chat.Component;
/** Flags written into a Link Panel and carried by books assembled from it. */
public record LinkProperties(int flags) {
public static final int DISARM = 1;
/** Retained only to read pre-0.4.7.1 test books; no longer generated or applied. */
public static final int GENERATE_PLATFORM = 2;
public static final int MAINTAIN_MOMENTUM = 4;
public static final int INTRA_LINKING = 8;
private static final int ALL_FLAGS = DISARM | GENERATE_PLATFORM | MAINTAIN_MOMENTUM | INTRA_LINKING;
public static final LinkProperties NONE = new LinkProperties(0);
public static final Codec<LinkProperties> CODEC = Codec.intRange(0, ALL_FLAGS).xmap(
LinkProperties::new, LinkProperties::flags);
public static final StreamCodec<ByteBuf, LinkProperties> STREAM_CODEC = StreamCodec.of(
(buffer, value) -> ByteBufCodecs.VAR_INT.encode(buffer, value.flags),
buffer -> new LinkProperties(ByteBufCodecs.VAR_INT.decode(buffer)));
public LinkProperties {
if ((flags & ~ALL_FLAGS) != 0 || flags < 0) {
throw new IllegalArgumentException("Unknown Link Panel flags: " + flags);
}
}
public boolean has(int flag) {
return (flags & flag) != 0;
}
/** Intra Linking only governs Linking Books; a Descriptive Book treats that panel as ordinary. */
public LinkProperties forDescriptiveBook() {
return new LinkProperties(flags & ~INTRA_LINKING);
}
public void appendTooltip(List<Component> lines) {
if (has(DISARM)) lines.add(propertyName("disarm"));
if (has(MAINTAIN_MOMENTUM)) lines.add(propertyName("maintain_momentum"));
if (has(INTRA_LINKING)) lines.add(propertyName("intra_linking"));
}
private static Component propertyName(String name) {
return Component.translatable("item.rivencraft.link_property." + name)
.withStyle(ChatFormatting.DARK_PURPLE);
}
public static Component name(int flag) {
return switch (flag) {
case DISARM -> propertyName("disarm");
case MAINTAIN_MOMENTUM -> propertyName("maintain_momentum");
case INTRA_LINKING -> propertyName("intra_linking");
default -> throw new IllegalArgumentException("Unknown link property flag: " + flag);
};
}
}
@@ -25,7 +25,11 @@ public final class LinkingService {
} }
public static LinkResult travel(ServerPlayer player, LinkTarget target) { public static LinkResult travel(ServerPlayer player, LinkTarget target) {
return travel(player, target, false); return travel(player, target, LinkProperties.NONE);
}
public static LinkResult travel(ServerPlayer player, LinkTarget target, LinkProperties properties) {
return travel(player, target, false, properties);
} }
public static Optional<Vec3> resolveDestination(ServerLevel level, BlockPos origin, boolean ageArrival) { public static Optional<Vec3> resolveDestination(ServerLevel level, BlockPos origin, boolean ageArrival) {
@@ -36,27 +40,36 @@ public final class LinkingService {
/** Travels to an Age-style destination, which must have solid footing. */ /** Travels to an Age-style destination, which must have solid footing. */
public static LinkResult travelWithFooting(ServerPlayer player, LinkTarget target) { public static LinkResult travelWithFooting(ServerPlayer player, LinkTarget target) {
return travelWithFooting(player, target, LinkProperties.NONE);
}
public static LinkResult travelWithFooting(ServerPlayer player, LinkTarget target, LinkProperties properties) {
ServerLevel destinationLevel = player.getServer().getLevel(target.location().dimension()); ServerLevel destinationLevel = player.getServer().getLevel(target.location().dimension());
if (destinationLevel == null) { if (destinationLevel == null) {
return LinkResult.MISSING_DIMENSION; return LinkResult.MISSING_DIMENSION;
} }
Optional<Vec3> destination = resolveDestination(destinationLevel, target.location().pos(), true); Optional<Vec3> destination = resolveDestination(destinationLevel, target.location().pos(), true);
if (destination.isEmpty()) { if (destination.isEmpty()) {
return LinkResult.NO_SAFE_DESTINATION; return LinkResult.NO_SAFE_DESTINATION;
} }
Vec3 position = destination.get(); Vec3 position = destination.get();
Vec3 momentum = player.getDeltaMovement();
if (properties.has(LinkProperties.DISARM)) dropInventoryAtSource(player);
teleport(player, destinationLevel, position, target); teleport(player, destinationLevel, position, target);
if (properties.has(LinkProperties.MAINTAIN_MOMENTUM)) player.setDeltaMovement(momentum);
player.resetFallDistance(); player.resetFallDistance();
return LinkResult.SUCCESS; return LinkResult.SUCCESS;
} }
private static LinkResult travel(ServerPlayer player, LinkTarget target, boolean requiresFooting) { private static LinkResult travel(ServerPlayer player, LinkTarget target, boolean requiresFooting,
LinkProperties properties) {
ServerLevel destinationLevel = player.getServer().getLevel(target.location().dimension()); ServerLevel destinationLevel = player.getServer().getLevel(target.location().dimension());
if (destinationLevel == null) { if (destinationLevel == null) {
return LinkResult.MISSING_DIMENSION; return LinkResult.MISSING_DIMENSION;
} }
if (destinationLevel == player.level() && !properties.has(LinkProperties.INTRA_LINKING))
return LinkResult.INTRA_LINKING_REQUIRED;
Optional<Vec3> destination = resolveDestination(destinationLevel, target.location().pos(), requiresFooting); Optional<Vec3> destination = resolveDestination(destinationLevel, target.location().pos(), requiresFooting);
if (destination.isEmpty()) { if (destination.isEmpty()) {
@@ -64,11 +77,26 @@ public final class LinkingService {
} }
Vec3 position = destination.get(); Vec3 position = destination.get();
Vec3 momentum = player.getDeltaMovement();
if (properties.has(LinkProperties.DISARM)) dropInventoryAtSource(player);
teleport(player, destinationLevel, position, target); teleport(player, destinationLevel, position, target);
if (properties.has(LinkProperties.MAINTAIN_MOMENTUM)) player.setDeltaMovement(momentum);
player.resetFallDistance(); player.resetFallDistance();
return LinkResult.SUCCESS; return LinkResult.SUCCESS;
} }
/** Drop each inventory stack as an item entity at the departure point. */
private static void dropInventoryAtSource(ServerPlayer player) {
var inventory = player.getInventory();
for (int slot = 0; slot < inventory.getContainerSize(); slot++) {
var stack = inventory.getItem(slot);
if (stack.isEmpty()) continue;
inventory.setItem(slot, net.minecraft.world.item.ItemStack.EMPTY);
player.drop(stack, false);
}
player.containerMenu.broadcastChanges();
}
private static void teleport( private static void teleport(
ServerPlayer player, ServerPlayer player,
ServerLevel destinationLevel, ServerLevel destinationLevel,
@@ -166,6 +194,7 @@ public final class LinkingService {
public enum LinkResult { public enum LinkResult {
SUCCESS, SUCCESS,
MISSING_DIMENSION, MISSING_DIMENSION,
INTRA_LINKING_REQUIRED,
NO_SAFE_DESTINATION NO_SAFE_DESTINATION
} }
} }
@@ -8,11 +8,20 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ClickType;
/** Legacy Ink Mixer atlas with a server-synced, sixteen-use basin. */ /** Legacy Ink Mixer atlas with a server-synced, sixteen-use basin. */
public final class InkMixerScreen extends AbstractContainerScreen<InkMixerMenu> { public final class InkMixerScreen extends AbstractContainerScreen<InkMixerMenu> {
private static final ResourceLocation BACKGROUND = ResourceLocation.fromNamespaceAndPath( private static final ResourceLocation BACKGROUND = ResourceLocation.fromNamespaceAndPath(
Rivencraft.MOD_ID, "textures/gui/ink_mixer_legacy.png"); Rivencraft.MOD_ID, "textures/gui/ink_mixer_legacy.png");
private static final int BASIN_X = 88;
private static final int BASIN_Y = 49;
private static final int BASIN_RADIUS = 30;
// Legacy's registered property colors: Disarm red, Momentum blue, Intra green.
private static final int[] PROPERTY_COLORS = {0xFFE84848, 0xFF5555FF, 0xFF55EF55};
private final int[] lastChances = new int[3];
private boolean basinClickPendingRelease;
private long lastAdditionTime;
public InkMixerScreen(InkMixerMenu menu, Inventory inventory, Component title) { public InkMixerScreen(InkMixerMenu menu, Inventory inventory, Component title) {
super(menu, inventory, title); super(menu, inventory, title);
@@ -26,16 +35,14 @@ public final class InkMixerScreen extends AbstractContainerScreen<InkMixerMenu>
renderBg(graphics, partialTick, mouseX, mouseY); renderBg(graphics, partialTick, mouseX, mouseY);
} }
@Override protected void renderBg(GuiGraphics graphics, float partialTick, int mouseX, int mouseY) { @Override protected void renderBg(GuiGraphics graphics, float partialTick, int mouseX, int mouseY) {
graphics.blit(BACKGROUND, leftPos, topPos, 0, 0, imageWidth, imageHeight, 256, 256); // Legacy draws this inset behind the transparent center of the main atlas.
int centerX = leftPos + 88; graphics.blit(BACKGROUND, leftPos + 54, topPos + 16, 179, 16, 66, 65, 256, 256);
int centerY = topPos + 49;
int fillTop = centerY + 26 - Math.round(menu.inkRemaining() / (float) InkVialItem.CAPACITY * 52);
if (menu.inkRemaining() > 0) { if (menu.inkRemaining() > 0) {
for (int y = Math.max(centerY - 26, fillTop); y <= centerY + 26; y++) { // Ink is a full dark basin in Legacy, rather than a vertical meter.
int halfWidth = (int) Math.sqrt(26 * 26 - (y - centerY) * (y - centerY)); graphics.fill(leftPos + 54, topPos + 16, leftPos + 120, topPos + 81, 0xFF101014);
graphics.fill(centerX - halfWidth, y, centerX + halfWidth + 1, y + 1, 0xFF241228); renderPropertyGlyph(graphics);
}
} }
graphics.blit(BACKGROUND, leftPos, topPos, 0, 0, imageWidth, imageHeight, 256, 256);
} }
@Override protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) { @Override protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
graphics.drawString(font, playerInventoryTitle, inventoryLabelX, inventoryLabelY, 0x404040, false); graphics.drawString(font, playerInventoryTitle, inventoryLabelX, inventoryLabelY, 0x404040, false);
@@ -43,10 +50,112 @@ public final class InkMixerScreen extends AbstractContainerScreen<InkMixerMenu>
@Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) { @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
super.render(graphics, mouseX, mouseY, partialTick); super.render(graphics, mouseX, mouseY, partialTick);
renderTooltip(graphics, mouseX, mouseY); renderTooltip(graphics, mouseX, mouseY);
int x = mouseX - (leftPos + 88); if (overBasin(mouseX, mouseY)) {
int y = mouseY - (topPos + 49); var lines = new java.util.ArrayList<Component>();
if (x * x + y * y <= 26 * 26) lines.add(Component.translatable("screen.rivencraft.ink_mixer.ink",
graphics.renderTooltip(font, Component.translatable("screen.rivencraft.ink_mixer.ink", menu.inkRemaining(), InkVialItem.CAPACITY));
menu.inkRemaining(), InkVialItem.CAPACITY), mouseX, mouseY); lines.add(Component.translatable("screen.rivencraft.ink_mixer.additive_hint"));
for (int index = 0; index < 3; index++) {
int chance = menu.modifierChancePermille(index);
if (chance > 0) lines.add(Component.translatable("screen.rivencraft.ink_mixer.chance",
switch (index) {
case 0 -> Component.translatable("item.rivencraft.link_property.disarm");
case 1 -> Component.translatable("item.rivencraft.link_property.maintain_momentum");
default -> Component.translatable("item.rivencraft.link_property.intra_linking");
}, chance / 10.0));
}
graphics.renderTooltip(font, lines, java.util.Optional.empty(), mouseX, mouseY);
}
}
@Override public boolean mouseClicked(double mouseX, double mouseY, int button) {
if ((button == 0 || button == 1) && overBasin(mouseX, mouseY)
&& !menu.getCarried().isEmpty()) {
slotClicked(menu.getSlot(InkMixerMenu.MODIFIER), InkMixerMenu.MODIFIER, button, ClickType.PICKUP);
basinClickPendingRelease = true;
return true;
}
return super.mouseClicked(mouseX, mouseY, button);
}
@Override public boolean mouseReleased(double mouseX, double mouseY, int button) {
if (basinClickPendingRelease) {
basinClickPendingRelease = false;
return true;
}
return super.mouseReleased(mouseX, mouseY, button);
}
private boolean overBasin(double mouseX, double mouseY) {
double x = mouseX - leftPos - BASIN_X;
double y = mouseY - topPos - BASIN_Y;
return x * x + y * y < BASIN_RADIUS * BASIN_RADIUS;
}
/** A GUI-scale projection of Legacy's colored, rotating D'ni ink effect. */
private void renderPropertyGlyph(GuiGraphics graphics) {
long now = System.currentTimeMillis();
int[] active = new int[3];
int count = 0;
int strongest = 0;
for (int index = 0; index < lastChances.length; index++) {
int chance = menu.modifierChancePermille(index);
if (chance > lastChances[index]) lastAdditionTime = now;
lastChances[index] = chance;
if (chance > 0) {
active[count++] = index;
strongest = Math.max(strongest, chance);
}
}
if (count == 0) {
lastAdditionTime = 0;
return;
}
double cycle = now / 1800.0;
int first = active[(int) cycle % count];
int second = active[((int) cycle + 1) % count];
double blend = (1.0 - Math.cos((cycle % 1.0) * Math.PI)) / 2.0;
int rgb = blendRgb(PROPERTY_COLORS[first], PROPERTY_COLORS[second], blend);
double pulse = Math.max(0.0, 1.0 - (now - lastAdditionTime) / 700.0);
int alpha = Math.clamp((int) (70 + strongest * 0.14 + pulse * 45), 0, 255);
int color = alpha << 24 | rgb;
int centerX = leftPos + BASIN_X;
int centerY = topPos + BASIN_Y;
double turn = now / 1200.0;
for (int spoke = 0; spoke < 4; spoke++) {
for (int step = 0; step <= 30; step++) {
double progress = step / 30.0;
double angle = turn + spoke * Math.PI / 2.0 + progress * 0.9;
double radius = 3.0 + progress * (15.0 + pulse * 3.0);
plot(graphics, centerX + Math.cos(angle) * radius,
centerY + Math.sin(angle) * radius, color);
}
}
for (int step = 0; step < 96; step++) {
double angle = step * Math.PI / 48.0 + turn * 0.3;
plot(graphics, centerX + Math.cos(angle) * 19.0,
centerY + Math.sin(angle) * 19.0, color);
if (strongest >= 990 && step % 2 == 0) {
plot(graphics, centerX + Math.cos(angle) * 23.0,
centerY + Math.sin(angle) * 23.0, color);
}
}
}
private static int blendRgb(int first, int second, double amount) {
int red = (int) (((first >> 16) & 0xFF) * (1.0 - amount)
+ ((second >> 16) & 0xFF) * amount);
int green = (int) (((first >> 8) & 0xFF) * (1.0 - amount)
+ ((second >> 8) & 0xFF) * amount);
int blue = (int) ((first & 0xFF) * (1.0 - amount) + (second & 0xFF) * amount);
return red << 16 | green << 8 | blue;
}
private static void plot(GuiGraphics graphics, double x, double y, int color) {
int pixelX = (int) Math.round(x);
int pixelY = (int) Math.round(y);
graphics.fill(pixelX, pixelY, pixelX + 1, pixelY + 1, color);
} }
} }
@@ -6,6 +6,7 @@ import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.client.SymbolPageTextures; import net.dnorberg.rivencraft.client.SymbolPageTextures;
import net.dnorberg.rivencraft.menu.NotebookMenu; import net.dnorberg.rivencraft.menu.NotebookMenu;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.writing.PageContent;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.EditBox;
@@ -115,7 +116,8 @@ public final class NotebookScreen extends AbstractContainerScreen<NotebookMenu>
if (index >= 0 && (button == 0 || button == 1)) { if (index >= 0 && (button == 0 || button == 1)) {
ItemStack page = menu.getSlot(index).getItem(); ItemStack page = menu.getSlot(index).getItem();
if ((!page.isEmpty() && !matchesSearch(page)) if ((!page.isEmpty() && !matchesSearch(page))
|| (page.isEmpty() && !menu.getCarried().is(ModItems.PAGE.get()))) { || (page.isEmpty() && (!menu.getCarried().is(ModItems.PAGE.get())
|| PageItem.content(menu.getCarried()).kind() == PageContent.Kind.LINK_PANEL))) {
return true; return true;
} }
setFocused(null); setFocused(null);
@@ -7,6 +7,7 @@ import java.util.Comparator;
import net.dnorberg.rivencraft.Rivencraft; import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.client.SymbolPageTextures; import net.dnorberg.rivencraft.client.SymbolPageTextures;
import net.dnorberg.rivencraft.item.PageItem; import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.menu.WritingDeskMenu; import net.dnorberg.rivencraft.menu.WritingDeskMenu;
import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity; import net.dnorberg.rivencraft.block.entity.WritingDeskBlockEntity;
import net.dnorberg.rivencraft.registry.ModDataComponents; import net.dnorberg.rivencraft.registry.ModDataComponents;
@@ -329,7 +330,9 @@ public final class WritingDeskScreen extends AbstractContainerScreen<WritingDesk
int surfaceY = (int) Math.floor(mouseY - topPos - 20); int surfaceY = (int) Math.floor(mouseY - topPos - 20);
if ((button == 0 || button == 1) && !menu.getCarried().isEmpty() if ((button == 0 || button == 1) && !menu.getCarried().isEmpty()
&& surfaceX >= 0 && surfaceX < 155 && surfaceY >= 0 && surfaceY < 164) { && surfaceX >= 0 && surfaceX < 155 && surfaceY >= 0 && surfaceY < 164) {
if (menu.getCarried().is(ModItems.PAGE.get()) && surfaceX % 31 < 30 && surfaceY % 41 < 40) { if (menu.getCarried().is(ModItems.PAGE.get())
&& PageItem.content(menu.getCarried()).kind() != PageContent.Kind.LINK_PANEL
&& surfaceX % 31 < 30 && surfaceY % 41 < 40) {
int index = (surfaceY / 41 + scrollRows) * 5 + surfaceX / 31; int index = (surfaceY / 41 + scrollRows) * 5 + surfaceX / 31;
List<DisplayPage> entries = filteredPages(); List<DisplayPage> entries = filteredPages();
// Only displayed positions are addressable. Filtering never turns // Only displayed positions are addressable. Filtering never turns
@@ -23,11 +23,16 @@ import mezz.jei.api.ingredients.subtypes.UidContext;
import mezz.jei.api.runtime.IJeiRuntime; import mezz.jei.api.runtime.IJeiRuntime;
import net.dnorberg.rivencraft.Rivencraft; import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.item.PageItem; import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.writing.InkModifierIngredients;
import net.dnorberg.rivencraft.writing.PageContent; import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.writing.SymbolReference;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
@@ -52,7 +57,8 @@ public final class RivencraftJeiPlugin implements IModPlugin {
PageContent content = PageItem.content(stack); PageContent content = PageItem.content(stack);
return switch (content.kind()) { return switch (content.kind()) {
case BLANK -> "blank"; case BLANK -> "blank";
case LINK_PANEL -> "link_panel"; case LINK_PANEL -> "link_panel:" + stack.getOrDefault(
ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE).flags();
case SYMBOL -> "symbol:" + content.symbol().orElseThrow().id(); case SYMBOL -> "symbol:" + content.symbol().orElseThrow().id();
case UNRESOLVED_SYMBOL -> "unresolved:" + content.symbol().orElseThrow().id(); case UNRESOLVED_SYMBOL -> "unresolved:" + content.symbol().orElseThrow().id();
}; };
@@ -103,17 +109,23 @@ public final class RivencraftJeiPlugin implements IModPlugin {
@Override @Override
public void registerRecipes(IRecipeRegistration registration) { public void registerRecipes(IRecipeRegistration registration) {
ItemStack panel = PageItem.createLinkPanelPage(); ItemStack panel = PageItem.createLinkPanelPage();
ItemStack symbolPage = PageItem.createSymbolPage(new SymbolReference(
ResourceLocation.fromNamespaceAndPath(Rivencraft.MOD_ID, "terrain/standard")));
registration.addRecipes(WRITING, List.of( registration.addRecipes(WRITING, List.of(
new WritingGuide(List.of(new ItemStack(Items.PAPER), new ItemStack(ModItems.INK_VIAL.get())), new WritingGuide(List.of(new ItemStack(Items.PAPER), new ItemStack(ModItems.INK_VIAL.get())),
panel, "jei.rivencraft.writing.link_panel_hand"), panel, "jei.rivencraft.writing.link_panel_hand"),
new WritingGuide(List.of(panel, new ItemStack(Items.PAPER), new ItemStack(ModItems.INK_VIAL.get())), new WritingGuide(List.of(symbolPage, new ItemStack(Items.PAPER), new ItemStack(ModItems.INK_VIAL.get())),
panel, "jei.rivencraft.writing.copy"), symbolPage, "jei.rivencraft.writing.copy"),
new WritingGuide(List.of(new ItemStack(Items.LEATHER), panel), new WritingGuide(List.of(new ItemStack(Items.LEATHER), panel),
new ItemStack(ModItems.DESCRIPTIVE_BOOK.get()), "jei.rivencraft.writing.bind"), new ItemStack(ModItems.DESCRIPTIVE_BOOK.get()), "jei.rivencraft.writing.bind"),
new WritingGuide(List.of(panel, new ItemStack(Items.LEATHER)), new WritingGuide(List.of(panel, new ItemStack(Items.LEATHER)),
new ItemStack(ModItems.LINKING_BOOK.get()), "jei.rivencraft.writing.linking_book") new ItemStack(ModItems.LINKING_BOOK.get()), "jei.rivencraft.writing.linking_book")
)); ));
registration.addRecipes(INK_MIXER, List.of(new InkMixerGuide(panel))); List<InkMixerGuide> mixerGuides = new ArrayList<>();
mixerGuides.add(new InkMixerGuide(panel, null));
InkModifierIngredients.builtIn().forEach(ingredient ->
mixerGuides.add(new InkMixerGuide(panel, ingredient)));
registration.addRecipes(INK_MIXER, mixerGuides);
} }
@Override @Override
@@ -124,7 +136,7 @@ public final class RivencraftJeiPlugin implements IModPlugin {
} }
private record WritingGuide(List<ItemStack> inputs, ItemStack output, String instructionKey) {} private record WritingGuide(List<ItemStack> inputs, ItemStack output, String instructionKey) {}
private record InkMixerGuide(ItemStack panel) {} private record InkMixerGuide(ItemStack panel, InkModifierIngredients.Ingredient additive) {}
private static final class InkMixerCategory extends AbstractRecipeCategory<InkMixerGuide> { private static final class InkMixerCategory extends AbstractRecipeCategory<InkMixerGuide> {
InkMixerCategory(IGuiHelper guiHelper) { InkMixerCategory(IGuiHelper guiHelper) {
@@ -138,6 +150,9 @@ public final class RivencraftJeiPlugin implements IModPlugin {
builder.addInputSlot(2, 3).setStandardSlotBackground().addItemStack(new ItemStack(Items.PAPER)); builder.addInputSlot(2, 3).setStandardSlotBackground().addItemStack(new ItemStack(Items.PAPER));
builder.addInputSlot(23, 3).setStandardSlotBackground() builder.addInputSlot(23, 3).setStandardSlotBackground()
.addItemStack(new ItemStack(ModItems.INK_VIAL.get())); .addItemStack(new ItemStack(ModItems.INK_VIAL.get()));
if (recipe.additive() != null)
builder.addInputSlot(44, 3).setStandardSlotBackground()
.addItemStack(recipe.additive().item());
builder.addOutputSlot(112, 3).setOutputSlotBackground().addItemStack(recipe.panel()); builder.addOutputSlot(112, 3).setOutputSlotBackground().addItemStack(recipe.panel());
builder.addOutputSlot(112, 46).setStandardSlotBackground() builder.addOutputSlot(112, 46).setStandardSlotBackground()
.addItemStack(new ItemStack(Items.GLASS_BOTTLE)); .addItemStack(new ItemStack(Items.GLASS_BOTTLE));
@@ -146,8 +161,20 @@ public final class RivencraftJeiPlugin implements IModPlugin {
@Override @Override
public void draw(InkMixerGuide recipe, IRecipeSlotsView slots, GuiGraphics graphics, public void draw(InkMixerGuide recipe, IRecipeSlotsView slots, GuiGraphics graphics,
double mouseX, double mouseY) { double mouseX, double mouseY) {
graphics.drawWordWrap(Minecraft.getInstance().font, Component instructions = recipe.additive() == null
Component.translatable("jei.rivencraft.ink_mixer.usage"), 2, 27, 104, 0x404040); ? Component.translatable("jei.rivencraft.ink_mixer.usage")
: additiveInstructions(recipe.additive());
graphics.drawWordWrap(Minecraft.getInstance().font, instructions, 2, 27, 104, 0x404040);
}
private static Component additiveInstructions(InkModifierIngredients.Ingredient additive) {
MutableComponent effects = Component.empty();
for (InkModifierIngredients.Effect effect : additive.effects()) {
if (!effects.getSiblings().isEmpty()) effects.append(", ");
effects.append(Component.translatable("jei.rivencraft.ink_mixer.effect",
LinkProperties.name(effect.flag()), Math.round(effect.chance() * 100)));
}
return Component.translatable("jei.rivencraft.ink_mixer.additive", effects);
} }
} }
@@ -6,6 +6,9 @@ import net.dnorberg.rivencraft.block.entity.BookBinderBlockEntity;
import net.dnorberg.rivencraft.book.AgeReference; import net.dnorberg.rivencraft.book.AgeReference;
import net.dnorberg.rivencraft.book.AgeDimensionService; import net.dnorberg.rivencraft.book.AgeDimensionService;
import net.dnorberg.rivencraft.book.AgeRegistrySavedData; import net.dnorberg.rivencraft.book.AgeRegistrySavedData;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.book.LinkTarget;
import net.dnorberg.rivencraft.book.LinkingService;
import net.dnorberg.rivencraft.item.PageItem; import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.menu.BookBinderMenu; import net.dnorberg.rivencraft.menu.BookBinderMenu;
import net.dnorberg.rivencraft.registry.ModBlocks; import net.dnorberg.rivencraft.registry.ModBlocks;
@@ -17,6 +20,7 @@ import net.dnorberg.rivencraft.writing.SymbolReference;
import net.dnorberg.rivencraft.writing.SymbolCatalog; import net.dnorberg.rivencraft.writing.SymbolCatalog;
import net.dnorberg.rivencraft.writing.WritingEntry; import net.dnorberg.rivencraft.writing.WritingEntry;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.gametest.framework.GameTest; import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -133,7 +137,14 @@ public final class BookBinderGameTests {
helper.assertFalse(binder.consumeAssembly(), "Failure must consume nothing"); helper.assertFalse(binder.consumeAssembly(), "Failure must consume nothing");
helper.assertTrue(binder.getItem(BookBinderBlockEntity.COVER).is(Items.LEATHER), helper.assertTrue(binder.getItem(BookBinderBlockEntity.COVER).is(Items.LEATHER),
"Rejected assembly must preserve cover"); "Rejected assembly must preserve cover");
binder.setItem(BookBinderBlockEntity.LINK_PANEL, PageItem.createLinkPanelPage()); ItemStack flavoredPanel = PageItem.createLinkPanelPage();
flavoredPanel.set(ModDataComponents.LINK_PROPERTIES.get(),
new net.dnorberg.rivencraft.book.LinkProperties(
net.dnorberg.rivencraft.book.LinkProperties.DISARM
| net.dnorberg.rivencraft.book.LinkProperties.MAINTAIN_MOMENTUM
| net.dnorberg.rivencraft.book.LinkProperties.INTRA_LINKING));
var expectedProperties = flavoredPanel.get(ModDataComponents.LINK_PROPERTIES.get()).forDescriptiveBook();
binder.setItem(BookBinderBlockEntity.LINK_PANEL, flavoredPanel);
var player = helper.makeMockServerPlayerInLevel(); var player = helper.makeMockServerPlayerInLevel();
player.moveTo(binder.getBlockPos().getX() + 0.5, binder.getBlockPos().getY() + 0.5, player.moveTo(binder.getBlockPos().getX() + 0.5, binder.getBlockPos().getY() + 0.5,
binder.getBlockPos().getZ() + 0.5); binder.getBlockPos().getZ() + 0.5);
@@ -143,6 +154,9 @@ public final class BookBinderGameTests {
menu.clicked(BookBinderMenu.RESULT, 0, ClickType.PICKUP, player); menu.clicked(BookBinderMenu.RESULT, 0, ClickType.PICKUP, player);
ItemStack book = menu.getCarried(); ItemStack book = menu.getCarried();
helper.assertTrue(book.is(ModItems.DESCRIPTIVE_BOOK.get()), "Result must be a Descriptive Book"); helper.assertTrue(book.is(ModItems.DESCRIPTIVE_BOOK.get()), "Result must be a Descriptive Book");
helper.assertValueEqual(book.get(ModDataComponents.LINK_PROPERTIES.get()),
expectedProperties,
"Binder must retain Disarm and Momentum but omit Intra Linking");
AgeReference age = book.get(ModDataComponents.AGE_REFERENCE.get()); AgeReference age = book.get(ModDataComponents.AGE_REFERENCE.get());
helper.assertTrue(age != null, "Assembled book must already be a written Age book"); helper.assertTrue(age != null, "Assembled book must already be a written Age book");
OrderedWriting writing = book.get(ModDataComponents.BOOK_WRITING.get()); OrderedWriting writing = book.get(ModDataComponents.BOOK_WRITING.get());
@@ -175,6 +189,50 @@ public final class BookBinderGameTests {
helper.succeed(); helper.succeed();
} }
public static void panelOnlyBookRetainsApplicableModifiers(GameTestHelper helper) {
BookBinderBlockEntity binder = place(helper);
binder.setTitle("Modified Random Age");
binder.setItem(BookBinderBlockEntity.COVER, new ItemStack(Items.LEATHER));
ItemStack panel = PageItem.createLinkPanelPage();
panel.set(ModDataComponents.LINK_PROPERTIES.get(), new LinkProperties(
LinkProperties.DISARM | LinkProperties.MAINTAIN_MOMENTUM | LinkProperties.INTRA_LINKING));
var player = helper.makeMockServerPlayerInLevel();
player.moveTo(binder.getBlockPos().getX() + 0.5, binder.getBlockPos().getY() + 0.5,
binder.getBlockPos().getZ() + 0.5);
BookBinderMenu menu = new BookBinderMenu(1, player.getInventory(), binder);
menu.setCarried(panel);
helper.assertTrue(menu.clickMenuButton(player, BookBinderMenu.STRIP_CLICK_BASE),
"The link strip must accept the modified panel without symbol pages");
ItemStack result = menu.quickMoveStack(player, BookBinderMenu.RESULT);
helper.assertTrue(result.is(ModItems.DESCRIPTIVE_BOOK.get()),
"A Link Panel alone must create a random-Age Descriptive Book");
LinkProperties expected = new LinkProperties(LinkProperties.DISARM | LinkProperties.MAINTAIN_MOMENTUM);
helper.assertValueEqual(result.get(ModDataComponents.LINK_PROPERTIES.get()), expected,
"The panel-only book must keep travel modifiers but omit Intra Linking");
ItemStack restored = ItemStack.parseOptional(helper.getLevel().registryAccess(),
(net.minecraft.nbt.CompoundTag) result.saveOptional(helper.getLevel().registryAccess()));
helper.assertValueEqual(restored.get(ModDataComponents.LINK_PROPERTIES.get()), expected,
"Panel-only book modifiers must survive save and reload");
BlockPos departure = player.blockPosition();
BlockPos destination = departure.offset(3, 0, 0);
helper.getLevel().setBlock(destination.below(), Blocks.STONE.defaultBlockState(), 3);
helper.getLevel().setBlock(destination, Blocks.AIR.defaultBlockState(), 3);
helper.getLevel().setBlock(destination.above(), Blocks.AIR.defaultBlockState(), 3);
player.getInventory().setItem(4, new ItemStack(Items.DIAMOND, 3));
LinkTarget target = new LinkTarget(GlobalPos.of(helper.getLevel().dimension(), destination), 0.0F, 0.0F);
helper.assertValueEqual(LinkingService.travelWithFooting(player, target,
restored.get(ModDataComponents.LINK_PROPERTIES.get()).forDescriptiveBook()),
LinkingService.LinkResult.SUCCESS,
"The panel-only book's properties must be accepted by grounded travel");
helper.assertTrue(player.getInventory().getItem(4).isEmpty(),
"Disarm must remove the carried items during panel-only book travel");
helper.assertTrue(helper.getLevel().getEntitiesOfClass(ItemEntity.class,
new AABB(departure).inflate(5.0), entity -> entity.getItem().is(Items.DIAMOND))
.stream().mapToInt(entity -> entity.getItem().getCount()).sum() >= 3,
"Disarm must drop the items at the departure location");
helper.succeed();
}
@GameTest(template = "empty") @GameTest(template = "empty")
public static void linkPanelOnlyCreatesCompletedRandomAgeBook(GameTestHelper helper) { public static void linkPanelOnlyCreatesCompletedRandomAgeBook(GameTestHelper helper) {
BookBinderBlockEntity binder = place(helper); BookBinderBlockEntity binder = place(helper);
@@ -87,6 +87,11 @@ public final class CoreGameTests {
BookBinderGameTests.assemblyIsAtomicAndRetainsPageOrder(helper); BookBinderGameTests.assemblyIsAtomicAndRetainsPageOrder(helper);
} }
@GameTest(template = "empty")
public static void panelOnlyBookModifiers(GameTestHelper helper) {
BookBinderGameTests.panelOnlyBookRetainsApplicableModifiers(helper);
}
@GameTest(template = "empty") @GameTest(template = "empty")
public static void binderRejectsConflictingGrammar(GameTestHelper helper) { public static void binderRejectsConflictingGrammar(GameTestHelper helper) {
BookBinderGameTests.conflictingGrammarKeepsBinderInputsRecoverable(helper); BookBinderGameTests.conflictingGrammarKeepsBinderInputsRecoverable(helper);
@@ -102,6 +107,11 @@ public final class CoreGameTests {
InkMixerGameTests.linkPanelRequiresTakingOutputAndPersistsInk(helper); InkMixerGameTests.linkPanelRequiresTakingOutputAndPersistsInk(helper);
} }
@GameTest(template = "empty")
public static void mixerModifierTransaction(GameTestHelper helper) {
InkMixerGameTests.modifierClickPersistsPreviewAndConsumesOnce(helper);
}
@GameTest(template = "empty") @GameTest(template = "empty")
public static void linkingBookRecipe(GameTestHelper helper) { public static void linkingBookRecipe(GameTestHelper helper) {
LinkingBookRecipeGameTests.legacyRecipeRequiresExactlyLeatherAndLinkPanel(helper); LinkingBookRecipeGameTests.legacyRecipeRequiresExactlyLeatherAndLinkPanel(helper);
@@ -28,6 +28,69 @@ public final class InkMixerGameTests {
return (InkMixerBlockEntity) helper.getLevel().getBlockEntity(pos); return (InkMixerBlockEntity) helper.getLevel().getBlockEntity(pos);
} }
public static void modifierClickPersistsPreviewAndConsumesOnce(GameTestHelper helper) {
InkMixerBlockEntity mixer = place(helper);
mixer.setItem(InkMixerBlockEntity.PAPER, new ItemStack(Items.PAPER, 2));
mixer.setItem(InkMixerBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
var player = helper.makeMockServerPlayerInLevel();
player.moveTo(mixer.getBlockPos().getX() + 0.5, mixer.getBlockPos().getY() + 0.5,
mixer.getBlockPos().getZ() + 0.5);
InkMixerMenu menu = new InkMixerMenu(1, player.getInventory(), mixer);
menu.setCarried(new ItemStack(Items.GUNPOWDER, 2));
menu.clicked(InkMixerMenu.MODIFIER, 1, ClickType.PICKUP, player);
helper.assertValueEqual(menu.getCarried().getCount(), 1, "Right click must consume one additive");
helper.assertValueEqual(mixer.modifierChancePermille(0), 200,
"Gunpowder must add Legacy's 20% Disarm chance");
menu.setCarried(new ItemStack(Items.STONE));
menu.clicked(InkMixerMenu.MODIFIER, 0, ClickType.PICKUP, player);
helper.assertValueEqual(menu.getCarried().getCount(), 1, "Invalid additive must remain carried");
helper.assertValueEqual(mixer.modifierChancePermille(0), 200,
"Invalid additive must not change the mixture");
ItemStack preview = mixer.previewLinkPanel();
var saved = mixer.saveWithoutMetadata(helper.getLevel().registryAccess());
var restored = new InkMixerBlockEntity(mixer.getBlockPos(), ModBlocks.INK_MIXER.get().defaultBlockState());
restored.loadWithComponents(saved, helper.getLevel().registryAccess());
helper.assertTrue(ItemStack.matches(preview, restored.previewLinkPanel()),
"Saving must retain the mixture and deterministic next-panel preview");
menu.setCarried(ItemStack.EMPTY);
menu.clicked(InkMixerMenu.RESULT, 0, ClickType.PICKUP, player);
helper.assertTrue(menu.getCarried().is(ModItems.PAGE.get()), "Taking result must give a panel");
helper.assertValueEqual(mixer.modifierChancePermille(0), 0,
"Mixture must be spent only when a panel is taken");
helper.assertValueEqual(mixer.getItem(InkMixerBlockEntity.PAPER).getCount(), 1,
"Taking the panel must consume exactly one paper");
helper.succeed();
}
@GameTest(template = "empty")
public static void enderPearlsRaiseBothPropertiesIndependentlyAndResetOnOutput(GameTestHelper helper) {
InkMixerBlockEntity mixer = place(helper);
mixer.setItem(InkMixerBlockEntity.PAPER, new ItemStack(Items.PAPER, 2));
mixer.setItem(InkMixerBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
ItemStack pearls = new ItemStack(Items.ENDER_PEARL, 20);
helper.assertTrue(mixer.addModifier(pearls, 20), "Ender Pearls must infuse the basin");
helper.assertTrue(pearls.isEmpty(), "Twenty pearls must be consumed exactly once");
helper.assertValueEqual(mixer.modifierChancePermille(0), 961,
"Disarm must approach 100% independently");
helper.assertValueEqual(mixer.modifierChancePermille(2), 961,
"Intra Linking must approach 100% independently");
helper.assertValueEqual(mixer.modifierChancePermille(1), 0,
"Ender Pearls must not add Momentum");
var player = helper.makeMockServerPlayerInLevel();
player.moveTo(mixer.getBlockPos().getX() + 0.5, mixer.getBlockPos().getY() + 0.5,
mixer.getBlockPos().getZ() + 0.5);
InkMixerMenu menu = new InkMixerMenu(1, player.getInventory(), mixer);
menu.clicked(InkMixerMenu.RESULT, 0, ClickType.PICKUP, player);
helper.assertTrue(menu.getCarried().is(ModItems.PAGE.get()), "Taking output must yield one panel");
for (int index = 0; index < 3; index++)
helper.assertValueEqual(mixer.modifierChancePermille(index), 0,
"Every modifier chance must reset when output is taken");
helper.assertValueEqual(mixer.getItem(InkMixerBlockEntity.PAPER).getCount(), 1,
"Taking output must consume one paper");
helper.succeed();
}
public static void linkPanelRequiresTakingOutputAndPersistsInk(GameTestHelper helper) { public static void linkPanelRequiresTakingOutputAndPersistsInk(GameTestHelper helper) {
InkMixerBlockEntity mixer = place(helper); InkMixerBlockEntity mixer = place(helper);
mixer.setItem(InkMixerBlockEntity.PAPER, new ItemStack(Items.PAPER, 2)); mixer.setItem(InkMixerBlockEntity.PAPER, new ItemStack(Items.PAPER, 2));
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.gametest;
import java.util.List; import java.util.List;
import net.dnorberg.rivencraft.Rivencraft; import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.item.PageItem; import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.registry.ModDataComponents; import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
@@ -48,6 +49,8 @@ public final class LinkingBookRecipeGameTests {
public static void outputIsUnwrittenAndRegisteredRecipeLoads(GameTestHelper helper) { public static void outputIsUnwrittenAndRegisteredRecipeLoads(GameTestHelper helper) {
ItemStack panel = PageItem.createLinkPanelPage(); ItemStack panel = PageItem.createLinkPanelPage();
panel.set(DataComponents.CUSTOM_NAME, Component.literal("Home Panel")); panel.set(DataComponents.CUSTOM_NAME, Component.literal("Home Panel"));
panel.set(ModDataComponents.LINK_PROPERTIES.get(),
new LinkProperties(LinkProperties.INTRA_LINKING | LinkProperties.MAINTAIN_MOMENTUM));
CraftingInput input = CraftingInput.of(2, 1, List.of(panel, new ItemStack(Items.LEATHER))); CraftingInput input = CraftingInput.of(2, 1, List.of(panel, new ItemStack(Items.LEATHER)));
var holder = helper.getLevel().getRecipeManager() var holder = helper.getLevel().getRecipeManager()
.getRecipeFor(RecipeType.CRAFTING, input, helper.getLevel()).orElseThrow(); .getRecipeFor(RecipeType.CRAFTING, input, helper.getLevel()).orElseThrow();
@@ -60,6 +63,14 @@ public final class LinkingBookRecipeGameTests {
helper.assertFalse(result.has(ModDataComponents.PAGE_CONTENT.get()), "Page identity must not leak onto the book"); helper.assertFalse(result.has(ModDataComponents.PAGE_CONTENT.get()), "Page identity must not leak onto the book");
helper.assertValueEqual(result.get(DataComponents.CUSTOM_NAME), Component.literal("Home Panel"), helper.assertValueEqual(result.get(DataComponents.CUSTOM_NAME), Component.literal("Home Panel"),
"The panel's custom name must survive crafting"); "The panel's custom name must survive crafting");
helper.assertValueEqual(result.get(ModDataComponents.LINK_PROPERTIES.get()),
panel.get(ModDataComponents.LINK_PROPERTIES.get()),
"The panel's link properties must survive crafting");
ItemStack restored = ItemStack.parseOptional(helper.getLevel().registryAccess(),
(net.minecraft.nbt.CompoundTag) result.saveOptional(helper.getLevel().registryAccess()));
helper.assertValueEqual(restored.get(ModDataComponents.LINK_PROPERTIES.get()),
panel.get(ModDataComponents.LINK_PROPERTIES.get()),
"The crafted book's link properties must persist through save/load");
helper.succeed(); helper.succeed();
} }
} }
@@ -11,6 +11,7 @@ import net.dnorberg.rivencraft.book.AgeRegistrySavedData;
import net.dnorberg.rivencraft.book.AgeRuntimeProfile; import net.dnorberg.rivencraft.book.AgeRuntimeProfile;
import net.dnorberg.rivencraft.book.AgeRuntimeProfiles; import net.dnorberg.rivencraft.book.AgeRuntimeProfiles;
import net.dnorberg.rivencraft.book.LinkTarget; import net.dnorberg.rivencraft.book.LinkTarget;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.book.LinkingService; import net.dnorberg.rivencraft.book.LinkingService;
import net.dnorberg.rivencraft.book.AgeVisitSavedData; import net.dnorberg.rivencraft.book.AgeVisitSavedData;
import net.dnorberg.rivencraft.book.AgeTraits; import net.dnorberg.rivencraft.book.AgeTraits;
@@ -578,7 +579,8 @@ public final class LinkingGameTests {
ServerPlayer player = helper.makeMockServerPlayerInLevel(); ServerPlayer player = helper.makeMockServerPlayerInLevel();
LinkTarget target = new LinkTarget(GlobalPos.of(helper.getLevel().dimension(), destination), 90.0F, 15.0F); LinkTarget target = new LinkTarget(GlobalPos.of(helper.getLevel().dimension(), destination), 90.0F, 15.0F);
LinkingService.LinkResult result = LinkingService.travel(player, target); LinkingService.LinkResult result = LinkingService.travel(player, target,
new LinkProperties(LinkProperties.INTRA_LINKING));
helper.assertValueEqual(result, LinkingService.LinkResult.SUCCESS, helper.assertValueEqual(result, LinkingService.LinkResult.SUCCESS,
"A Linking Book must accept leaf blocks even without a floor"); "A Linking Book must accept leaf blocks even without a floor");
@@ -603,7 +605,8 @@ public final class LinkingGameTests {
ServerPlayer player = helper.makeMockServerPlayerInLevel(); ServerPlayer player = helper.makeMockServerPlayerInLevel();
LinkTarget target = new LinkTarget(GlobalPos.of(helper.getLevel().dimension(), absoluteOrigin), 0.0F, 0.0F); LinkTarget target = new LinkTarget(GlobalPos.of(helper.getLevel().dimension(), absoluteOrigin), 0.0F, 0.0F);
helper.assertValueEqual(LinkingService.travelWithFooting(player, target), LinkingService.LinkResult.SUCCESS, helper.assertValueEqual(LinkingService.travelWithFooting(player, target,
new LinkProperties(LinkProperties.INTRA_LINKING)), LinkingService.LinkResult.SUCCESS,
"Descriptive Book travel must find an alternate grounded arrival"); "Descriptive Book travel must find an alternate grounded arrival");
BlockPos landing = player.blockPosition(); BlockPos landing = player.blockPosition();
helper.assertTrue(helper.getLevel().getBlockState(landing.below()).isFaceSturdy( helper.assertTrue(helper.getLevel().getBlockState(landing.below()).isFaceSturdy(
@@ -624,8 +627,10 @@ public final class LinkingGameTests {
ServerPlayer player = helper.makeMockServerPlayerInLevel(); ServerPlayer player = helper.makeMockServerPlayerInLevel();
LinkTarget target = new LinkTarget(GlobalPos.of(helper.getLevel().dimension(), absoluteOrigin), 0.0F, 0.0F); LinkTarget target = new LinkTarget(GlobalPos.of(helper.getLevel().dimension(), absoluteOrigin), 0.0F, 0.0F);
helper.assertValueEqual(LinkingService.travel(player, target), LinkingService.LinkResult.NO_SAFE_DESTINATION, helper.assertValueEqual(LinkingService.travel(player, target,
new LinkProperties(LinkProperties.INTRA_LINKING)), LinkingService.LinkResult.NO_SAFE_DESTINATION,
"Linking must fail rather than placing a player inside a blocked destination"); "Linking must fail rather than placing a player inside a blocked destination");
helper.succeed(); helper.succeed();
} }
} }
@@ -287,6 +287,8 @@ public final class WritingDataGameTests {
helper.assertFalse(menu.getSlot(0).mayPlace(new ItemStack(Items.DIRT)), helper.assertFalse(menu.getSlot(0).mayPlace(new ItemStack(Items.DIRT)),
"Notebook slots must reject non-Page items"); "Notebook slots must reject non-Page items");
helper.assertFalse(menu.getSlot(0).mayPlace(PageItem.createLinkPanelPage()),
"Notebook slots must reject Link Panels");
menu.getSlot(0).set(first); menu.getSlot(0).set(first);
menu.getSlot(1).set(second); menu.getSlot(1).set(second);
helper.assertTrue(menu.clickMenuButton(player, NotebookMenu.MOVE_NEXT_BASE), helper.assertTrue(menu.clickMenuButton(player, NotebookMenu.MOVE_NEXT_BASE),
@@ -97,7 +97,7 @@ public final class WritingDeskGameTests {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1)); BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3); helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
ItemStack source = PageItem.createLinkPanelPage(); ItemStack source = terrainPage();
desk.setItem(0, source.copy()); desk.setItem(0, source.copy());
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 2)); desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 2));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get())); desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
@@ -180,7 +180,7 @@ public final class WritingDeskGameTests {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1)); BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3); helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
desk.setItem(0, PageItem.createLinkPanelPage()); desk.setItem(0, terrainPage());
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 2)); desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER, 2));
desk.setItem(WritingDeskBlockEntity.RETURN, new ItemStack(Items.GLASS_BOTTLE, 64)); desk.setItem(WritingDeskBlockEntity.RETURN, new ItemStack(Items.GLASS_BOTTLE, 64));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get())); desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
@@ -210,7 +210,7 @@ public final class WritingDeskGameTests {
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
ItemStack notebook = new ItemStack(ModItems.NOTEBOOK.get()); ItemStack notebook = new ItemStack(ModItems.NOTEBOOK.get());
notebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), notebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(),
new NotebookContents(List.of(ItemStack.EMPTY, PageItem.createLinkPanelPage()))); new NotebookContents(List.of(ItemStack.EMPTY, terrainPage())));
desk.setItem(0, notebook); desk.setItem(0, notebook);
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER)); desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get())); desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
@@ -232,7 +232,7 @@ public final class WritingDeskGameTests {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1)); BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3); helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
desk.setItem(0, PageItem.createLinkPanelPage()); desk.setItem(0, terrainPage());
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER)); desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get())); desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
var first = helper.makeMockServerPlayerInLevel(); var first = helper.makeMockServerPlayerInLevel();
@@ -258,7 +258,7 @@ public final class WritingDeskGameTests {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1)); BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3); helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
desk.setItem(0, PageItem.createLinkPanelPage()); desk.setItem(0, terrainPage());
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER)); desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get())); desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
var player = helper.makeMockServerPlayerInLevel(); var player = helper.makeMockServerPlayerInLevel();
@@ -319,7 +319,7 @@ public final class WritingDeskGameTests {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1)); BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3); helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); WritingDeskBlockEntity desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
desk.setItem(0, PageItem.createLinkPanelPage()); desk.setItem(0, terrainPage());
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER)); desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get())); desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
var player = helper.makeMockServerPlayerInLevel(); var player = helper.makeMockServerPlayerInLevel();
@@ -446,7 +446,7 @@ public final class WritingDeskGameTests {
helper.assertTrue(menu.clickMenuButton(player, 87), "Tab 88 must be selectable without page-ID collisions"); helper.assertTrue(menu.clickMenuButton(player, 87), "Tab 88 must be selectable without page-ID collisions");
helper.assertValueEqual(desk.activeCollection(), 87, "Tab 88 must become active"); helper.assertValueEqual(desk.activeCollection(), 87, "Tab 88 must become active");
helper.assertFalse(menu.clickMenuButton(player, 88), "Tab 89 must not exist"); helper.assertFalse(menu.clickMenuButton(player, 88), "Tab 89 must not exist");
desk.setItem(87, PageItem.createLinkPanelPage()); desk.setItem(87, terrainPage());
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER)); desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get())); desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.ALL_PAGE_BUTTON_BASE + 87 * NotebookContents.MAX_PAGES), helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.ALL_PAGE_BUTTON_BASE + 87 * NotebookContents.MAX_PAGES),
@@ -502,7 +502,7 @@ public final class WritingDeskGameTests {
var player = helper.makeMockServerPlayerInLevel(); var player = helper.makeMockServerPlayerInLevel();
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
var menu = new WritingDeskMenu(1, player.getInventory(), desk); var menu = new WritingDeskMenu(1, player.getInventory(), desk);
ItemStack held = PageItem.createLinkPanelPage().copyWithCount(3); ItemStack held = terrainPage().copyWithCount(3);
ItemStack expectedPage = held.copyWithCount(1); ItemStack expectedPage = held.copyWithCount(1);
player.getInventory().setItem(9, held); player.getInventory().setItem(9, held);
menu.clicked(WritingDeskMenu.COPY_RESULT + 1, 0, ClickType.PICKUP, player); menu.clicked(WritingDeskMenu.COPY_RESULT + 1, 0, ClickType.PICKUP, player);
@@ -520,7 +520,7 @@ public final class WritingDeskGameTests {
helper.assertValueEqual(menu.pageCapacity(87), NotebookContents.MAX_PAGES, "Notebook tab must expose normal notebook capacity"); helper.assertValueEqual(menu.pageCapacity(87), NotebookContents.MAX_PAGES, "Notebook tab must expose normal notebook capacity");
helper.assertValueEqual(menu.pageCapacity(0), 0, "Empty tab has no page storage"); helper.assertValueEqual(menu.pageCapacity(0), 0, "Empty tab has no page storage");
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE), "Empty tab must require a collection first"); helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE), "Empty tab must require a collection first");
desk.setItem(0, PageItem.createLinkPanelPage()); desk.setItem(0, terrainPage());
helper.assertValueEqual(menu.pageCapacity(0), 1, "Loose page tab must expose exactly one position"); helper.assertValueEqual(menu.pageCapacity(0), 1, "Loose page tab must expose exactly one position");
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE), "Loose page must not be replaced"); helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE), "Loose page must not be replaced");
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE + 1), "Loose page tab must not grow extra positions"); helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE + 1), "Loose page tab must not grow extra positions");
@@ -543,14 +543,13 @@ public final class WritingDeskGameTests {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1)); BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3); helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
ItemStack linkPanel = PageItem.createLinkPanelPage(); ItemStack movingPage = terrainPage();
ItemStack terrain = PageItem.createSymbolPage(new SymbolReference( ItemStack terrain = terrainPage();
ResourceLocation.parse("rivencraft:terrain/standard")));
ItemStack firstBook = new ItemStack(ModItems.NOTEBOOK.get()); ItemStack firstBook = new ItemStack(ModItems.NOTEBOOK.get());
firstBook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(List.of(linkPanel, terrain))); firstBook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(List.of(movingPage, terrain)));
desk.setItem(0, firstBook); desk.setItem(0, firstBook);
desk.setItem(1, new ItemStack(ModItems.NOTEBOOK.get())); desk.setItem(1, new ItemStack(ModItems.NOTEBOOK.get()));
desk.setItem(2, PageItem.createLinkPanelPage()); desk.setItem(2, terrainPage());
var player = helper.makeMockServerPlayerInLevel(); var player = helper.makeMockServerPlayerInLevel();
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
var menu = new WritingDeskMenu(1, player.getInventory(), desk); var menu = new WritingDeskMenu(1, player.getInventory(), desk);
@@ -558,18 +557,18 @@ public final class WritingDeskGameTests {
helper.assertTrue(menu.clickMenuButton(player, moveToEmpty), "Drag must move to a distant empty notebook position"); helper.assertTrue(menu.clickMenuButton(player, moveToEmpty), "Drag must move to a distant empty notebook position");
var pages = desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages(); var pages = desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
helper.assertTrue(pages.get(0).isEmpty(), "Moving must clear the source position"); helper.assertTrue(pages.get(0).isEmpty(), "Moving must clear the source position");
helper.assertTrue(ItemStack.matches(pages.get(26), linkPanel), "Moving must preserve page components"); helper.assertTrue(ItemStack.matches(pages.get(26), movingPage), "Moving must preserve page components");
helper.assertValueEqual(desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pageCount(), 2, helper.assertValueEqual(desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pageCount(), 2,
"Moving must preserve total page count"); "Moving must preserve total page count");
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 26, 0, 1)), helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 26, 0, 1)),
"Drag onto an occupied position must swap pages"); "Drag onto an occupied position must swap pages");
pages = desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages(); pages = desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
helper.assertTrue(ItemStack.matches(pages.get(1), linkPanel) && ItemStack.matches(pages.get(26), terrain), helper.assertTrue(ItemStack.matches(pages.get(1), movingPage) && ItemStack.matches(pages.get(26), terrain),
"Swap must preserve both pages"); "Swap must preserve both pages");
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 1, 1, 5)), helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 1, 1, 5)),
"Drag into another notebook must work"); "Drag into another notebook must work");
var otherPages = desk.getItem(1).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages(); var otherPages = desk.getItem(1).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages();
helper.assertTrue(ItemStack.matches(otherPages.get(5), linkPanel) helper.assertTrue(ItemStack.matches(otherPages.get(5), movingPage)
&& desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages().get(1).isEmpty(), && desk.getItem(0).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages().get(1).isEmpty(),
"Cross notebook move must have one destination and no old source"); "Cross notebook move must have one destination and no old source");
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 1, 1, 6)), helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 1, 1, 6)),
@@ -584,7 +583,7 @@ public final class WritingDeskGameTests {
menu.setCarried(new ItemStack(Items.DIAMOND)); menu.setCarried(new ItemStack(Items.DIAMOND));
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(1, 5, 1, 6)), helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(1, 5, 1, 6)),
"Held inventory items must not be moved by a panel drag"); "Held inventory items must not be moved by a panel drag");
helper.assertTrue(ItemStack.matches(desk.getItem(1).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages().get(5), linkPanel), helper.assertTrue(ItemStack.matches(desk.getItem(1).get(ModDataComponents.NOTEBOOK_CONTENTS.get()).pages().get(5), movingPage),
"Rejected drags must leave notebook data intact"); "Rejected drags must leave notebook data intact");
helper.succeed(); helper.succeed();
} }
@@ -594,7 +593,7 @@ public final class WritingDeskGameTests {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1)); BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3); helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos); var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
ItemStack page = PageItem.createLinkPanelPage(); ItemStack page = terrainPage();
ItemStack source = new ItemStack(ModItems.NOTEBOOK.get()); ItemStack source = new ItemStack(ModItems.NOTEBOOK.get());
source.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), source.set(ModDataComponents.NOTEBOOK_CONTENTS.get(),
new NotebookContents(List.of(page, page, page, page, page, page))); new NotebookContents(List.of(page, page, page, page, page, page)));
@@ -643,4 +642,47 @@ public final class WritingDeskGameTests {
"Extracting a loose page must empty its tab and return the same item"); "Extracting a loose page must empty its tab and return the same item");
helper.succeed(); helper.succeed();
} }
@GameTest(template = "empty")
public static void linkPanelsCannotBeStoredOrCopiedButOldPanelsCanBeRecovered(GameTestHelper helper) {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
helper.getLevel().setBlock(pos, ModBlocks.WRITING_DESK.get().defaultBlockState(), 3);
var desk = (WritingDeskBlockEntity) helper.getLevel().getBlockEntity(pos);
ItemStack panel = PageItem.createLinkPanelPage();
ItemStack oldNotebook = new ItemStack(ModItems.NOTEBOOK.get());
oldNotebook.set(ModDataComponents.NOTEBOOK_CONTENTS.get(), new NotebookContents(List.of(panel)));
helper.assertFalse(desk.canPlaceItem(0, panel), "Desk tab must reject a Link Panel");
helper.assertFalse(desk.canPlaceItem(0, oldNotebook),
"Desk tab must reject a Notebook containing an old Link Panel");
// A preexisting desk is loaded without discarding its contents.
desk.setItem(0, panel.copy());
desk.setItem(1, new ItemStack(ModItems.NOTEBOOK.get()));
desk.setItem(WritingDeskBlockEntity.PAPER, new ItemStack(Items.PAPER));
desk.setItem(WritingDeskBlockEntity.INK, new ItemStack(ModItems.INK_VIAL.get()));
var player = helper.makeMockServerPlayerInLevel();
player.moveTo(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
var menu = new WritingDeskMenu(1, player.getInventory(), desk);
menu.broadcastChanges();
helper.assertTrue(menu.getSlot(WritingDeskMenu.COPY_RESULT).getItem().isEmpty(),
"Existing Link Panels must not produce a Desk copy");
helper.assertTrue(menu.quickMoveStack(player, WritingDeskMenu.COPY_RESULT).isEmpty(),
"Shift-click must not bypass the Link Panel copy rule");
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.movePageButtonId(0, 0, 1, 0)),
"An old Link Panel must not move into a Notebook");
menu.setCarried(panel.copy());
helper.assertFalse(menu.clickMenuButton(player, WritingDeskMenu.PLACE_PAGE_BUTTON_BASE
+ NotebookContents.MAX_PAGES), "A carried Link Panel must not enter a Notebook");
menu.setCarried(ItemStack.EMPTY);
helper.assertTrue(menu.clickMenuButton(player, WritingDeskMenu.extractPageButtonId(0, 0, -1)),
"A stored legacy Link Panel must remain recoverable to the cursor");
helper.assertTrue(ItemStack.matches(menu.getCarried(), panel),
"Recovery must preserve the original Link Panel");
helper.succeed();
}
private static ItemStack terrainPage() {
return PageItem.createSymbolPage(new SymbolReference(
ResourceLocation.parse("rivencraft:terrain/standard")));
}
} }
@@ -4,6 +4,7 @@ import java.util.List;
import net.dnorberg.rivencraft.book.AgeReference; import net.dnorberg.rivencraft.book.AgeReference;
import net.dnorberg.rivencraft.book.AgeVisitSavedData; import net.dnorberg.rivencraft.book.AgeVisitSavedData;
import net.dnorberg.rivencraft.book.LinkTarget; import net.dnorberg.rivencraft.book.LinkTarget;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.book.LinkingService; import net.dnorberg.rivencraft.book.LinkingService;
import net.dnorberg.rivencraft.book.AgeDimensionService; import net.dnorberg.rivencraft.book.AgeDimensionService;
import net.dnorberg.rivencraft.config.RivencraftConfig; import net.dnorberg.rivencraft.config.RivencraftConfig;
@@ -54,7 +55,9 @@ public final class DescriptiveBookItem extends Item {
ServerLevel sourceLevel = player.serverLevel(); ServerLevel sourceLevel = player.serverLevel();
var sourcePosition = player.blockPosition(); var sourcePosition = player.blockPosition();
LinkingService.LinkResult result = LinkingService.travelWithFooting(player, ageTarget); LinkProperties properties = stack.getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE)
.forDescriptiveBook();
LinkingService.LinkResult result = LinkingService.travelWithFooting(player, ageTarget, properties);
if (result != LinkingService.LinkResult.SUCCESS) { if (result != LinkingService.LinkResult.SUCCESS) {
player.displayClientMessage(Component.translatable("message.rivencraft.descriptive_book.unsafe"), true); player.displayClientMessage(Component.translatable("message.rivencraft.descriptive_book.unsafe"), true);
return false; return false;
@@ -109,5 +112,7 @@ public final class DescriptiveBookItem extends Item {
? Component.translatable("item.rivencraft.descriptive_book.unwritten") ? Component.translatable("item.rivencraft.descriptive_book.unwritten")
: Component.translatable("item.rivencraft.descriptive_book.age", age.name()); : Component.translatable("item.rivencraft.descriptive_book.age", age.name());
tooltipComponents.add(status.withStyle(ChatFormatting.GRAY)); tooltipComponents.add(status.withStyle(ChatFormatting.GRAY));
stack.getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE)
.forDescriptiveBook().appendTooltip(tooltipComponents);
} }
} }
@@ -4,6 +4,7 @@ import java.util.List;
import net.dnorberg.rivencraft.book.LinkTarget; import net.dnorberg.rivencraft.book.LinkTarget;
import net.dnorberg.rivencraft.book.AgeRegistrySavedData; import net.dnorberg.rivencraft.book.AgeRegistrySavedData;
import net.dnorberg.rivencraft.book.LinkingService; import net.dnorberg.rivencraft.book.LinkingService;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.registry.ModDataComponents; import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModSounds; import net.dnorberg.rivencraft.registry.ModSounds;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
@@ -49,7 +50,8 @@ public final class LinkingBookItem extends Item {
Level sourceLevel = player.level(); Level sourceLevel = player.level();
BlockPos sourcePosition = player.blockPosition(); BlockPos sourcePosition = player.blockPosition();
LinkingService.LinkResult result = LinkingService.travel(player, target); LinkProperties properties = stack.getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE);
LinkingService.LinkResult result = LinkingService.travel(player, target, properties);
if (result == LinkingService.LinkResult.SUCCESS) { if (result == LinkingService.LinkResult.SUCCESS) {
sourceLevel.playSound(null, sourcePosition, ModSounds.LINK.get(), SoundSource.PLAYERS, sourceLevel.playSound(null, sourcePosition, ModSounds.LINK.get(), SoundSource.PLAYERS,
0.8F, sourceLevel.random.nextFloat() * 0.2F + 0.9F); 0.8F, sourceLevel.random.nextFloat() * 0.2F + 0.9F);
@@ -65,9 +67,11 @@ public final class LinkingBookItem extends Item {
return InteractionResultHolder.success(stack); return InteractionResultHolder.success(stack);
} }
String errorKey = result == LinkingService.LinkResult.MISSING_DIMENSION String errorKey = switch (result) {
? "message.rivencraft.linking_book.missing_dimension" case MISSING_DIMENSION -> "message.rivencraft.linking_book.missing_dimension";
: "message.rivencraft.linking_book.unsafe"; case INTRA_LINKING_REQUIRED -> "message.rivencraft.linking_book.intra_required";
default -> "message.rivencraft.linking_book.unsafe";
};
player.displayClientMessage(Component.translatable(errorKey), true); player.displayClientMessage(Component.translatable(errorKey), true);
return InteractionResultHolder.fail(stack); return InteractionResultHolder.fail(stack);
} }
@@ -85,9 +89,11 @@ public final class LinkingBookItem extends Item {
TooltipFlag tooltipFlag TooltipFlag tooltipFlag
) { ) {
LinkTarget target = stack.get(ModDataComponents.LINK_TARGET.get()); LinkTarget target = stack.get(ModDataComponents.LINK_TARGET.get());
LinkProperties properties = stack.getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE);
if (target == null) { if (target == null) {
tooltipComponents.add(Component.translatable("item.rivencraft.linking_book.unbound") tooltipComponents.add(Component.translatable("item.rivencraft.linking_book.unbound")
.withStyle(ChatFormatting.GRAY)); .withStyle(ChatFormatting.GRAY));
properties.appendTooltip(tooltipComponents);
return; return;
} }
@@ -101,6 +107,7 @@ public final class LinkingBookItem extends Item {
position.getZ() position.getZ()
) )
.withStyle(ChatFormatting.GRAY)); .withStyle(ChatFormatting.GRAY));
properties.appendTooltip(tooltipComponents);
} }
public static String destinationName(ServerLevel level) { public static String destinationName(ServerLevel level) {
@@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import net.dnorberg.rivencraft.Rivencraft; import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.registry.ModDataComponents; import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.writing.PageContent; import net.dnorberg.rivencraft.writing.PageContent;
@@ -223,6 +224,8 @@ public final class PageItem extends Item {
if (content.kind() == PageContent.Kind.LINK_PANEL) { if (content.kind() == PageContent.Kind.LINK_PANEL) {
tooltipComponents.add(Component.translatable("item.rivencraft.page.link_panel.description") tooltipComponents.add(Component.translatable("item.rivencraft.page.link_panel.description")
.withStyle(ChatFormatting.GRAY)); .withStyle(ChatFormatting.GRAY));
stack.getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE)
.appendTooltip(tooltipComponents);
return; return;
} }
SymbolReference reference = content.symbol().orElseThrow(); SymbolReference reference = content.symbol().orElseThrow();
@@ -10,6 +10,7 @@ import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.DataSlot; import net.minecraft.world.inventory.DataSlot;
import net.minecraft.world.inventory.Slot; import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@@ -17,13 +18,15 @@ import net.minecraft.world.item.Items;
/** Server-owned virtual output; taking it spends paper and the configured ink cost once. */ /** Server-owned virtual output; taking it spends paper and the configured ink cost once. */
public final class InkMixerMenu extends AbstractContainerMenu { public final class InkMixerMenu extends AbstractContainerMenu {
public static final int RESULT = InkMixerBlockEntity.SIZE; public static final int MODIFIER = InkMixerBlockEntity.SIZE;
public static final int RESULT = MODIFIER + 1;
private static final int PLAYER_START = RESULT + 1; private static final int PLAYER_START = RESULT + 1;
private final InkMixerBlockEntity mixer; private final InkMixerBlockEntity mixer;
private final Container inputs; private final Container inputs;
private final SimpleContainer result = new SimpleContainer(1); private final SimpleContainer result = new SimpleContainer(1);
private final boolean clientSide; private final boolean clientSide;
private int inkRemaining; private int inkRemaining;
private final int[] modifierChances = new int[3];
public InkMixerMenu(int id, Inventory inventory, RegistryFriendlyByteBuf data) { public InkMixerMenu(int id, Inventory inventory, RegistryFriendlyByteBuf data) {
this(id, inventory, inventory.player.level().getBlockEntity(data.readBlockPos()) this(id, inventory, inventory.player.level().getBlockEntity(data.readBlockPos())
@@ -39,9 +42,19 @@ public final class InkMixerMenu extends AbstractContainerMenu {
@Override public int get() { return clientSide ? inkRemaining : mixer.inkRemaining(); } @Override public int get() { return clientSide ? inkRemaining : mixer.inkRemaining(); }
@Override public void set(int value) { inkRemaining = value; } @Override public void set(int value) { inkRemaining = value; }
}); });
for (int index = 0; index < modifierChances.length; index++) {
final int chanceIndex = index;
addDataSlot(new DataSlot() {
@Override public int get() {
return clientSide ? modifierChances[chanceIndex] : mixer.modifierChancePermille(chanceIndex);
}
@Override public void set(int value) { modifierChances[chanceIndex] = value; }
});
}
addSlot(new MixerSlot(InkMixerBlockEntity.INK, 8, 27)); addSlot(new MixerSlot(InkMixerBlockEntity.INK, 8, 27));
addSlot(new MixerSlot(InkMixerBlockEntity.PAPER, 8, 48)); addSlot(new MixerSlot(InkMixerBlockEntity.PAPER, 8, 48));
addSlot(new MixerSlot(InkMixerBlockEntity.BOTTLES, 152, 27)); addSlot(new MixerSlot(InkMixerBlockEntity.BOTTLES, 152, 27));
addSlot(new ModifierSlot(79, 40));
addSlot(new ResultSlot(152, 48)); addSlot(new ResultSlot(152, 48));
for (int row = 0; row < 3; row++) for (int row = 0; row < 3; row++)
for (int column = 0; column < 9; column++) for (int column = 0; column < 9; column++)
@@ -52,6 +65,24 @@ public final class InkMixerMenu extends AbstractContainerMenu {
} }
public int inkRemaining() { return inkRemaining; } public int inkRemaining() { return inkRemaining; }
public int modifierChancePermille(int index) { return modifierChances[index]; }
@Override public void clicked(int slotId, int button, ClickType clickType, Player player) {
if (slotId == MODIFIER) {
if (!clientSide && stillValid(player) && clickType == ClickType.PICKUP
&& (button == 0 || button == 1)) {
ItemStack carried = getCarried();
int amount = button == 1 ? 1 : carried.getCount();
if (mixer.addModifier(carried, amount)) {
setCarried(carried);
refreshResult();
broadcastChanges();
}
}
return;
}
super.clicked(slotId, button, clickType, player);
}
@Override public boolean stillValid(Player player) { @Override public boolean stillValid(Player player) {
return mixer != null && mixer.stillValid(player); return mixer != null && mixer.stillValid(player);
@@ -64,8 +95,7 @@ public final class InkMixerMenu extends AbstractContainerMenu {
private void refreshResult() { private void refreshResult() {
if (clientSide) return; if (clientSide) return;
ItemStack preview = mixer != null && mixer.canCreateLinkPanel() ItemStack preview = mixer == null ? ItemStack.EMPTY : mixer.previewLinkPanel();
? PageItem.createLinkPanelPage() : ItemStack.EMPTY;
if (!ItemStack.matches(result.getItem(0), preview)) result.setItem(0, preview); if (!ItemStack.matches(result.getItem(0), preview)) result.setItem(0, preview);
} }
@@ -87,7 +117,7 @@ public final class InkMixerMenu extends AbstractContainerMenu {
ItemStack source = slot.getItem(); ItemStack source = slot.getItem();
ItemStack original = source.copy(); ItemStack original = source.copy();
boolean moved; boolean moved;
if (index < RESULT) moved = moveItemStackTo(source, PLAYER_START, slots.size(), true); if (index < MODIFIER) moved = moveItemStackTo(source, PLAYER_START, slots.size(), true);
else if (source.is(ModItems.INK_VIAL.get())) else if (source.is(ModItems.INK_VIAL.get()))
moved = moveItemStackTo(source, InkMixerBlockEntity.INK, InkMixerBlockEntity.INK + 1, false); moved = moveItemStackTo(source, InkMixerBlockEntity.INK, InkMixerBlockEntity.INK + 1, false);
else if (source.is(Items.PAPER)) else if (source.is(Items.PAPER))
@@ -105,6 +135,12 @@ public final class InkMixerMenu extends AbstractContainerMenu {
@Override public boolean mayPlace(ItemStack stack) { return inputs.canPlaceItem(getContainerSlot(), stack); } @Override public boolean mayPlace(ItemStack stack) { return inputs.canPlaceItem(getContainerSlot(), stack); }
} }
private static final class ModifierSlot extends Slot {
ModifierSlot(int x, int y) { super(new SimpleContainer(1), 0, x, y); }
@Override public boolean mayPlace(ItemStack stack) { return false; }
@Override public boolean mayPickup(Player player) { return false; }
}
private final class ResultSlot extends Slot { private final class ResultSlot extends Slot {
ResultSlot(int x, int y) { super(result, 0, x, y); } ResultSlot(int x, int y) { super(result, 0, x, y); }
@Override public boolean mayPlace(ItemStack stack) { return false; } @Override public boolean mayPlace(ItemStack stack) { return false; }
@@ -5,6 +5,8 @@ import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.registry.ModMenus; import net.dnorberg.rivencraft.registry.ModMenus;
import net.dnorberg.rivencraft.writing.NotebookContents; import net.dnorberg.rivencraft.writing.NotebookContents;
import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.item.PageItem;
import net.minecraft.core.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.world.Container; import net.minecraft.world.Container;
@@ -82,6 +84,7 @@ public final class NotebookMenu extends AbstractContainerMenu {
} }
} else { } else {
if (!source.is(ModItems.PAGE.get()) if (!source.is(ModItems.PAGE.get())
|| PageItem.content(source).kind() == PageContent.Kind.LINK_PANEL
|| !moveItemStackTo(source, 0, PLAYER_INVENTORY_START, false)) { || !moveItemStackTo(source, 0, PLAYER_INVENTORY_START, false)) {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@@ -135,7 +138,10 @@ public final class NotebookMenu extends AbstractContainerMenu {
super(container, slot, x, y); super(container, slot, x, y);
} }
@Override public boolean mayPlace(ItemStack stack) { return stack.is(ModItems.PAGE.get()); } @Override public boolean mayPlace(ItemStack stack) {
return stack.is(ModItems.PAGE.get())
&& PageItem.content(stack).kind() != PageContent.Kind.LINK_PANEL;
}
@Override public int getMaxStackSize() { return 1; } @Override public int getMaxStackSize() { return 1; }
} }
@@ -180,7 +180,7 @@ public final class WritingDeskMenu extends AbstractContainerMenu {
private boolean placeCarriedPage(int collectionIndex, int pageIndex) { private boolean placeCarriedPage(int collectionIndex, int pageIndex) {
// Resolve the actual storage position on the server, never a filtered list index. // Resolve the actual storage position on the server, never a filtered list index.
ItemStack carried = getCarried(); ItemStack carried = getCarried();
if (clientSide || !carried.is(ModItems.PAGE.get())) return false; if (clientSide || !storablePage(carried)) return false;
ItemStack collection = desk.getItem(collectionIndex); ItemStack collection = desk.getItem(collectionIndex);
if (collection.is(ModItems.NOTEBOOK.get())) { if (collection.is(ModItems.NOTEBOOK.get())) {
var pages = new java.util.ArrayList<>(collection.getOrDefault( var pages = new java.util.ArrayList<>(collection.getOrDefault(
@@ -215,12 +215,14 @@ public final class WritingDeskMenu extends AbstractContainerMenu {
if (sourceNotebook && (sourcePage >= sourcePages.size() || sourcePages.get(sourcePage).isEmpty())) return false; if (sourceNotebook && (sourcePage >= sourcePages.size() || sourcePages.get(sourcePage).isEmpty())) return false;
ItemStack moving = sourceNotebook ? sourcePages.get(sourcePage) : sourceBook; ItemStack moving = sourceNotebook ? sourcePages.get(sourcePage) : sourceBook;
if (moving.getCount() != 1) return false; if (moving.getCount() != 1) return false;
if (!storablePage(moving)) return false;
if (!targetNotebook && targetBook.getCount() != 1) return false; if (!targetNotebook && targetBook.getCount() != 1) return false;
var targetPages = targetNotebook ? sourceCollection == targetCollection ? sourcePages var targetPages = targetNotebook ? sourceCollection == targetCollection ? sourcePages
: new java.util.ArrayList<>(targetBook.getOrDefault( : new java.util.ArrayList<>(targetBook.getOrDefault(
ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages()) : null; ModDataComponents.NOTEBOOK_CONTENTS.get(), NotebookContents.EMPTY).pages()) : null;
if (targetNotebook) while (targetPages.size() <= targetPage) targetPages.add(ItemStack.EMPTY); if (targetNotebook) while (targetPages.size() <= targetPage) targetPages.add(ItemStack.EMPTY);
ItemStack displaced = targetNotebook ? targetPages.get(targetPage) : targetBook; ItemStack displaced = targetNotebook ? targetPages.get(targetPage) : targetBook;
if (!displaced.isEmpty() && !storablePage(displaced)) return false;
if (targetNotebook) targetPages.set(targetPage, moving); if (targetNotebook) targetPages.set(targetPage, moving);
if (sourceNotebook) { if (sourceNotebook) {
sourcePages.set(sourcePage, displaced); sourcePages.set(sourcePage, displaced);
@@ -256,6 +258,7 @@ public final class WritingDeskMenu extends AbstractContainerMenu {
setCarried(moving); setCarried(moving);
} else { } else {
if (targetSlot >= WritingDeskBlockEntity.COLLECTIONS && targetSlot < PLAYER_START) return false; if (targetSlot >= WritingDeskBlockEntity.COLLECTIONS && targetSlot < PLAYER_START) return false;
if (targetSlot < WritingDeskBlockEntity.COLLECTIONS && !storablePage(moving)) return false;
Slot target = slots.get(targetSlot); Slot target = slots.get(targetSlot);
if (!target.isActive() || !target.mayPlace(moving)) return false; if (!target.isActive() || !target.mayPlace(moving)) return false;
ItemStack current = target.getItem(); ItemStack current = target.getItem();
@@ -340,10 +343,15 @@ public final class WritingDeskMenu extends AbstractContainerMenu {
if (moving.is(Items.PAPER)) if (moving.is(Items.PAPER))
return moveItemStackTo(moving, WritingDeskBlockEntity.PAPER, return moveItemStackTo(moving, WritingDeskBlockEntity.PAPER,
WritingDeskBlockEntity.PAPER + 1, false); WritingDeskBlockEntity.PAPER + 1, false);
if (moving.is(ModItems.PAGE.get())) return moveItemStackTo(moving, firstVisibleTab, firstVisibleTab + VISIBLE_TABS, false); if (storablePage(moving)) return moveItemStackTo(moving, firstVisibleTab, firstVisibleTab + VISIBLE_TABS, false);
return false; return false;
} }
private static boolean storablePage(ItemStack stack) {
return stack.is(ModItems.PAGE.get())
&& PageItem.content(stack).kind() != PageContent.Kind.LINK_PANEL;
}
private ItemStack selectedSource() { private ItemStack selectedSource() {
if (selectedSymbol != null) { if (selectedSymbol != null) {
SymbolReference reference = new SymbolReference(selectedSymbol); SymbolReference reference = new SymbolReference(selectedSymbol);
@@ -375,6 +383,7 @@ public final class WritingDeskMenu extends AbstractContainerMenu {
ItemStack source = selectedSource(); ItemStack source = selectedSource();
return blockEntity != null && source.is(ModItems.PAGE.get()) return blockEntity != null && source.is(ModItems.PAGE.get())
&& PageItem.content(source).kind() != PageContent.Kind.BLANK && PageItem.content(source).kind() != PageContent.Kind.BLANK
&& PageItem.content(source).kind() != PageContent.Kind.LINK_PANEL
&& PageItem.isUsableWriting(source) && blockEntity.canConsumeCopyMaterials(); && PageItem.isUsableWriting(source) && blockEntity.canConsumeCopyMaterials();
} }
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.registry;
import net.dnorberg.rivencraft.Rivencraft; import net.dnorberg.rivencraft.Rivencraft;
import net.dnorberg.rivencraft.book.LinkTarget; import net.dnorberg.rivencraft.book.LinkTarget;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.book.AgeReference; import net.dnorberg.rivencraft.book.AgeReference;
import net.dnorberg.rivencraft.writing.PageContent; import net.dnorberg.rivencraft.writing.PageContent;
import net.dnorberg.rivencraft.writing.NotebookContents; import net.dnorberg.rivencraft.writing.NotebookContents;
@@ -26,6 +27,12 @@ public final class ModDataComponents {
.networkSynchronized(LinkTarget.STREAM_CODEC) .networkSynchronized(LinkTarget.STREAM_CODEC)
.cacheEncoding() .cacheEncoding()
.build()); .build());
public static final DeferredHolder<DataComponentType<?>, DataComponentType<LinkProperties>> LINK_PROPERTIES =
DATA_COMPONENTS.register("link_properties", () -> DataComponentType.<LinkProperties>builder()
.persistent(LinkProperties.CODEC)
.networkSynchronized(LinkProperties.STREAM_CODEC)
.cacheEncoding()
.build());
public static final DeferredHolder<DataComponentType<?>, DataComponentType<AgeReference>> AGE_REFERENCE = public static final DeferredHolder<DataComponentType<?>, DataComponentType<AgeReference>> AGE_REFERENCE =
DATA_COMPONENTS.register("age_reference", () -> DataComponentType.<AgeReference>builder() DATA_COMPONENTS.register("age_reference", () -> DataComponentType.<AgeReference>builder()
.persistent(AgeReference.CODEC) .persistent(AgeReference.CODEC)
@@ -0,0 +1,33 @@
package net.dnorberg.rivencraft.writing;
import java.util.List;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
/** Built-in Legacy ink additives. Optional mod dusts will be mapped through tags separately. */
public final class InkModifierIngredients {
public record Effect(int flag, double chance) {}
public record Ingredient(ItemStack item, List<Effect> effects) {}
private static final List<Ingredient> BUILT_IN = List.of(
new Ingredient(new ItemStack(Items.GUNPOWDER), List.of(new Effect(LinkProperties.DISARM, 0.20))),
new Ingredient(new ItemStack(Items.MUSHROOM_STEW), List.of(new Effect(LinkProperties.DISARM, 0.05))),
new Ingredient(new ItemStack(Items.EXPERIENCE_BOTTLE), List.of(new Effect(LinkProperties.INTRA_LINKING, 0.15))),
new Ingredient(new ItemStack(Items.ENDER_PEARL), List.of(
new Effect(LinkProperties.INTRA_LINKING, 0.15),
new Effect(LinkProperties.DISARM, 0.15))),
new Ingredient(new ItemStack(Items.FEATHER), List.of(new Effect(LinkProperties.MAINTAIN_MOMENTUM, 0.15))),
new Ingredient(new ItemStack(Items.FIRE_CHARGE), List.of(new Effect(LinkProperties.DISARM, 0.25)))
);
private InkModifierIngredients() {}
public static List<Ingredient> builtIn() {
return BUILT_IN;
}
public static Ingredient find(ItemStack stack) {
return BUILT_IN.stream().filter(ingredient -> stack.is(ingredient.item().getItem())).findFirst().orElse(null);
}
}
@@ -1,6 +1,7 @@
package net.dnorberg.rivencraft.writing; package net.dnorberg.rivencraft.writing;
import net.dnorberg.rivencraft.item.PageItem; import net.dnorberg.rivencraft.item.PageItem;
import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.registry.ModRecipeSerializers; import net.dnorberg.rivencraft.registry.ModRecipeSerializers;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
@@ -50,11 +51,13 @@ public final class LinkingBookRecipe extends CustomRecipe {
ItemStack panel = findPanel(input); ItemStack panel = findPanel(input);
if (panel.isEmpty()) return ItemStack.EMPTY; if (panel.isEmpty()) return ItemStack.EMPTY;
ItemStack book = new ItemStack(ModItems.LINKING_BOOK.get()); ItemStack book = new ItemStack(ModItems.LINKING_BOOK.get());
// Legacy copied the panel's data. Only its custom name is meaningful to a // Copy book-relevant panel data, never the Page identity component.
// 1.21.1 Linking Book today; page-only components must not reach the book.
if (panel.has(DataComponents.CUSTOM_NAME)) { if (panel.has(DataComponents.CUSTOM_NAME)) {
book.set(DataComponents.CUSTOM_NAME, panel.get(DataComponents.CUSTOM_NAME)); book.set(DataComponents.CUSTOM_NAME, panel.get(DataComponents.CUSTOM_NAME));
} }
if (panel.has(ModDataComponents.LINK_PROPERTIES.get())) {
book.set(ModDataComponents.LINK_PROPERTIES.get(), panel.get(ModDataComponents.LINK_PROPERTIES.get()));
}
return book; return book;
} }
@@ -10,7 +10,10 @@
"item.rivencraft.page.blank": "Blank Page", "item.rivencraft.page.blank": "Blank Page",
"item.rivencraft.page.blank.description": "Ready for writing at a Writing Desk.", "item.rivencraft.page.blank.description": "Ready for writing at a Writing Desk.",
"item.rivencraft.page.link_panel": "Link Panel Page", "item.rivencraft.page.link_panel": "Link Panel Page",
"item.rivencraft.page.link_panel.description": "The baseline panel required to assemble a Descriptive Book.", "item.rivencraft.page.link_panel.description": "A Link Panel for assembling books.",
"item.rivencraft.link_property.disarm": "Disarm",
"item.rivencraft.link_property.maintain_momentum": "Maintain Momentum",
"item.rivencraft.link_property.intra_linking": "Intra Linking",
"item.rivencraft.page.unresolved": "Unresolved Symbol Page", "item.rivencraft.page.unresolved": "Unresolved Symbol Page",
"item.rivencraft.notebook": "Notebook", "item.rivencraft.notebook": "Notebook",
"item.rivencraft.notebook.pages": "Pages: %s/%s", "item.rivencraft.notebook.pages": "Pages: %s/%s",
@@ -23,6 +26,8 @@
"block.rivencraft.ink_mixer": "Ink Mixer", "block.rivencraft.ink_mixer": "Ink Mixer",
"container.rivencraft.ink_mixer": "Ink Mixer", "container.rivencraft.ink_mixer": "Ink Mixer",
"screen.rivencraft.ink_mixer.ink": "Ink: %s/%s", "screen.rivencraft.ink_mixer.ink": "Ink: %s/%s",
"screen.rivencraft.ink_mixer.additive_hint": "Click the basin with an additive; right-click adds one.",
"screen.rivencraft.ink_mixer.chance": "%s: %s%%",
"screen.rivencraft.book_binder.title": "Book title", "screen.rivencraft.book_binder.title": "Book title",
"screen.rivencraft.book_binder.title_hint": "Name the book", "screen.rivencraft.book_binder.title_hint": "Name the book",
"screen.rivencraft.book_binder.missing_panel": "Link Panel required as the first page", "screen.rivencraft.book_binder.missing_panel": "Link Panel required as the first page",
@@ -67,6 +72,7 @@
"message.rivencraft.linking_book.linked": "Linked", "message.rivencraft.linking_book.linked": "Linked",
"message.rivencraft.linking_book.missing_dimension": "That dimension is unavailable", "message.rivencraft.linking_book.missing_dimension": "That dimension is unavailable",
"message.rivencraft.linking_book.unsafe": "No safe destination was found near the link", "message.rivencraft.linking_book.unsafe": "No safe destination was found near the link",
"message.rivencraft.linking_book.intra_required": "This book needs an Intra Linking panel for same-dimension travel",
"message.rivencraft.descriptive_book.unwritten": "This Descriptive Book is unwritten", "message.rivencraft.descriptive_book.unwritten": "This Descriptive Book is unwritten",
"message.rivencraft.descriptive_book.created": "Created Age: %s", "message.rivencraft.descriptive_book.created": "Created Age: %s",
"message.rivencraft.descriptive_book.unavailable": "That Age is unavailable", "message.rivencraft.descriptive_book.unavailable": "That Age is unavailable",
@@ -243,6 +249,8 @@
"jei.rivencraft.writing.link_panel_hand": "Hold paper and an Ink Vial in opposite hands; use the vial to make a Link Panel.", "jei.rivencraft.writing.link_panel_hand": "Hold paper and an Ink Vial in opposite hands; use the vial to make a Link Panel.",
"jei.rivencraft.ink_mixer": "Ink Mixer", "jei.rivencraft.ink_mixer": "Ink Mixer",
"jei.rivencraft.ink_mixer.usage": "Paper + ink makes a Link Panel. One vial fills 16 ink; each panel uses the configured ink cost. The empty vial returns as a glass bottle.", "jei.rivencraft.ink_mixer.usage": "Paper + ink makes a Link Panel. One vial fills 16 ink; each panel uses the configured ink cost. The empty vial returns as a glass bottle.",
"jei.rivencraft.ink_mixer.additive": "Click this additive into the ink basin: %s. Effects roll when the panel is taken.",
"jei.rivencraft.ink_mixer.effect": "%s %s%%",
"jei.rivencraft.writing.copy": "At a Writing Desk, select a stored Page, add paper and ink, then take the copy. The source Page stays.", "jei.rivencraft.writing.copy": "At a Writing Desk, select a stored Page, add paper and ink, then take the copy. The source Page stays.",
"jei.rivencraft.writing.bind": "At a Book Binder, name the Age and add a cover plus Link Panel. Optional symbol Pages follow the panel.", "jei.rivencraft.writing.bind": "At a Book Binder, name the Age and add a cover plus Link Panel. Optional symbol Pages follow the panel.",
"jei.rivencraft.writing.linking_book": "Craft one Link Panel Page with leather to make an unwritten Linking Book. Open it to name and bind it.", "jei.rivencraft.writing.linking_book": "Craft one Link Panel Page with leather to make an unwritten Linking Book. Open it to name and bind it.",