Public Access
This commit is contained in:
1 parent
cd3a99fa78
commit
0e602f0154
6 files changed
+54
-4
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package net.dnorberg.rivencraft.book;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
|
||||
/**
|
||||
* Stable identity for an Age, independent of its eventual dimension key.
|
||||
*
|
||||
* <p>Milestone 3 will resolve this identifier through server-owned Age data.
|
||||
* Books only retain the identifier so dimension regeneration or migration does
|
||||
* not invalidate every existing book.</p>
|
||||
*/
|
||||
public record AgeReference(UUID id) {
|
||||
public static final Codec<AgeReference> CODEC = UUIDUtil.STRING_CODEC.xmap(AgeReference::new, AgeReference::id);
|
||||
public static final StreamCodec<ByteBuf, AgeReference> STREAM_CODEC = StreamCodec.composite(
|
||||
UUIDUtil.STREAM_CODEC,
|
||||
AgeReference::id,
|
||||
AgeReference::new
|
||||
);
|
||||
|
||||
public String shortId() {
|
||||
return id.toString().substring(0, 8);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package net.dnorberg.rivencraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import net.dnorberg.rivencraft.book.AgeReference;
|
||||
import net.dnorberg.rivencraft.registry.ModDataComponents;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
@@ -19,6 +22,11 @@ public final class DescriptiveBookItem extends Item {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoil(ItemStack stack) {
|
||||
return stack.has(ModDataComponents.AGE_REFERENCE.get()) || super.isFoil(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(
|
||||
ItemStack stack,
|
||||
@@ -26,7 +34,10 @@ public final class DescriptiveBookItem extends Item {
|
||||
List<Component> tooltipComponents,
|
||||
TooltipFlag tooltipFlag
|
||||
) {
|
||||
tooltipComponents.add(Component.translatable("item.rivencraft.descriptive_book.unwritten")
|
||||
.withStyle(ChatFormatting.GRAY));
|
||||
AgeReference age = stack.get(ModDataComponents.AGE_REFERENCE.get());
|
||||
MutableComponent status = age == null
|
||||
? Component.translatable("item.rivencraft.descriptive_book.unwritten")
|
||||
: Component.translatable("item.rivencraft.descriptive_book.age", age.shortId());
|
||||
tooltipComponents.add(status.withStyle(ChatFormatting.GRAY));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.dnorberg.rivencraft.registry;
|
||||
|
||||
import net.dnorberg.rivencraft.Rivencraft;
|
||||
import net.dnorberg.rivencraft.book.LinkTarget;
|
||||
import net.dnorberg.rivencraft.book.AgeReference;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
@@ -18,6 +19,12 @@ public final class ModDataComponents {
|
||||
.networkSynchronized(LinkTarget.STREAM_CODEC)
|
||||
.cacheEncoding()
|
||||
.build());
|
||||
public static final DeferredHolder<DataComponentType<?>, DataComponentType<AgeReference>> AGE_REFERENCE =
|
||||
DATA_COMPONENTS.register("age_reference", () -> DataComponentType.<AgeReference>builder()
|
||||
.persistent(AgeReference.CODEC)
|
||||
.networkSynchronized(AgeReference.STREAM_CODEC)
|
||||
.cacheEncoding()
|
||||
.build());
|
||||
|
||||
private ModDataComponents() {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"item.rivencraft.descriptive_book": "Descriptive Book",
|
||||
"item.rivencraft.descriptive_book.unwritten": "Unwritten",
|
||||
"item.rivencraft.descriptive_book.age": "Age %s",
|
||||
"item.rivencraft.linking_book": "Linking Book",
|
||||
"item.rivencraft.linking_book.unbound": "Unbound — sneak-use to bind",
|
||||
"item.rivencraft.linking_book.destination": "%s (%s, %s, %s)",
|
||||
|
||||
Reference in new issue
Block a user