Mojang Mappings

This commit is contained in:
skippyall
2026-04-29 08:51:37 +02:00
parent cc9fedd63b
commit f5202a4264
140 changed files with 1646 additions and 1675 deletions
@@ -4,18 +4,17 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.skippyall.minions.registration.MinionRegistries;
import net.minecraft.dialog.body.DialogBody;
import net.minecraft.registry.DynamicRegistryManager;
import java.util.List;
import java.util.function.Function;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.dialog.body.DialogBody;
public interface DocsEntry {
Codec<DocsEntry> CODEC = MinionRegistries.DOCS_ENTRY_TYPES.getCodec().dispatch(DocsEntry::getCodec, Function.identity());
Codec<DocsEntry> CODEC = MinionRegistries.DOCS_ENTRY_TYPES.byNameCodec().dispatch(DocsEntry::getCodec, Function.identity());
Metadata getMetadata();
List<DialogBody> getDialog(DynamicRegistryManager manager);
List<DialogBody> getDialog(RegistryAccess manager);
MapCodec<? extends DocsEntry> getCodec();
@@ -4,22 +4,21 @@ import com.google.gson.JsonParseException;
import com.mojang.serialization.JsonOps;
import io.github.skippyall.minions.Minions;
import net.fabricmc.fabric.api.resource.SimpleResourceReloadListener;
import net.minecraft.dialog.AfterAction;
import net.minecraft.dialog.DialogActionButtonData;
import net.minecraft.dialog.DialogButtonData;
import net.minecraft.dialog.DialogCommonData;
import net.minecraft.dialog.action.SimpleDialogAction;
import net.minecraft.dialog.type.MultiActionDialog;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.dialog.ActionButton;
import net.minecraft.server.dialog.CommonButtonData;
import net.minecraft.server.dialog.CommonDialogData;
import net.minecraft.server.dialog.DialogAction;
import net.minecraft.server.dialog.MultiActionDialog;
import net.minecraft.server.dialog.action.StaticAction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.StrictJsonParser;
import net.minecraft.util.Tuple;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
@@ -31,46 +30,46 @@ import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
public class DocsManager implements SimpleResourceReloadListener<Pair<Map<Identifier, DocsEntry>, DocsTree>> {
private static Map<Identifier, DocsEntry> docs;
public class DocsManager implements SimpleResourceReloadListener<Tuple<Map<ResourceLocation, DocsEntry>, DocsTree>> {
private static Map<ResourceLocation, DocsEntry> docs;
private static DocsTree tree;
public static DocsTree getTree() {
return tree;
}
public static void showDocsEntry(ServerPlayerEntity player, Identifier id) {
public static void showDocsEntry(ServerPlayer player, ResourceLocation id) {
DocsEntry entry = getDocsEntry(id);
if(entry == null) {
return;
}
List<DialogActionButtonData> buttons = new ArrayList<>();
List<ActionButton> buttons = new ArrayList<>();
if(tree != null) {
DocsTree.DocElement element = tree.getElement(id);
if (element.previous() != null) {
Identifier previousId = element.previous().getId();
buttons.add(getDialogButton(Text.literal("<- ").append(Text.translatable(getDocsEntry(previousId).getMetadata().titleKey())), previousId.toString()));
ResourceLocation previousId = element.previous().getId();
buttons.add(getDialogButton(Component.literal("<- ").append(Component.translatable(getDocsEntry(previousId).getMetadata().titleKey())), previousId.toString()));
}
if (element.next() != null) {
Identifier nextId = element.next().getId();
buttons.add(getDialogButton(Text.translatable(getDocsEntry(nextId).getMetadata().titleKey()).append(Text.literal(" ->")), nextId.toString()));
ResourceLocation nextId = element.next().getId();
buttons.add(getDialogButton(Component.translatable(getDocsEntry(nextId).getMetadata().titleKey()).append(Component.literal(" ->")), nextId.toString()));
}
}
buttons.add(new DialogActionButtonData(
new DialogButtonData(Text.translatable("gui.ok"), 100),
buttons.add(new ActionButton(
new CommonButtonData(Component.translatable("gui.ok"), 100),
Optional.empty()
));
player.openDialog(RegistryEntry.of(new MultiActionDialog(
new DialogCommonData(
Text.translatable(entry.getMetadata().titleKey()),
player.openDialog(Holder.direct(new MultiActionDialog(
new CommonDialogData(
Component.translatable(entry.getMetadata().titleKey()),
Optional.empty(),
true,
false,
AfterAction.CLOSE,
entry.getDialog(player.getRegistryManager()),
DialogAction.CLOSE,
entry.getDialog(player.registryAccess()),
List.of()
),
buttons,
@@ -79,38 +78,38 @@ public class DocsManager implements SimpleResourceReloadListener<Pair<Map<Identi
)));
}
private static DialogActionButtonData getDialogButton(Text text, String dialogToOpen) {
return new DialogActionButtonData(
new DialogButtonData(
private static ActionButton getDialogButton(Component text, String dialogToOpen) {
return new ActionButton(
new CommonButtonData(
text, 100
),
Optional.of(new SimpleDialogAction(new ClickEvent.RunCommand("/minions docs " + dialogToOpen)))
Optional.of(new StaticAction(new ClickEvent.RunCommand("/minions docs " + dialogToOpen)))
);
}
public static DocsEntry getDocsEntry(Identifier id) {
public static DocsEntry getDocsEntry(ResourceLocation id) {
return docs.get(id);
}
public static Collection<Identifier> getDocsEntryIds() {
public static Collection<ResourceLocation> getDocsEntryIds() {
return docs.keySet();
}
@Override
public CompletableFuture<Pair<Map<Identifier, DocsEntry>, DocsTree>> load(ResourceManager resourceManager, Executor executor) {
public CompletableFuture<Tuple<Map<ResourceLocation, DocsEntry>, DocsTree>> load(ResourceManager resourceManager, Executor executor) {
return CompletableFuture.supplyAsync(() -> {
Map<Identifier, Resource> resources = resourceManager.findResources("docs", id -> id.getNamespace().equals(Minions.MOD_ID) && id.getPath().endsWith(".json"));
Map<ResourceLocation, Resource> resources = resourceManager.listResources("docs", id -> id.getNamespace().equals(Minions.MOD_ID) && id.getPath().endsWith(".json"));
final DocsTree.BranchElement[] root = {null};
Map<Identifier, DocsEntry> docsEntries = new HashMap<>();
Map<ResourceLocation, DocsEntry> docsEntries = new HashMap<>();
resources.forEach((id, resource) -> {
try(Reader reader = resource.getReader()) {
try(Reader reader = resource.openAsReader()) {
if(id.getPath().equals("docs/tree.json")) {
DocsTree.BranchElement.CODEC.decode(JsonOps.INSTANCE, StrictJsonParser.parse(reader))
.ifSuccess(entry -> root[0] = entry.getFirst())
.ifError(error -> Minions.LOGGER.warn("Could not parse docs tree {}: {}", id, error.message()));
} else {
Identifier docId = Identifier.of(id.getNamespace(), id.getPath().substring("docs/".length(), id.getPath().length() - ".json".length()));
ResourceLocation docId = ResourceLocation.fromNamespaceAndPath(id.getNamespace(), id.getPath().substring("docs/".length(), id.getPath().length() - ".json".length()));
DocsEntry.CODEC.decode(JsonOps.INSTANCE, StrictJsonParser.parse(reader))
.ifSuccess(entry -> docsEntries.put(docId, entry.getFirst()))
.ifError(error -> Minions.LOGGER.warn("Could not parse docs entry {}: {}", id, error.message()));
@@ -121,24 +120,24 @@ public class DocsManager implements SimpleResourceReloadListener<Pair<Map<Identi
});
if(root[0] != null) {
DocsTree tree = new DocsTree(root[0]);
return new Pair<>(docsEntries, tree);
return new Tuple<>(docsEntries, tree);
} else {
return new Pair<>(docsEntries, null);
return new Tuple<>(docsEntries, null);
}
}, executor);
}
@Override
public CompletableFuture<Void> apply(Pair<Map<Identifier, DocsEntry>, DocsTree> o, ResourceManager resourceManager, Executor executor) {
public CompletableFuture<Void> apply(Tuple<Map<ResourceLocation, DocsEntry>, DocsTree> o, ResourceManager resourceManager, Executor executor) {
return CompletableFuture.supplyAsync(() -> {
docs = o.getLeft();
tree = o.getRight();
docs = o.getA();
tree = o.getB();
return null;
});
}
@Override
public Identifier getFabricId() {
return Identifier.of(Minions.MOD_ID, "docs");
public ResourceLocation getFabricId() {
return ResourceLocation.fromNamespaceAndPath(Minions.MOD_ID, "docs");
}
}
@@ -2,16 +2,15 @@ package io.github.skippyall.minions.docs;
import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;
import net.minecraft.util.Identifier;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import net.minecraft.resources.ResourceLocation;
public class DocsTree {
private final BranchElement root;
private final Map<Identifier, DocElement> entries = new HashMap<>();
private final Map<ResourceLocation, DocElement> entries = new HashMap<>();
public DocsTree(BranchElement root) {
this.root = root;
@@ -30,7 +29,7 @@ public class DocsTree {
return root;
}
public DocElement getElement(Identifier id) {
public DocElement getElement(ResourceLocation id) {
return entries.get(id);
}
@@ -55,15 +54,15 @@ public class DocsTree {
}
public static final class DocElement extends Element {
public static final Codec<DocElement> CODEC = Identifier.CODEC.xmap(DocElement::new, DocElement::getId);
public static final Codec<DocElement> CODEC = ResourceLocation.CODEC.xmap(DocElement::new, DocElement::getId);
private final Identifier id;
private final ResourceLocation id;
public DocElement(Identifier element) {
public DocElement(ResourceLocation element) {
this.id = element;
}
public Identifier getId() {
public ResourceLocation getId() {
return id;
}
}
@@ -4,36 +4,35 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.skippyall.minions.gui.GuiDisplay;
import net.minecraft.dialog.body.DialogBody;
import net.minecraft.dialog.body.ItemDialogBody;
import net.minecraft.dialog.body.PlainMessageDialogBody;
import net.minecraft.item.Item;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.util.Identifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.dialog.body.DialogBody;
import net.minecraft.server.dialog.body.ItemBody;
import net.minecraft.server.dialog.body.PlainMessage;
import net.minecraft.world.item.Item;
public record ReferenceEntry(Metadata metadata, RegistryKey<?> object, Text shortDescription, Text longDescription) implements DocsEntry {
private static final Codec<RegistryKey<?>> REGISTRY_KEY_CODEC = RecordCodecBuilder.create(instance ->
public record ReferenceEntry(Metadata metadata, ResourceKey<?> object, Component shortDescription, Component longDescription) implements DocsEntry {
private static final Codec<ResourceKey<?>> REGISTRY_KEY_CODEC = RecordCodecBuilder.create(instance ->
instance.group(
Identifier.CODEC.fieldOf("registry").forGetter(RegistryKey::getRegistry),
Identifier.CODEC.fieldOf("value").forGetter(RegistryKey::getValue)
).apply(instance, (registry, value) -> RegistryKey.of(RegistryKey.ofRegistry(registry), value))
ResourceLocation.CODEC.fieldOf("registry").forGetter(ResourceKey::registry),
ResourceLocation.CODEC.fieldOf("value").forGetter(ResourceKey::location)
).apply(instance, (registry, value) -> ResourceKey.create(ResourceKey.createRegistryKey(registry), value))
);
public static final MapCodec<ReferenceEntry> CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group(
Metadata.CODEC.fieldOf("metadata").forGetter(ReferenceEntry::getMetadata),
REGISTRY_KEY_CODEC.fieldOf("object").forGetter(ReferenceEntry::object),
TextCodecs.CODEC.fieldOf("shortDescription").forGetter(ReferenceEntry::shortDescription),
TextCodecs.CODEC.fieldOf("longDescription").forGetter(ReferenceEntry::longDescription)
ComponentSerialization.CODEC.fieldOf("shortDescription").forGetter(ReferenceEntry::shortDescription),
ComponentSerialization.CODEC.fieldOf("longDescription").forGetter(ReferenceEntry::longDescription)
).apply(instance, ReferenceEntry::new));
@Override
@@ -42,33 +41,33 @@ public record ReferenceEntry(Metadata metadata, RegistryKey<?> object, Text shor
}
@Override
public List<DialogBody> getDialog(DynamicRegistryManager manager) {
public List<DialogBody> getDialog(RegistryAccess manager) {
List<DialogBody> bodyElements = new ArrayList<>();
GuiDisplay display = getObjectDisplay(manager);
if(display != null) {
bodyElements.add(new ItemDialogBody(display.createItemStack(), Optional.empty(), false, false, 16, 16));
bodyElements.add(new ItemBody(display.createItemStack(), Optional.empty(), false, false, 16, 16));
}
bodyElements.add(new PlainMessageDialogBody(Text.translatable(object.getValue().toTranslationKey(object.getRegistry().getPath())), 200));
bodyElements.add(new PlainMessageDialogBody(longDescription, 200));
bodyElements.add(new PlainMessage(Component.translatable(object.location().toLanguageKey(object.registry().getPath())), 200));
bodyElements.add(new PlainMessage(longDescription, 200));
return bodyElements;
}
public GuiDisplay getObjectDisplay(DynamicRegistryManager manager) {
public GuiDisplay getObjectDisplay(RegistryAccess manager) {
GuiDisplay display = GuiDisplay.DEFAULT_DISPLAY;
if(object.isOf(RegistryKeys.ITEM) || object.isOf(RegistryKeys.BLOCK)) {
if(object.isFor(Registries.ITEM) || object.isFor(Registries.BLOCK)) {
Item item;
if(object.isOf(RegistryKeys.ITEM)) {
item = Registries.ITEM.get(object.getValue());
if(object.isFor(Registries.ITEM)) {
item = BuiltInRegistries.ITEM.getValue(object.location());
} else {
item = Registries.BLOCK.get(object.getValue()).asItem();
item = BuiltInRegistries.BLOCK.getValue(object.location()).asItem();
}
if(item != null) {
display = new GuiDisplay.ItemBased(item);
}
} else {
Identifier displayId = object.getValue().withPrefixedPath(object.getRegistry().getPath() + "/");
ResourceLocation displayId = object.location().withPrefix(object.registry().getPath() + "/");
display = GuiDisplay.getGuiDisplay(displayId, manager);
}
return display;