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
5 changes: 4 additions & 1 deletion 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.11-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 Down
18 changes: 9 additions & 9 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.8
minecraft_version=1.21.8
yarn_mappings=1.21.8+build.1
loader_version=0.17.2

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

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

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=18.0.796
rei_version=20.0.811

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

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

# 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.8
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
3 changes: 2 additions & 1 deletion 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 @@ -89,7 +90,7 @@ private static int executeGetLavenderBook(CommandContext<FabricClientCommandSour
}

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
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
10 changes: 6 additions & 4 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 @@ -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
48 changes: 9 additions & 39 deletions src/main/java/io/wispforest/lavender/book/StructureComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
import io.wispforest.owo.ui.parsing.UIModelParsingException;
import io.wispforest.owo.ui.parsing.UIParsing;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.ScreenRect;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.RotationAxis;
import org.lwjgl.glfw.GLFW;
import org.w3c.dom.Element;

Expand Down Expand Up @@ -54,42 +51,15 @@ public void update(float delta, int mouseX, int mouseY) {
@Override
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
var client = MinecraftClient.getInstance();
var entityBuffers = client.getBufferBuilders().getEntityVertexConsumers();

float scale = Math.min(this.width, this.height);
scale /= Math.max(structure.xSize, Math.max(structure.ySize, structure.zSize));
scale /= 1.625f;

var matrices = context.getMatrices();

matrices.push();
matrices.translate(this.x + this.width / 2f, this.y + this.height / 2f, 100);
matrices.scale(scale, -scale, scale);

matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(this.displayAngle));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(this.rotation));
matrices.translate(this.structure.xSize / -2f, this.structure.ySize / -2f, this.structure.zSize / -2f);

structure.forEachPredicate((blockPos, predicate) -> {
if (this.visibleLayer != -1 && this.visibleLayer != blockPos.getY()) return;

matrices.push();
matrices.translate(blockPos.getX(), blockPos.getY(), blockPos.getZ());

client.getBlockRenderManager().renderBlockAsEntity(
predicate.preview(), matrices, entityBuffers,
LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE,
OverlayTexture.DEFAULT_UV
);

matrices.pop();
});

matrices.pop();

DiffuseLighting.disableGuiDepthLighting();
entityBuffers.draw();
DiffuseLighting.enableGuiDepthLighting();
context.state.addSpecialElement(new StructureComponentRenderState(
structure,
displayAngle,
rotation,
visibleLayer,
new ScreenRect(this.x, this.y, this.width, this.height),
context.scissorStack.peekLast()
));

if (this.placeable) {
if (StructureOverlayRenderer.isShowingOverlay(this.structure.id)) {
Expand Down
Loading