Compare commits

...
2 Commits
Author SHA1 Message Date
dnorberg 9cb63e6994 Align Writing Desk numerals with Legacy glyphs (#43)
Build / build (push) Canceled after 0s
2026-10-21 14:01:02 -04:00
dnorberg 6337b5aa10 Restore Legacy link modifier travel behavior
Build / build (push) Canceled after 0s
2026-10-21 13:36:30 -04:00
53 changed files with 376 additions and 66 deletions

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

+3 -2
View File
@@ -85,8 +85,9 @@ 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 the base paper/ink/vial operation and separate entries for Gunpowder, Mushroom
Stew, Experience Bottle, Ender Pearl, Feather, and Fire Charge, Stew, Experience Bottle, Ender Pearl, Feather, and Fire Charge,
with their property chances. Black Dye and Clay Ball should not appear: the with their property chances. Black Dye and Clay Ball should not appear: the
former had no working Legacy effect, while Generate Platform is redundant former had no working Legacy effect, while Clay Ball remains unsupported by
with default Age arrival. Without JEI, Rivencraft should still the mixer. The creative Link Modifier can enable a single arrival platform for
Linking Books; they do not create one by default. Without JEI, Rivencraft should still
start and the mixer should work normally. start and the mixer should work normally.
Put paper and an Ink Vial in the mixer. Hold Gunpowder on the cursor and Put paper and an Ink Vial in the mixer. Hold Gunpowder on the cursor and
+1 -1
View File
@@ -27,4 +27,4 @@ Implementation requirements: keep the mixer server-authoritative; persist mixtur
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. 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. 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 Ink Mixer still does not roll Generate Platform, but since 0.6.7.1 the creative Link Modifier can explicitly enable it for Linking Books; their default remains off. Optional dust-tag mappings remain outside this built-in subset until their cross-mod tags and gameplay meaning are agreed.
+1 -1
View File
@@ -20,7 +20,7 @@ Milestone 5 issue #29 adds typed meaning to the existing data-pack symbol catalo
`poem` is optional, client-safe artwork metadata: exactly four alphabetic words, ordered top, right, bottom, left. The client layers their glyphs from the shared Legacy component sheet at runtime. GUI thumbnails use the full transparent artwork over their page backgrounds; item icons use the same artwork reduced from 16 to 13 pixels across, over the page texture. Unregistered words use a stable generated component combination; when a symbol has no poem, the six original built-in IDs retain their Legacy poems and other IDs produce four stable fallback words. This affects appearance only, never Age generation. Generated images are cached up to 256 entries and discarded on resource reload. `poem` is optional, client-safe artwork metadata: exactly four alphabetic words, ordered top, right, bottom, left. The client layers their glyphs from the shared Legacy component sheet at runtime. GUI thumbnails use the full transparent artwork over their page backgrounds; item icons use the same artwork reduced from 16 to 13 pixels across, over the page texture. Unregistered words use a stable generated component combination; when a symbol has no poem, the six original built-in IDs retain their Legacy poems and other IDs produce four stable fallback words. This affects appearance only, never Age generation. Generated images are cached up to 256 entries and discarded on resource reload.
The Writing Desk's 88 collection tabs use Legacy's number components, chiefly the bottom row of `symbolcomponents.png`, rather than word sigils. Legacy's `ModWords.constructNumber` combines four unit marks (1–4) with four five-step marks (5–20) to form 1–24 and uses a separate zero mark. Rivencraft extends these marks positionally in base 25 for tabs 25–88 (for example, 25 is 1 followed by 0). Hovering still reveals the decimal number for accessibility. The former arbitrary-word glyph generator remains useful for rendering text: on page-free Descriptive Books, the generated Age description now appears as a sequence of layered word glyphs instead of Minecraft's enchantment font. The Age name stays readable. The Writing Desk retains 88 collection tabs, numbered from zero as in Legacy. Legacy's `ModWords.constructNumber` defines 0 as component 1 and 1–24 by overlaying a unit mark (1–4) and a five-step mark (5–20) from the bottom row of `symbolcomponents.png` in the *same square*. Legacy's Writing Desk has 25 tabs (0–24) and scrolls its four-tab window **one tab at a time**. Thus the supplied Legacy screenshots labeled 1–4, 5–8, and so on show overlapping windows, not 88 distinct numerals. Rivencraft retains its previously requested four-at-a-time navigation and 88 tabs. Its additional tab numbers use positional base 25: each place is an overlaid Legacy digit, with the places side by side (25 = 1,0). The two glyphs are sized and positioned to fit the tab. Hovering reveals the decimal tab index for accessibility. The generated-word mechanism renders page-free Descriptive Book text as layered glyphs instead of Minecraft's enchantment font. The Age name stays readable.
| Role | Value type and allowed values | | Role | Value type and allowed values |
| --- | --- | | --- | --- |
+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.6.7.0 mod_version=0.6.7.2
immersive_portals_version=6.0.7 immersive_portals_version=6.0.7
terrablender_version=4.1.0.8 terrablender_version=4.1.0.8
serene_seasons_version_id=pHEgQQUE serene_seasons_version_id=pHEgQQUE
@@ -11,7 +11,6 @@ import net.dnorberg.rivencraft.registry.ModItems;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.RandomSource; import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@@ -54,16 +53,16 @@ public final class CrystalPortalBlock extends BaseEntityBlock {
@Override protected boolean canBeReplaced(BlockState state, Fluid fluid) { return false; } @Override protected boolean canBeReplaced(BlockState state, Fluid fluid) { return false; }
@Override protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) { @Override protected void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
if (!(level instanceof ServerLevel server) || !(entity instanceof ServerPlayer player)) return; if (!(level instanceof ServerLevel server)) return;
long now = server.getServer().getTickCount(); long now = server.getServer().getTickCount();
if (PortalTravelCooldown.blocked(player, now)) return; if (PortalTravelCooldown.blocked(entity, now)) return;
if (!(level.getBlockEntity(pos) instanceof CrystalPortalBlockEntity portal) if (!(level.getBlockEntity(pos) instanceof CrystalPortalBlockEntity portal)
|| portal.receptacle() == null || !level.hasChunkAt(portal.receptacle()) || portal.receptacle() == null || !level.hasChunkAt(portal.receptacle())
|| !(level.getBlockEntity(portal.receptacle()) instanceof BookReceptacleBlockEntity holder)) return; || !(level.getBlockEntity(portal.receptacle()) instanceof BookReceptacleBlockEntity holder)) return;
ItemStack book = holder.getBook(); ItemStack book = holder.getBook();
if (book.isEmpty()) return; if (book.isEmpty()) return;
PortalTravelCooldown.mark(player, now); PortalTravelCooldown.mark(entity, now);
PortalTravelQueue.enqueue(player, server, pos, portal.receptacle(), book, now); PortalTravelQueue.enqueue(entity, server, pos, portal.receptacle(), book, now);
} }
@Override protected void neighborChanged(BlockState state, Level level, BlockPos pos, Block neighbor, @Override protected void neighborChanged(BlockState state, Level level, BlockPos pos, Block neighbor,
@@ -101,9 +101,14 @@ public final class AgeDimensionService {
public static Optional<LinkTarget> resolve(ServerPlayer player, AgeReference reference, public static Optional<LinkTarget> resolve(ServerPlayer player, AgeReference reference,
OrderedWriting writing, boolean generatePlatform) { OrderedWriting writing, boolean generatePlatform) {
AgeDefinition definition = AgeRegistrySavedData.resolveOrCreate(player.serverLevel(), reference, writing); return resolve(player.serverLevel(), reference, writing, generatePlatform);
if (AgeRegistrySavedData.get(player.serverLevel()).isDead(definition.id())) return Optional.empty(); }
ServerLevel level = ensureLoaded(player.getServer(), definition);
public static Optional<LinkTarget> resolve(ServerLevel source, AgeReference reference,
OrderedWriting writing, boolean generatePlatform) {
AgeDefinition definition = AgeRegistrySavedData.resolveOrCreate(source, reference, writing);
if (AgeRegistrySavedData.get(source).isDead(definition.id())) return Optional.empty();
ServerLevel level = ensureLoaded(source.getServer(), definition);
if (level == null) { if (level == null) {
return Optional.empty(); return Optional.empty();
} }
@@ -0,0 +1,58 @@
package net.dnorberg.rivencraft.book;
import net.dnorberg.rivencraft.mixin.MobDropChanceAccessor;
import net.minecraft.world.Container;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
/** Legacy-style Disarm: leave carried items and eligible equipment at the departure point. */
public final class LinkDisarmService {
private LinkDisarmService() {}
public static boolean mayTravel(Entity entity) {
// Legacy refuses loose items and dropped Link Books on Disarm links.
return !(entity instanceof ItemEntity);
}
public static void disarm(Entity entity) {
if (entity instanceof ServerPlayer player) {
eject(player, player.getInventory());
player.containerMenu.broadcastChanges();
}
if (entity instanceof Container container) eject(entity, container);
if (entity instanceof AbstractHorse horse) eject(entity, horse.getInventory());
if (entity instanceof Mob mob) dropEquipment(mob);
}
private static void eject(Entity carrier, Container inventory) {
for (int slot = 0; slot < inventory.getContainerSize(); slot++) {
ItemStack stack = inventory.getItem(slot);
if (stack.isEmpty()) continue;
inventory.setItem(slot, ItemStack.EMPTY);
carrier.spawnAtLocation(stack);
}
inventory.setChanged();
}
private static void dropEquipment(Mob mob) {
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack stack = mob.getItemBySlot(slot);
if (stack.isEmpty()) continue;
float chance = ((MobDropChanceAccessor) mob).rivencraft$getEquipmentDropChance(slot);
mob.setItemSlot(slot, ItemStack.EMPTY);
if (chance <= 0 || mob.getRandom().nextFloat() >= chance) continue;
if (chance <= 1 && stack.isDamageableItem()) {
int minimum = Math.max(stack.getMaxDamage() - 25, 1);
int damage = stack.getMaxDamage() - mob.getRandom().nextInt(
1 + mob.getRandom().nextInt(minimum));
stack.setDamageValue(Math.clamp(damage, 1, minimum));
}
mob.spawnAtLocation(stack);
}
}
}
@@ -0,0 +1,125 @@
package net.dnorberg.rivencraft.book;
import net.dnorberg.rivencraft.Rivencraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.horse.Donkey;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.Zombie;
import net.minecraft.world.entity.vehicle.MinecartChest;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.gametest.GameTestHolder;
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
@GameTestHolder(Rivencraft.MOD_ID)
@PrefixGameTestTemplate(false)
public final class LinkModifierBehaviorGameTests {
private LinkModifierBehaviorGameTests() {}
@GameTest(template = "empty")
public static void maintainMomentumRotatesToDestinationYaw(GameTestHelper helper) {
Vec3 result = LinkingService.rotatedMomentum(new Vec3(3, -0.5, 4), 90);
helper.assertTrue(Math.abs(result.x) < 0.0001 && Math.abs(result.y + 0.3) < 0.0001
&& Math.abs(result.z - 5) < 0.0001,
"Legacy momentum preserves horizontal speed, rotates to destination yaw, and adds a small lift");
helper.succeed();
}
@GameTest(template = "empty")
public static void disarmRefusesLooseItems(GameTestHelper helper) {
var level = helper.getLevel();
ItemEntity item = new ItemEntity(level, 1, 1, 1, new ItemStack(Items.DIAMOND));
level.addFreshEntity(item);
LinkTarget target = new LinkTarget(GlobalPos.of(level.dimension(), helper.absolutePos(new BlockPos(2, 1, 2))),
0, 0);
helper.assertValueEqual(LinkingService.travelEntityPortal(item, target,
new LinkProperties(LinkProperties.DISARM | LinkProperties.INTRA_LINKING), false),
LinkingService.LinkResult.DISARM_REJECTED,
"Legacy Disarm must refuse a loose item before teleportation");
helper.assertTrue(item.isAlive() && item.getItem().is(Items.DIAMOND),
"Rejected item must remain at the source");
helper.succeed();
}
@GameTest(template = "empty")
public static void ordinaryLinkMovesLooseItemWithoutMakingPlatform(GameTestHelper helper) {
var level = helper.getLevel();
BlockPos landing = helper.absolutePos(new BlockPos(2, 2, 2));
level.setBlock(landing.below(), Blocks.AIR.defaultBlockState(), 2);
level.setBlock(landing, Blocks.AIR.defaultBlockState(), 2);
level.setBlock(landing.above(), Blocks.AIR.defaultBlockState(), 2);
ItemEntity item = new ItemEntity(level, 1, 1, 1, new ItemStack(Items.DIAMOND));
level.addFreshEntity(item);
LinkTarget target = new LinkTarget(GlobalPos.of(level.dimension(), landing), 0, 0);
helper.assertValueEqual(LinkingService.travelEntityPortal(item, target,
new LinkProperties(LinkProperties.INTRA_LINKING), false),
LinkingService.LinkResult.SUCCESS, "Ordinary portal links may carry loose items");
helper.assertTrue(item.blockPosition().distManhattan(landing) <= 1,
"Item must arrive at the linked location");
helper.assertTrue(level.getBlockState(landing.below()).isAir(),
"A Linking Book must not generate a landing platform by default");
helper.succeed();
}
@GameTest(template = "empty")
public static void explicitGeneratePlatformAddsOnlyArrivalFloor(GameTestHelper helper) {
var level = helper.getLevel();
BlockPos landing = helper.absolutePos(new BlockPos(2, 2, 2));
level.setBlock(landing.below(), Blocks.AIR.defaultBlockState(), 2);
level.setBlock(landing, Blocks.AIR.defaultBlockState(), 2);
level.setBlock(landing.above(), Blocks.AIR.defaultBlockState(), 2);
level.setBlock(landing.above(2), Blocks.AIR.defaultBlockState(), 2);
ItemEntity item = new ItemEntity(level, 1, 1, 1, new ItemStack(Items.DIAMOND));
level.addFreshEntity(item);
LinkTarget target = new LinkTarget(GlobalPos.of(level.dimension(), landing), 0, 0);
helper.assertValueEqual(LinkingService.travelEntityPortal(item, target,
new LinkProperties(LinkProperties.INTRA_LINKING | LinkProperties.GENERATE_PLATFORM), false),
LinkingService.LinkResult.SUCCESS, "An explicit platform link must travel");
helper.assertTrue(level.getBlockState(landing.below()).is(
net.dnorberg.rivencraft.registry.ModBlocks.CLOUD_PLATFORM.get()),
"An enabled Linking Book platform must add one cloud block below the arrival");
helper.succeed();
}
@GameTest(template = "empty")
public static void disarmEmptiesCarrierAndMobEquipment(GameTestHelper helper) {
var level = helper.getLevel();
Vec3 source = Vec3.atCenterOf(helper.absolutePos(new BlockPos(1, 1, 1)));
MinecartChest cart = EntityType.CHEST_MINECART.create(level);
Donkey donkey = EntityType.DONKEY.create(level);
Zombie zombie = EntityType.ZOMBIE.create(level);
helper.assertTrue(cart != null && donkey != null && zombie != null, "Carriers must instantiate");
cart.setPos(source);
donkey.setPos(source);
zombie.setPos(source);
level.addFreshEntity(cart);
level.addFreshEntity(donkey);
level.addFreshEntity(zombie);
cart.setItem(0, new ItemStack(Items.EMERALD));
donkey.getInventory().setItem(0, new ItemStack(Items.SADDLE));
zombie.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD));
zombie.setDropChance(EquipmentSlot.MAINHAND, 2.0F);
LinkDisarmService.disarm(cart);
LinkDisarmService.disarm(donkey);
LinkDisarmService.disarm(zombie);
helper.assertTrue(cart.getItem(0).isEmpty() && donkey.getInventory().getItem(0).isEmpty()
&& zombie.getItemBySlot(EquipmentSlot.MAINHAND).isEmpty(),
"Disarm must remove inventory contents and worn equipment");
var drops = level.getEntitiesOfClass(ItemEntity.class, new AABB(source, source).inflate(3));
helper.assertTrue(drops.stream().anyMatch(item -> item.getItem().is(Items.EMERALD))
&& drops.stream().anyMatch(item -> item.getItem().is(Items.SADDLE))
&& drops.stream().anyMatch(item -> item.getItem().is(Items.IRON_SWORD)),
"Carrier items and guaranteed-drop mob equipment must remain at departure");
helper.succeed();
}
}
@@ -11,7 +11,7 @@ import net.minecraft.network.chat.Component;
/** Flags written into a Link Panel and carried by books assembled from it. */ /** Flags written into a Link Panel and carried by books assembled from it. */
public record LinkProperties(int flags) { public record LinkProperties(int flags) {
public static final int DISARM = 1; public static final int DISARM = 1;
/** Retained to read older test books; a newly edited book uses DISABLE_PLATFORM instead. */ /** Linking Books do not create a platform unless this Legacy flag is enabled. */
public static final int GENERATE_PLATFORM = 2; public static final int GENERATE_PLATFORM = 2;
public static final int MAINTAIN_MOMENTUM = 4; public static final int MAINTAIN_MOMENTUM = 4;
public static final int INTRA_LINKING = 8; public static final int INTRA_LINKING = 8;
@@ -48,6 +48,7 @@ public record LinkProperties(int flags) {
if (has(INTRA_LINKING)) lines.add(propertyName("intra_linking")); if (has(INTRA_LINKING)) lines.add(propertyName("intra_linking"));
if (has(INTRA_LINKING_ONLY)) lines.add(propertyName("intra_linking_only")); if (has(INTRA_LINKING_ONLY)) lines.add(propertyName("intra_linking_only"));
if (has(RELATIVE_LINK)) lines.add(propertyName("relative_link")); if (has(RELATIVE_LINK)) lines.add(propertyName("relative_link"));
if (has(GENERATE_PLATFORM)) lines.add(propertyName("generate_platform"));
if (has(DISABLE_PLATFORM)) lines.add(propertyName("disable_platform")); if (has(DISABLE_PLATFORM)) lines.add(propertyName("disable_platform"));
} }
@@ -63,6 +64,7 @@ public record LinkProperties(int flags) {
case INTRA_LINKING -> propertyName("intra_linking"); case INTRA_LINKING -> propertyName("intra_linking");
case INTRA_LINKING_ONLY -> propertyName("intra_linking_only"); case INTRA_LINKING_ONLY -> propertyName("intra_linking_only");
case RELATIVE_LINK -> propertyName("relative_link"); case RELATIVE_LINK -> propertyName("relative_link");
case GENERATE_PLATFORM -> propertyName("generate_platform");
case DISABLE_PLATFORM -> propertyName("disable_platform"); case DISABLE_PLATFORM -> propertyName("disable_platform");
default -> throw new IllegalArgumentException("Unknown link property flag: " + flag); default -> throw new IllegalArgumentException("Unknown link property flag: " + flag);
}; };
@@ -6,16 +6,20 @@ import java.util.stream.IntStream;
import java.util.stream.Stream; import java.util.stream.Stream;
import net.dnorberg.rivencraft.compat.ImmersivePortalsChunkLoaders; import net.dnorberg.rivencraft.compat.ImmersivePortalsChunkLoaders;
import net.dnorberg.rivencraft.entity.DroppedBookEntity; import net.dnorberg.rivencraft.entity.DroppedBookEntity;
import net.dnorberg.rivencraft.portal.PortalTravelCooldown;
import net.dnorberg.rivencraft.registry.ModBlocks;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.border.WorldBorder; import net.minecraft.world.level.border.WorldBorder;
import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraft.world.level.portal.DimensionTransition;
import net.neoforged.fml.ModList; import net.neoforged.fml.ModList;
/** Server-side validation and execution for book travel. */ /** Server-side validation and execution for book travel. */
@@ -96,9 +100,9 @@ public final class LinkingService {
Vec3 position = destination.get(); Vec3 position = destination.get();
Vec3 momentum = player.getDeltaMovement(); Vec3 momentum = player.getDeltaMovement();
if (properties.has(LinkProperties.DISARM)) dropInventoryAtSource(player); if (properties.has(LinkProperties.DISARM)) LinkDisarmService.disarm(player);
teleport(player, destinationLevel, position, target, true); teleport(player, destinationLevel, position, target, true);
if (properties.has(LinkProperties.MAINTAIN_MOMENTUM)) player.setDeltaMovement(momentum); applyMomentum(player, momentum, target, properties);
player.resetFallDistance(); player.resetFallDistance();
return LinkResult.SUCCESS; return LinkResult.SUCCESS;
} }
@@ -114,9 +118,9 @@ public final class LinkingService {
landingOrigin(player, destinationLevel, target, properties), true); landingOrigin(player, destinationLevel, target, properties), true);
if (destination.isEmpty()) return LinkResult.NO_SAFE_DESTINATION; if (destination.isEmpty()) return LinkResult.NO_SAFE_DESTINATION;
Vec3 momentum = player.getDeltaMovement(); Vec3 momentum = player.getDeltaMovement();
if (properties.has(LinkProperties.DISARM)) dropInventoryAtSource(player); if (properties.has(LinkProperties.DISARM)) LinkDisarmService.disarm(player);
teleport(player, destinationLevel, destination.get(), target, instant); teleport(player, destinationLevel, destination.get(), target, instant);
if (properties.has(LinkProperties.MAINTAIN_MOMENTUM)) player.setDeltaMovement(momentum); applyMomentum(player, momentum, target, properties);
player.resetFallDistance(); player.resetFallDistance();
return LinkResult.SUCCESS; return LinkResult.SUCCESS;
} }
@@ -142,36 +146,80 @@ public final class LinkingService {
Vec3 position = destination.get(); Vec3 position = destination.get();
Vec3 momentum = player.getDeltaMovement(); Vec3 momentum = player.getDeltaMovement();
if (properties.has(LinkProperties.DISARM)) dropInventoryAtSource(player); if (properties.has(LinkProperties.DISARM)) LinkDisarmService.disarm(player);
teleport(player, destinationLevel, position, target, instant); teleport(player, destinationLevel, position, target, instant);
if (properties.has(LinkProperties.MAINTAIN_MOMENTUM)) player.setDeltaMovement(momentum); if (properties.has(LinkProperties.GENERATE_PLATFORM))
generateArrivalPlatform(destinationLevel, position);
applyMomentum(player, momentum, target, properties);
player.resetFallDistance(); player.resetFallDistance();
return LinkResult.SUCCESS; return LinkResult.SUCCESS;
} }
/** Non-player portal travel follows the same link rules; Disarm may remove carried cargo. */
public static LinkResult travelEntityPortal(Entity entity, LinkTarget target,
LinkProperties properties, boolean requiresFooting) {
if (!(entity.level() instanceof ServerLevel source)) return LinkResult.MISSING_DIMENSION;
ServerLevel destinationLevel = source.getServer().getLevel(target.location().dimension());
if (destinationLevel == null) return LinkResult.MISSING_DIMENSION;
if (properties.has(LinkProperties.INTRA_LINKING_ONLY) && destinationLevel != source)
return LinkResult.INTRA_ONLY;
if (destinationLevel == source && !properties.has(LinkProperties.INTRA_LINKING)
&& !properties.has(LinkProperties.INTRA_LINKING_ONLY)) return LinkResult.INTRA_LINKING_REQUIRED;
if (properties.has(LinkProperties.DISARM) && !LinkDisarmService.mayTravel(entity))
return LinkResult.DISARM_REJECTED;
if (!entity.canChangeDimensions(source, destinationLevel)) return LinkResult.NO_SAFE_DESTINATION;
BlockPos origin = landingOrigin(entity, destinationLevel, target, properties);
Optional<Vec3> destination = resolveDestination(destinationLevel, origin, requiresFooting);
if (destination.isEmpty()) return LinkResult.NO_SAFE_DESTINATION;
Vec3 momentum = entity.getDeltaMovement();
if (properties.has(LinkProperties.DISARM)) LinkDisarmService.disarm(entity);
Entity arrived = entity.changeDimension(new DimensionTransition(destinationLevel, destination.get(),
properties.has(LinkProperties.MAINTAIN_MOMENTUM)
? rotatedMomentum(momentum, target.yaw()) : Vec3.ZERO,
target.yaw(), target.pitch(), DimensionTransition.DO_NOTHING));
if (arrived == null) return LinkResult.NO_SAFE_DESTINATION;
if (!requiresFooting && properties.has(LinkProperties.GENERATE_PLATFORM))
generateArrivalPlatform(destinationLevel, destination.get());
arrived.setXRot(target.pitch());
arrived.resetFallDistance();
PortalTravelCooldown.mark(arrived, source.getServer().getTickCount());
return LinkResult.SUCCESS;
}
static Vec3 rotatedMomentum(Vec3 incoming, float destinationYaw) {
// Legacy rotates the horizontal speed to the destination yaw and adds a small upward lift.
double horizontalSpeed = Math.hypot(incoming.x, incoming.z);
double radians = Math.toRadians(destinationYaw);
return new Vec3(horizontalSpeed * Math.cos(radians), incoming.y + 0.2,
horizontalSpeed * Math.sin(radians));
}
private static void applyMomentum(ServerPlayer player, Vec3 incoming, LinkTarget target,
LinkProperties properties) {
player.setDeltaMovement(properties.has(LinkProperties.MAINTAIN_MOMENTUM)
? rotatedMomentum(incoming, target.yaw()) : Vec3.ZERO);
}
private static void generateArrivalPlatform(ServerLevel level, Vec3 arrival) {
BlockPos feet = BlockPos.containing(arrival);
BlockPos floor = feet.below();
// Legacy only fills a missing floor when there is clear space above the arrival.
if (level.isEmptyBlock(floor) && level.isEmptyBlock(feet.above(2)))
level.setBlock(floor, ModBlocks.CLOUD_PLATFORM.get().defaultBlockState(), 3);
}
/** Legacy relative links retain the traveller's offset from the source spawn. */ /** Legacy relative links retain the traveller's offset from the source spawn. */
private static BlockPos landingOrigin(ServerPlayer player, ServerLevel destinationLevel, private static BlockPos landingOrigin(Entity player, ServerLevel destinationLevel,
LinkTarget target, LinkProperties properties) { LinkTarget target, LinkProperties properties) {
if (!properties.has(LinkProperties.RELATIVE_LINK)) return target.location().pos(); if (!properties.has(LinkProperties.RELATIVE_LINK)) return target.location().pos();
BlockPos sourceSpawn = player.serverLevel().getSharedSpawnPos(); BlockPos sourceSpawn = ((ServerLevel) player.level()).getSharedSpawnPos();
BlockPos destinationSpawn = destinationLevel.getSharedSpawnPos(); BlockPos destinationSpawn = destinationLevel.getSharedSpawnPos();
BlockPos departure = player.blockPosition(); BlockPos departure = player.blockPosition();
return destinationSpawn.offset(departure.getX() - sourceSpawn.getX(), return destinationSpawn.offset(departure.getX() - sourceSpawn.getX(),
departure.getY() - sourceSpawn.getY(), departure.getZ() - sourceSpawn.getZ()); departure.getY() - sourceSpawn.getY(), departure.getZ() - sourceSpawn.getZ());
} }
/** 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,
@@ -285,6 +333,7 @@ public final class LinkingService {
MISSING_DIMENSION, MISSING_DIMENSION,
INTRA_LINKING_REQUIRED, INTRA_LINKING_REQUIRED,
INTRA_ONLY, INTRA_ONLY,
DISARM_REJECTED,
NO_SAFE_DESTINATION NO_SAFE_DESTINATION
} }
} }
@@ -196,7 +196,7 @@ public final class SymbolPageTextures {
graphics.setColor(1F, 1F, 1F, 1F); graphics.setColor(1F, 1F, 1F, 1F);
} }
/** Legacy's single-number marks; numbers above 24 use positional base 25. */ /** Overlay each Legacy digit's components; place base-25 digits side by side. */
public static void drawNumeral(GuiGraphics graphics, int number, int x, int y, int size) { public static void drawNumeral(GuiGraphics graphics, int number, int x, int y, int size) {
int[] digits = SymbolNumerals.digitsFor(number); int[] digits = SymbolNumerals.digitsFor(number);
int digitSize = digits.length == 1 ? size : Math.max(8, size * 3 / 4); int digitSize = digits.length == 1 ? size : Math.max(8, size * 3 / 4);
@@ -6,6 +6,7 @@ import net.dnorberg.rivencraft.menu.LinkModifierMenu;
import net.dnorberg.rivencraft.network.SetLinkModifierTitlePayload; import net.dnorberg.rivencraft.network.SetLinkModifierTitlePayload;
import net.dnorberg.rivencraft.network.SetLinkModifierSeedPayload; import net.dnorberg.rivencraft.network.SetLinkModifierSeedPayload;
import net.dnorberg.rivencraft.registry.ModDataComponents; import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModItems;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.components.Tooltip;
@@ -137,9 +138,12 @@ public final class LinkModifierScreen extends AbstractContainerScreen<LinkModifi
@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); graphics.blit(BACKGROUND, leftPos, topPos, 0, 0, imageWidth, imageHeight, 256, 256);
LinkProperties properties = menu.book().getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE); LinkProperties properties = menu.book().getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE);
for (int index = 0; index < FLAGS.length; index++) for (int index = 0; index < FLAGS.length; index++) {
boolean selected = FLAGS[index] == LinkProperties.DISABLE_PLATFORM
? platformEnabled(properties) : properties.has(FLAGS[index]);
square(graphics, 5 + (index / 3) * 20, 10 + (index % 3) * 20, square(graphics, 5 + (index / 3) * 20, 10 + (index % 3) * 20,
properties.has(FLAGS[index]), false); selected, false);
}
if (menu.canDelete(minecraft.player)) { if (menu.canDelete(minecraft.player)) {
square(graphics, 120, 32, menu.awaitingDeletionConfirmation(), false); square(graphics, 120, 32, menu.awaitingDeletionConfirmation(), false);
if (menu.awaitingDeletionConfirmation()) square(graphics, 140, 32, false, true); if (menu.awaitingDeletionConfirmation()) square(graphics, 140, 32, false, true);
@@ -166,8 +170,8 @@ public final class LinkModifierScreen extends AbstractContainerScreen<LinkModifi
if (inside(mouseX, mouseY, 5 + (index / 3) * 20, 10 + (index % 3) * 20, 18, 18)) { if (inside(mouseX, mouseY, 5 + (index / 3) * 20, 10 + (index % 3) * 20, 18, 18)) {
Component label = FLAGS[index] == LinkProperties.DISABLE_PLATFORM Component label = FLAGS[index] == LinkProperties.DISABLE_PLATFORM
? Component.literal("Generate Platform: " ? Component.literal("Generate Platform: "
+ (menu.book().getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE) + (platformEnabled(menu.book().getOrDefault(ModDataComponents.LINK_PROPERTIES.get(),
.has(LinkProperties.DISABLE_PLATFORM) ? "Off" : "On")) LinkProperties.NONE)) ? "On" : "Off"))
: LinkProperties.name(FLAGS[index]); : LinkProperties.name(FLAGS[index]);
graphics.renderTooltip(font, label, mouseX, mouseY); graphics.renderTooltip(font, label, mouseX, mouseY);
return; return;
@@ -180,4 +184,10 @@ public final class LinkModifierScreen extends AbstractContainerScreen<LinkModifi
? "screen.rivencraft.link_modifier.confirm" : "screen.rivencraft.link_modifier.retire"), ? "screen.rivencraft.link_modifier.confirm" : "screen.rivencraft.link_modifier.retire"),
mouseX, mouseY); mouseX, mouseY);
} }
private boolean platformEnabled(LinkProperties properties) {
return menu.book().is(ModItems.LINKING_BOOK.get())
? properties.has(LinkProperties.GENERATE_PLATFORM)
: !properties.has(LinkProperties.DISABLE_PLATFORM);
}
} }
@@ -151,8 +151,8 @@ public final class WritingDeskScreen extends AbstractContainerScreen<WritingDesk
if (tab == menu.activeCollection() && !allMode) graphics.setColor(0.5F, 0.5F, 1F, 1F); if (tab == menu.activeCollection() && !allMode) graphics.setColor(0.5F, 0.5F, 1F, 1F);
graphics.blit(LEGACY_DESK, x, tabY, 0, 166, 58, 37); graphics.blit(LEGACY_DESK, x, tabY, 0, 166, 58, 37);
graphics.setColor(1F, 1F, 1F, 1F); graphics.setColor(1F, 1F, 1F, 1F);
// Encode the visible one-based tab number with Legacy's numeric word glyph. // Legacy numbers its Writing Desk collections from zero.
SymbolPageTextures.drawNumeral(graphics, tab + 1, x + 8, tabY + 3, 19); SymbolPageTextures.drawNumeral(graphics, tab, x + (tab < 25 ? 8 : 4), tabY + 3, 19);
ItemStack collection = menu.getSlot(tab).getItem(); ItemStack collection = menu.getSlot(tab).getItem();
if (!collection.isEmpty()) { if (!collection.isEmpty()) {
String name = collection.getHoverName().getString(); String name = collection.getHoverName().getString();
@@ -227,7 +227,7 @@ public final class WritingDeskScreen extends AbstractContainerScreen<WritingDesk
else if (mouseX < leftPos + 34 && localY >= 29 && localY < 177) { else if (mouseX < leftPos + 34 && localY >= 29 && localY < 177) {
int tab = menu.firstVisibleTab() + (localY - 29) / 37; int tab = menu.firstVisibleTab() + (localY - 29) / 37;
graphics.renderTooltip(font, Component.translatable("screen.rivencraft.writing_desk.tab_symbol", graphics.renderTooltip(font, Component.translatable("screen.rivencraft.writing_desk.tab_symbol",
tab + 1), mouseX, mouseY); tab), mouseX, mouseY);
} }
} }
} }
@@ -151,11 +151,23 @@ public final class WritingDataGameTests {
"Zero must use Legacy's dedicated number mark"); "Zero must use Legacy's dedicated number mark");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(1), new int[] {56}), helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(1), new int[] {56}),
"One must use Legacy's first bottom-row mark"); "One must use Legacy's first bottom-row mark");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(5), new int[] {60}),
"Five must use Legacy's first five-step mark");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(10), new int[] {61}),
"Ten must use Legacy's second five-step mark");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(14), new int[] {61, 59}),
"Fourteen must overlay the ten and four marks");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(20), new int[] {63}),
"Twenty must use Legacy's final five-step mark");
helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(24), new int[] {63, 59}), helper.assertTrue(Arrays.equals(SymbolNumerals.componentsForDigit(24), new int[] {63, 59}),
"Twenty-four must combine Legacy's five and unit marks"); "Twenty-four must combine Legacy's five and unit marks");
helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(25), new int[] {1, 0}), helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(25), new int[] {1, 0}),
"Twenty-five must start a second base-25 place"); "Twenty-five must start a second base-25 place");
helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(88), new int[] {3, 13}), helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(49), new int[] {1, 24}),
"Forty-nine must use twenty-four in its ones place");
helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(50), new int[] {2, 0}),
"Fifty must carry into the second base-25 place");
helper.assertTrue(Arrays.equals(SymbolNumerals.digitsFor(87), new int[] {3, 12}),
"Last writing-desk tab must retain its numeric value"); "Last writing-desk tab must retain its numeric value");
String display = "\"name\":\"symbol.example.test\"," String display = "\"name\":\"symbol.example.test\","
@@ -142,7 +142,8 @@ public final class LinkModifierMenu extends AbstractContainerMenu {
case TOGGLE_INTRA -> LinkProperties.INTRA_LINKING; case TOGGLE_INTRA -> LinkProperties.INTRA_LINKING;
case TOGGLE_INTRA_ONLY -> LinkProperties.INTRA_LINKING_ONLY; case TOGGLE_INTRA_ONLY -> LinkProperties.INTRA_LINKING_ONLY;
case TOGGLE_RELATIVE -> LinkProperties.RELATIVE_LINK; case TOGGLE_RELATIVE -> LinkProperties.RELATIVE_LINK;
case TOGGLE_PLATFORM -> LinkProperties.DISABLE_PLATFORM; case TOGGLE_PLATFORM -> book().is(ModItems.LINKING_BOOK.get())
? LinkProperties.GENERATE_PLATFORM : LinkProperties.DISABLE_PLATFORM;
default -> 0; default -> 0;
}; };
if (flag == 0 || ((flag == LinkProperties.INTRA_LINKING || flag == LinkProperties.INTRA_LINKING_ONLY) if (flag == 0 || ((flag == LinkProperties.INTRA_LINKING || flag == LinkProperties.INTRA_LINKING_ONLY)
@@ -0,0 +1,12 @@
package net.dnorberg.rivencraft.mixin;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(Mob.class)
public interface MobDropChanceAccessor {
@Invoker("getEquipmentDropChance")
float rivencraft$getEquipmentDropChance(EquipmentSlot slot);
}
@@ -2,12 +2,13 @@ package net.dnorberg.rivencraft.portal;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
/** Session-only portal cooldowns: tick counters must never be saved with players. */ /** Session-only portal cooldowns: tick counters must never be saved with players. */
public final class PortalTravelCooldown { public final class PortalTravelCooldown {
public static final long TICKS = 40; public static final long TICKS = 40;
private static final Map<ServerPlayer, Long> LAST_USE = new WeakHashMap<>(); private static final Map<Entity, Long> LAST_USE = new WeakHashMap<>();
private PortalTravelCooldown() {} private PortalTravelCooldown() {}
@@ -15,16 +16,16 @@ public final class PortalTravelCooldown {
return previous >= 0 && now >= previous && now - previous < TICKS; return previous >= 0 && now >= previous && now - previous < TICKS;
} }
public static boolean blocked(ServerPlayer player, long now) { public static boolean blocked(Entity entity, long now) {
return blocked(now, LAST_USE.getOrDefault(player, -1L)); return blocked(now, LAST_USE.getOrDefault(entity, -1L));
} }
public static void mark(ServerPlayer player, long now) { public static void mark(Entity entity, long now) {
LAST_USE.put(player, now); LAST_USE.put(entity, now);
} }
public static void forget(ServerPlayer player) { public static void forget(Entity entity) {
LAST_USE.remove(player); LAST_USE.remove(entity);
} }
public static void clear() { public static void clear() {
@@ -7,34 +7,43 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import net.dnorberg.rivencraft.block.entity.BookReceptacleBlockEntity; import net.dnorberg.rivencraft.block.entity.BookReceptacleBlockEntity;
import net.dnorberg.rivencraft.block.entity.CrystalPortalBlockEntity; import net.dnorberg.rivencraft.block.entity.CrystalPortalBlockEntity;
import net.dnorberg.rivencraft.book.AgeDimensionService;
import net.dnorberg.rivencraft.book.AgeReference;
import net.dnorberg.rivencraft.book.LinkDisarmService;
import net.dnorberg.rivencraft.book.LinkProperties;
import net.dnorberg.rivencraft.book.LinkTarget;
import net.dnorberg.rivencraft.book.LinkingService;
import net.dnorberg.rivencraft.item.DescriptiveBookItem; import net.dnorberg.rivencraft.item.DescriptiveBookItem;
import net.dnorberg.rivencraft.item.LinkingBookItem; import net.dnorberg.rivencraft.item.LinkingBookItem;
import net.dnorberg.rivencraft.registry.ModDataComponents;
import net.dnorberg.rivencraft.registry.ModItems; import net.dnorberg.rivencraft.registry.ModItems;
import net.dnorberg.rivencraft.writing.OrderedWriting;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
/** Defers block-collision travel until the movement packet that entered the portal has finished. */ /** Defers block-collision travel until the movement packet that entered the portal has finished. */
public final class PortalTravelQueue { public final class PortalTravelQueue {
private static final Map<ServerPlayer, Pending> PENDING = new IdentityHashMap<>(); private static final Map<Entity, Pending> PENDING = new IdentityHashMap<>();
private record Pending(ServerLevel source, BlockPos portal, BlockPos receptacle, private record Pending(ServerLevel source, BlockPos portal, BlockPos receptacle,
ItemStack book, long queuedTick) {} ItemStack book, long queuedTick) {}
private record Travel(ServerPlayer player, Pending pending) {} private record Travel(Entity entity, Pending pending) {}
private PortalTravelQueue() {} private PortalTravelQueue() {}
public static void enqueue(ServerPlayer player, ServerLevel source, BlockPos portal, public static void enqueue(Entity entity, ServerLevel source, BlockPos portal,
BlockPos receptacle, ItemStack book, long now) { BlockPos receptacle, ItemStack book, long now) {
PENDING.putIfAbsent(player, new Pending(source, portal.immutable(), receptacle.immutable(), PENDING.putIfAbsent(entity, new Pending(source, portal.immutable(), receptacle.immutable(),
book.copyWithCount(1), now)); book.copyWithCount(1), now));
} }
public static void process(MinecraftServer server) { public static void process(MinecraftServer server) {
List<Travel> ready = new ArrayList<>(); List<Travel> ready = new ArrayList<>();
Iterator<Map.Entry<ServerPlayer, Pending>> iterator = PENDING.entrySet().iterator(); Iterator<Map.Entry<Entity, Pending>> iterator = PENDING.entrySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
var entry = iterator.next(); var entry = iterator.next();
if (server.getTickCount() <= entry.getValue().queuedTick()) continue; if (server.getTickCount() <= entry.getValue().queuedTick()) continue;
@@ -44,21 +53,45 @@ public final class PortalTravelQueue {
// Travel can itself cause block-collision callbacks, so do not keep an // Travel can itself cause block-collision callbacks, so do not keep an
// iterator over the pending map while changing the player's dimension. // iterator over the pending map while changing the player's dimension.
for (Travel travel : ready) { for (Travel travel : ready) {
ServerPlayer player = travel.player(); Entity entity = travel.entity();
Pending pending = travel.pending(); Pending pending = travel.pending();
if (server.getPlayerList().getPlayer(player.getUUID()) != player if ((entity instanceof ServerPlayer player
|| !player.isAlive() || player.serverLevel() != pending.source() && server.getPlayerList().getPlayer(player.getUUID()) != player)
|| entity.isRemoved() || !entity.isAlive() || entity.level() != pending.source()
|| !(pending.source().getBlockEntity(pending.portal()) instanceof CrystalPortalBlockEntity portal) || !(pending.source().getBlockEntity(pending.portal()) instanceof CrystalPortalBlockEntity portal)
|| !pending.receptacle().equals(portal.receptacle()) || !pending.receptacle().equals(portal.receptacle())
|| !(pending.source().getBlockEntity(pending.receptacle()) instanceof BookReceptacleBlockEntity holder) || !(pending.source().getBlockEntity(pending.receptacle()) instanceof BookReceptacleBlockEntity holder)
|| !ItemStack.isSameItemSameComponents(holder.getBook(), pending.book())) continue; || !ItemStack.isSameItemSameComponents(holder.getBook(), pending.book())) continue;
if (pending.book().is(ModItems.LINKING_BOOK.get())) if (entity instanceof ServerPlayer player) {
LinkingBookItem.usePortalBook(player, pending.book()); if (pending.book().is(ModItems.LINKING_BOOK.get()))
else if (pending.book().is(ModItems.DESCRIPTIVE_BOOK.get())) LinkingBookItem.usePortalBook(player, pending.book());
DescriptiveBookItem.usePortalBook(player, pending.book()); else if (pending.book().is(ModItems.DESCRIPTIVE_BOOK.get()))
DescriptiveBookItem.usePortalBook(player, pending.book());
} else {
travelEntity(entity, pending);
}
} }
} }
private static void travelEntity(Entity entity, Pending pending) {
ItemStack book = pending.book();
LinkProperties properties = book.getOrDefault(ModDataComponents.LINK_PROPERTIES.get(), LinkProperties.NONE);
if (properties.has(LinkProperties.DISARM) && !LinkDisarmService.mayTravel(entity)) return;
LinkTarget target;
boolean descriptive = book.is(ModItems.DESCRIPTIVE_BOOK.get());
if (descriptive) {
AgeReference reference = book.get(ModDataComponents.AGE_REFERENCE.get());
if (reference == null) return;
properties = properties.forDescriptiveBook();
target = AgeDimensionService.resolve(pending.source(), reference, OrderedWriting.EMPTY,
!properties.has(LinkProperties.DISABLE_PLATFORM)).orElse(null);
} else if (book.is(ModItems.LINKING_BOOK.get())) {
target = book.get(ModDataComponents.LINK_TARGET.get());
} else return;
if (target == null) return;
LinkingService.travelEntityPortal(entity, target, properties, descriptive);
}
public static void forget(ServerPlayer player) { PENDING.remove(player); } public static void forget(ServerPlayer player) { PENDING.remove(player); }
public static void clear() { PENDING.clear(); } public static void clear() { PENDING.clear(); }
} }
@@ -1,8 +1,8 @@
package net.dnorberg.rivencraft.writing; package net.dnorberg.rivencraft.writing;
/** /**
* Number components from Mystcraft Legacy's ModWords#constructNumber. * Positional base-25 numerals using Mystcraft Legacy's 0–24 digit components.
* Legacy registers 0–25; larger Rivencraft tab numbers use positional base 25. * Components within one digit are layered in the same square, not laid side by side.
*/ */
public final class SymbolNumerals { public final class SymbolNumerals {
private SymbolNumerals() {} private SymbolNumerals() {}
@@ -19,7 +19,7 @@ public final class SymbolNumerals {
} }
public static int[] componentsForDigit(int digit) { public static int[] componentsForDigit(int digit) {
if (digit < 0 || digit >= 25) throw new IllegalArgumentException("Numeral digit must be in [0, 24]"); if (digit < 0 || digit >= 25) throw new IllegalArgumentException("Base-25 digit must be in [0, 24]");
if (digit == 0) return new int[] {1}; if (digit == 0) return new int[] {1};
int fifths = digit / 5; int fifths = digit / 5;
int remainder = digit % 5; int remainder = digit % 5;
@@ -18,6 +18,7 @@
"item.rivencraft.link_property.intra_linking_only": "Intra-Linking Only", "item.rivencraft.link_property.intra_linking_only": "Intra-Linking Only",
"item.rivencraft.link_property.relative_link": "Relative Link", "item.rivencraft.link_property.relative_link": "Relative Link",
"item.rivencraft.link_property.disable_platform": "Generate Platform: Off", "item.rivencraft.link_property.disable_platform": "Generate Platform: Off",
"item.rivencraft.link_property.generate_platform": "Generate Platform: On",
"item.rivencraft.page.unresolved": "Unresolved Symbol Page", "item.rivencraft.page.unresolved": "Unresolved Symbol Page",
"item.rivencraft.notebook": "Notebook", "item.rivencraft.notebook": "Notebook",
"item.rivencraft.collation_folder": "Collation Folder", "item.rivencraft.collation_folder": "Collation Folder",
@@ -7,6 +7,7 @@
"AgeDimensionSeedMixin", "AgeDimensionSeedMixin",
"AgeDungeonPlacementMixin", "AgeDungeonPlacementMixin",
"AgeStructureBiomeMixin", "AgeStructureBiomeMixin",
"MobDropChanceAccessor",
"StructurePlacementAccessor" "StructurePlacementAccessor"
], ],
"client": [ "client": [