Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'fabric-loom' version '1.13-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -41,6 +41,9 @@ repositories {

// modmenu
maven { url "https://maven.terraformersmc.com/releases/" }

// TEMP: lavender-md for 1.21.5 explodes 1.21.8 dev env by trying to load 1.21.5 FAPI modules for some reason????
mavenLocal()
}

dependencies {
Expand All @@ -55,9 +58,6 @@ dependencies {
modImplementation "io.wispforest:owo-lib:${project.owo_version}"
include "io.wispforest:owo-sentinel:${project.owo_version}"

// modLocalRuntime "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"

include modApi("io.wispforest.lavender-md:core:${project.lavender_md_version}")
include modApi("io.wispforest.lavender-md:owo-ui:${project.lavender_md_version}")

Expand Down
19 changes: 8 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_base_version=1.21.4
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.2
loader_version=0.16.9
minecraft_base_version=1.21.10
minecraft_version=1.21.10
yarn_mappings=1.21.10+build.2
loader_version=0.18.1

# Mod Properties
mod_version = 0.1.15
Expand All @@ -15,16 +15,13 @@ org.gradle.jvmargs=-Xmx1G

# Dependencies
# check this on https://fabricmc.net/develop
fabric_version=0.112.0+1.21.4

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=18.0.796
fabric_version=0.138.3+1.21.10

# https://maven.wispforest.io/#/releases/io/wispforest/owo-lib/
owo_version=0.12.20+1.21.4
owo_version=0.12.24+1.21.9

# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
modmenu_version=13.0.0-beta.1
modmenu_version=16.0.0-rc.1

# https://maven.wispforest.io/#/releases/io/wispforest/lavender-md/core/
lavender_md_version=0.1.2+1.21.2
lavender_md_version=0.1.2+1.21.10
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
27 changes: 11 additions & 16 deletions src/main/java/io/wispforest/lavender/Lavender.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.wispforest.lavender;

import com.mojang.logging.LogUtils;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.wispforest.endec.Endec;
import io.wispforest.endec.impl.BuiltInEndecs;
import io.wispforest.endec.impl.StructEndecBuilder;
Expand All @@ -11,15 +13,14 @@
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.datafixer.DataFixTypes;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.Uuids;
import net.minecraft.world.PersistentState;
import net.minecraft.world.PersistentStateType;
import org.slf4j.Logger;

import java.util.UUID;
Expand All @@ -40,7 +41,7 @@ public void onInitialize() {
PayloadTypeRegistry.playS2C().register(WorldUUIDPayload.ID, CodecUtils.toPacketCodec(WorldUUIDPayload.ENDEC));

ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
sender.sendPacket(new WorldUUIDPayload(server.getOverworld().getPersistentStateManager().getOrCreate(WorldUUIDState.TYPE, "lavender_world_id").id));
sender.sendPacket(new WorldUUIDPayload(server.getOverworld().getPersistentStateManager().getOrCreate(WorldUUIDState.TYPE).id));
});

LavenderClientRecipeCache.initialize();
Expand All @@ -52,27 +53,21 @@ public static Identifier id(String path) {

public static class WorldUUIDState extends PersistentState {

public static final PersistentState.Type<WorldUUIDState> TYPE = new Type<>(() -> {
public static final Codec<WorldUUIDState> CODEC = RecordCodecBuilder.create(
instance -> instance.ap(WorldUUIDState::new, Uuids.INT_STREAM_CODEC.fieldOf("UUID").forGetter(w -> w.id))
);

public static final PersistentStateType<WorldUUIDState> TYPE = new PersistentStateType<>("lavender_world_id", () -> {
var state = new WorldUUIDState(UUID.randomUUID());
state.markDirty();
return state;
}, WorldUUIDState::read, DataFixTypes.LEVEL);
}, CODEC, DataFixTypes.LEVEL);

public final UUID id;

private WorldUUIDState(UUID id) {
this.id = id;
}

@Override
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
nbt.putUuid("UUID", id);
return nbt;
}

public static WorldUUIDState read(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
return new WorldUUIDState(nbt.contains("UUID", NbtElement.INT_ARRAY_TYPE) ? nbt.getUuid("UUID") : null);
}
}

public record WorldUUIDPayload(UUID worldUuid) implements CustomPayload {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/wispforest/lavender/LavenderCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.gui.screen.ChatScreen;
import net.minecraft.client.network.ClientCommandSource;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.IdentifierArgumentType;
Expand Down Expand Up @@ -82,14 +83,14 @@ private static int executeGetLavenderBook(CommandContext<FabricClientCommandSour

var jAvAsE = command;
context.getSource().getClient().send(() -> {
context.getSource().getClient().setScreen(new ChatScreen(jAvAsE));
context.getSource().getClient().setScreen(new ChatScreen(jAvAsE, true));
});

return 0;
}

public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access) {
dispatcher.register(literal("get-lavender-book").requires(source -> source.hasPermissionLevel(2))
dispatcher.register(literal("get-lavender-book").requires(source -> ((ClientCommandSource)source).hasPermissionLevel(2))
.then(argument("book_id", IdentifierArgumentType.identifier()).suggests(LOADED_BOOKS)
.executes(context -> executeGetLavenderBook(context, false))
.then(argument("force_dynamic_book", BoolArgumentType.bool())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.TexturedRenderLayers;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.command.argument.ItemStringReader;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -258,7 +260,7 @@ private static Function<Sizing, Component> getIcon(JsonObject meta) {
var id = Identifier.tryParse(JsonHelper.getString(meta, "icon_sprite"));
if (id == null) return null;

return sizing -> Components.sprite(MinecraftClient.getInstance().getGuiAtlasManager().getSprite(id)).sizing(sizing);
return sizing -> Components.sprite(new SpriteIdentifier(TexturedRenderLayers.GUI_ATLAS_TEXTURE, id)).sizing(sizing);
} else {
return sizing -> Containers.stack(sizing, sizing);
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/wispforest/lavender/book/BookLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.google.gson.reflect.TypeToken;
import com.mojang.serialization.JsonOps;
import io.wispforest.lavender.Lavender;
import io.wispforest.lavender.client.BookBakedModel;
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin;
import net.minecraft.registry.Registries;
import net.minecraft.resource.ResourceFinder;
import net.minecraft.resource.ResourceManager;
Expand All @@ -23,20 +21,23 @@

public class BookLoader {

private static final Gson GSON = new GsonBuilder().setLenient().disableHtmlEscaping().create();
private static final Gson GSON = new GsonBuilder().setStrictness(Strictness.LENIENT).disableHtmlEscaping().create();
private static final TypeToken<Map<String, String>> MACROS_TOKEN = new TypeToken<>() {};
private static final ResourceFinder BOOK_FINDER = ResourceFinder.json("lavender/books");

private static final Map<Identifier, Book> LOADED_BOOKS = new HashMap<>();
private static final Map<Identifier, Book> VISIBLE_BOOKS = new HashMap<>();

public static void initialize() {
// Seemingly unnecessary
/*
ModelLoadingPlugin.register(context -> {
for (var book : VISIBLE_BOOKS.values()) {
if (book.dynamicBookModel() == null) return;
context.addModels(book.dynamicBookModel());
}
});
*/
}

public static @Nullable Book get(Identifier bookId) {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/io/wispforest/lavender/book/LavenderBookItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.component.ComponentType;
import net.minecraft.component.type.TooltipDisplayComponent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
Expand All @@ -26,8 +27,8 @@
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class LavenderBookItem extends Item {

Expand Down Expand Up @@ -145,7 +146,7 @@ public ActionResult use(World world, PlayerEntity user, Hand hand) {

var bookId = bookIdOf(playerStack);
if (bookId == null) return ActionResult.SUCCESS;
if (!world.isClient) return ActionResult.SUCCESS;
if (!world.isClient()) return ActionResult.SUCCESS;

var book = BookLoader.get(bookId);
if (book == null) {
Expand All @@ -162,16 +163,17 @@ private static void openBookScreen(Book book) {
MinecraftClient.getInstance().setScreen(new LavenderBookScreen(book));
}

@SuppressWarnings("deprecation")
@Override
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
public void appendTooltip(ItemStack stack, Item.TooltipContext context, TooltipDisplayComponent displayComponent, Consumer<Text> textConsumer, TooltipType type) {
var bookId = bookIdOf(stack);
if (bookId == null) {
tooltip.add(TextOps.withFormatting("⚠ §No associated book", Formatting.RED, Formatting.DARK_GRAY));
textConsumer.accept(TextOps.withFormatting("⚠ §No associated book", Formatting.RED, Formatting.DARK_GRAY));
} else {
var book = BookLoader.get(bookId);
if (book != null) return;

tooltip.add(TextOps.withFormatting("⚠ §Unknown book \"" + bookId + "\"", Formatting.RED, Formatting.DARK_GRAY));
textConsumer.accept(TextOps.withFormatting("⚠ §Unknown book \"" + bookId + "\"", Formatting.RED, Formatting.DARK_GRAY));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.wispforest.lavender.book;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import io.wispforest.lavender.Lavender;
import io.wispforest.lavender.client.LavenderClient;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
Expand All @@ -26,7 +26,17 @@ public class LavenderClientStorage {
private static final TypeToken<Map<UUID, Map<Identifier, Set<Identifier>>>> VIEWED_ENTRIES_TYPE = new TypeToken<>() {};
private static Map<UUID, Map<Identifier, Set<Identifier>>> viewedEntries;

private static final Gson GSON = new GsonBuilder().registerTypeAdapter(Identifier.class, new Identifier.Serializer()).setPrettyPrinting().create();
private static final Gson GSON = new GsonBuilder().registerTypeAdapter(Identifier.class, new IdentifierSerializer()).setPrettyPrinting().create();

private static class IdentifierSerializer implements JsonDeserializer<Identifier>, JsonSerializer<Identifier> {
public Identifier deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
return Identifier.of(JsonHelper.asString(jsonElement, "location"));
}

public JsonElement serialize(Identifier identifier, Type type, JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(identifier.toString());
}
}

static {
try {
Expand Down
Loading