Skip to content

Commit

Permalink
Merge branch '1.21' into 1.21-Neo
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Seeker committed Sep 9, 2024
2 parents e83cb71 + 212005b commit 7977709
Show file tree
Hide file tree
Showing 61 changed files with 1,273 additions and 310 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ dependencies {
// modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
// modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}")

include api(forgeRuntimeLibrary("io.wispforest:endec:0.1.4"))
include api(forgeRuntimeLibrary("io.wispforest.endec:netty:0.1.2"))
include api(forgeRuntimeLibrary("io.wispforest.endec:gson:0.1.3"))
include api(forgeRuntimeLibrary("io.wispforest.endec:jankson:0.1.3"))
include api("io.wispforest:endec:0.1.5")
include api("io.wispforest.endec:netty:0.1.2")
include api("io.wispforest.endec:gson:0.1.3")
include api("io.wispforest.endec:jankson:0.1.3")

include api(forgeRuntimeLibrary("blue.endless:jankson:${project.jankson_version}"))

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11
# Mod Properties
mod_version=0.12.10
mod_version=0.12.12
maven_group=io.wispforest
archives_base_name=owo-lib-neo

Expand Down
18 changes: 15 additions & 3 deletions src/main/java/io/wispforest/owo/client/screens/SyncedProperty.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package io.wispforest.owo.client.screens;

import io.wispforest.endec.Endec;
import io.wispforest.endec.SerializationContext;
import io.wispforest.owo.serialization.RegistriesAttribute;
import io.wispforest.owo.util.Observable;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler;
import org.jetbrains.annotations.ApiStatus;

public class SyncedProperty<T> extends Observable<T> {
private final int index;
private final Endec<T> endec;
private final ScreenHandler owner;
private boolean needsSync;

@ApiStatus.Internal
public SyncedProperty(int index, Endec<T> endec, T initial) {
public SyncedProperty(int index, Endec<T> endec, T initial, ScreenHandler owner) {
super(initial);

this.index = index;
this.endec = endec;
this.owner = owner;
}

public int index() {
Expand All @@ -30,12 +35,12 @@ public boolean needsSync() {
@ApiStatus.Internal
public void write(PacketByteBuf buf) {
needsSync = false;
buf.write(this.endec, value);
buf.write(serializationContext(), this.endec, value);
}

@ApiStatus.Internal
public void read(PacketByteBuf buf) {
this.set(buf.read(this.endec));
this.set(buf.read(serializationContext(), this.endec));
}

@Override
Expand All @@ -48,4 +53,11 @@ protected void notifyObservers(T value) {
public void markDirty() {
notifyObservers(value);
}

private SerializationContext serializationContext() {
var player = this.owner.player();
if (player == null) return SerializationContext.empty();

return SerializationContext.attributes(RegistriesAttribute.of(player.getRegistryManager()));
}
}
Empty file.
3 changes: 2 additions & 1 deletion src/main/java/io/wispforest/owo/config/ConfigWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.wispforest.owo.Owo;
import io.wispforest.owo.config.annotation.*;
import io.wispforest.owo.config.ui.ConfigScreen;
import io.wispforest.owo.config.ui.ConfigScreenProviders;
import io.wispforest.owo.serialization.endec.MinecraftEndecs;
import io.wispforest.owo.ui.core.Color;
import io.wispforest.owo.util.NumberReflection;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected ConfigWrapper(Class<C> clazz, Consumer<Jankson.Builder> janksonBuilder

if (FMLLoader.getDist() == Dist.CLIENT && clazz.isAnnotationPresent(Modmenu.class)) {
var modmenuAnnotation = clazz.getAnnotation(Modmenu.class);
ConfigScreen.registerProvider(
ConfigScreenProviders.registerOwoConfigScreen(
modmenuAnnotation.modId(),
screen -> ConfigScreen.createWithCustomModel(Identifier.of(modmenuAnnotation.uiModelId()), this, screen)
);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/io/wispforest/owo/config/OwoConfigCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.wispforest.owo.Owo;
import io.wispforest.owo.config.ui.ConfigScreen;
import io.wispforest.owo.config.ui.ConfigScreenProviders;
import io.wispforest.owo.ops.TextOps;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.server.command.CommandManager;
Expand All @@ -36,15 +38,15 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
})));
}

private static class ConfigScreenArgumentType implements ArgumentType<ConfigScreen> {
private static class ConfigScreenArgumentType implements ArgumentType<Screen> {

private static final SimpleCommandExceptionType NO_SUCH_CONFIG_SCREEN = new SimpleCommandExceptionType(
TextOps.concat(Owo.PREFIX, Text.literal("no config screen with that id"))
);

@Override
public ConfigScreen parse(StringReader reader) throws CommandSyntaxException {
var provider = ConfigScreen.getProvider(reader.readString());
public Screen parse(StringReader reader) throws CommandSyntaxException {
var provider = ConfigScreenProviders.get(reader.readString());
if (provider == null) throw NO_SUCH_CONFIG_SCREEN.create();

return provider.apply(null);
Expand All @@ -53,7 +55,7 @@ public ConfigScreen parse(StringReader reader) throws CommandSyntaxException {
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
var configNames = new ArrayList<String>();
ConfigScreen.forEachProvider((s, screenFunction) -> configNames.add(s));
ConfigScreenProviders.forEach((s, screenFunction) -> configNames.add(s));
return CommandSource.suggestMatching(configNames, builder);
}
}
Expand Down
35 changes: 12 additions & 23 deletions src/main/java/io/wispforest/owo/config/ui/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.mutable.MutableInt;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

Expand All @@ -55,8 +54,6 @@ public class ConfigScreen extends BaseUIModelScreen<FlowLayout> {

public static final Identifier DEFAULT_MODEL_ID = Identifier.of("owo", "config");

private static final Map<String, Function<Screen, ? extends ConfigScreen>> CONFIG_SCREEN_PROVIDERS = new HashMap<>();

private static final Map<Predicate<Option<?>>, OptionComponentFactory<?>> DEFAULT_FACTORIES = new HashMap<>();
/**
* A set of extra option factories - add to this if you want to override
Expand Down Expand Up @@ -104,35 +101,27 @@ public static ConfigScreen createWithCustomModel(Identifier modelId, ConfigWrapp
}

/**
* Register the given config screen provider. This is primarily
* used for making your config available in ModMenu and to the
* {@code /owo-config} command, although other places my use it as well
*
* @param modId The mod id for which to supply a config screen
* @param supplier The supplier to register - this gets the parent screen
* as argument
* @throws IllegalArgumentException If a config screen provider is
* already registered for the given mod id
* @deprecated Use {@link ConfigScreenProviders#register(String, Function)} instead
*/
@Deprecated(forRemoval = true)
public static <S extends ConfigScreen> void registerProvider(String modId, Function<Screen, S> supplier) {
if (CONFIG_SCREEN_PROVIDERS.put(modId, supplier) != null) {
throw new IllegalArgumentException("Tried to register config screen provider for mod id " + modId + " twice");
}
ConfigScreenProviders.registerOwoConfigScreen(modId, supplier);
}

/**
* Get the config screen provider associated with
* the given mod id
*
* @return The associated config screen provider, or {@code null} if
* none is registered
* @deprecated Use {@link ConfigScreenProviders#get(String)} instead
*/
@Deprecated(forRemoval = true)
public static @Nullable Function<Screen, ? extends ConfigScreen> getProvider(String modId) {
return CONFIG_SCREEN_PROVIDERS.get(modId);
return ConfigScreenProviders.getOwoProvider(modId);
}

/**
* @deprecated Use {@link ConfigScreenProviders#forEach(BiConsumer)} instead
*/
@Deprecated(forRemoval = true)
public static void forEachProvider(BiConsumer<String, Function<Screen, ? extends ConfigScreen>> action) {
CONFIG_SCREEN_PROVIDERS.forEach(action);
ConfigScreenProviders.forEachOwoProvider(action);
}

@Override
Expand Down Expand Up @@ -462,7 +451,7 @@ public void removed() {
UIParsing.registerFactory("config-text-box", element -> new ConfigTextBox());
}

private record SearchMatches(String query, List<SearchAnchorComponent> matches) {}
protected record SearchMatches(String query, List<SearchAnchorComponent> matches) {}

public static class SearchHighlighterComponent extends BaseComponent {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.wispforest.owo.config.ui;

import net.minecraft.client.gui.screen.Screen;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;

public class ConfigScreenProviders {

private static final Map<String, Function<Screen, ? extends Screen>> PROVIDERS = new HashMap<>();
private static final Map<String, Function<Screen, ? extends ConfigScreen>> OWO_SCREEN_PROVIDERS = new HashMap<>();

/**
* Register the given config screen provider. This is primarily
* used for making a config screen available in ModMenu and to the
* {@code /owo-config} command, although other places my use it as well
*
* @param modId The mod id for which to supply a config screen
* @param supplier The supplier to register - this gets the parent screen
* as argument
* @throws IllegalArgumentException If a config screen provider is
* already registered for the given mod id
*/
public static <S extends Screen> void register(String modId, Function<Screen, S> supplier) {
if (PROVIDERS.put(modId, supplier) != null) {
throw new IllegalArgumentException("Tried to register config screen provider for mod id " + modId + " twice");
}
}

/**
* Get the config screen provider associated with
* the given mod id
*
* @return The associated config screen provider, or {@code null} if
* none is registered
*/
public static @Nullable Function<Screen, ? extends Screen> get(String modId) {
return PROVIDERS.get(modId);
}

public static void forEach(BiConsumer<String, Function<Screen, ? extends Screen>> action) {
PROVIDERS.forEach(action);
}

// -- internal methods for backwards-compat in ConfigScreen --

@ApiStatus.Internal
public static <S extends ConfigScreen> void registerOwoConfigScreen(String modId, Function<Screen, S> supplier) {
register(modId, supplier);
OWO_SCREEN_PROVIDERS.put(modId, supplier);
}

static @Nullable Function<Screen, ? extends ConfigScreen> getOwoProvider(String modId) {
return OWO_SCREEN_PROVIDERS.get(modId);
}

static void forEachOwoProvider(BiConsumer<String, Function<Screen, ? extends ConfigScreen>> action) {
OWO_SCREEN_PROVIDERS.forEach(action);
}
}
64 changes: 64 additions & 0 deletions src/main/java/io/wispforest/owo/ext/DerivedComponentMap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.wispforest.owo.ext;

import net.minecraft.component.ComponentChanges;
import net.minecraft.component.ComponentMap;
import net.minecraft.component.ComponentMapImpl;
import net.minecraft.component.ComponentType;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.Set;

@ApiStatus.Internal
public class DerivedComponentMap implements ComponentMap {
private final ComponentMap base;
private final ComponentMapImpl delegate;

public DerivedComponentMap(ComponentMap base) {
this.base = base;
this.delegate = new ComponentMapImpl(base);
}

public static ComponentMap reWrapIfNeeded(ComponentMap original) {
if (original instanceof DerivedComponentMap derived) {
return new DerivedComponentMap(derived.base);
} else {
return original;
}
}

public void derive(ItemStack owner) {
delegate.setChanges(ComponentChanges.EMPTY);
var builder = ComponentChanges.builder();
owner.getItem().deriveStackComponents(owner.getComponents(), builder);
delegate.setChanges(builder.build());
}

@Nullable
@Override
public <T> T get(ComponentType<? extends T> type) {
return delegate.get(type);
}

@Override
public Set<ComponentType<?>> getTypes() {
return delegate.getTypes();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

DerivedComponentMap that = (DerivedComponentMap) o;
return base.equals(that.base) && delegate.equals(that.delegate);
}

@Override
public int hashCode() {
int result = base.hashCode();
result = 31 * result + delegate.hashCode();
return result;
}
}
15 changes: 15 additions & 0 deletions src/main/java/io/wispforest/owo/ext/OwoItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.wispforest.owo.ext;

import net.minecraft.component.ComponentChanges;
import net.minecraft.component.ComponentMap;
import org.jetbrains.annotations.ApiStatus;

public interface OwoItem {
/**
* Generates component-derived-components from the stack's components
* @param source a map containing the item stack's non-derived components
* @param target a builder for the derived component map
*/
@ApiStatus.Experimental
default void deriveStackComponents(ComponentMap source, ComponentChanges.Builder target) { }
}
5 changes: 2 additions & 3 deletions src/main/java/io/wispforest/owo/itemgroup/OwoItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
* within, as well as arbitrary buttons with defaults provided for links
* to places like GitHub, Modrinth, etc.
* <p>
* Tabs can be populated by using {@link OwoItemSettings} and setting the
* {@link OwoItemSettings#tab(int)}. Furthermore, tags can be used for easily populating
* tabs from data
* Tabs can be populated by setting the {@link OwoItemSettingsExtension#tab(int)}.
* Furthermore, tags can be used for easily populating tabs from data
* <p>
* The roots of this implementation originated in Biome Makeover, where it was written by Lemonszz
*/
Expand Down
Loading

0 comments on commit 7977709

Please sign in to comment.