Skip to content

Commit

Permalink
Merge branch '1.20.2' of github.com:glisco03/owo-lib into multiple-wi…
Browse files Browse the repository at this point in the history
…ndows
  • Loading branch information
BasiqueEvangelist committed Oct 2, 2023
2 parents f926fc6 + a3cdd02 commit 92ef210
Show file tree
Hide file tree
Showing 72 changed files with 781 additions and 383 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
id 'io.github.juuxel.loom-quiltflower' version '1.10.0'
id 'io.github.juuxel.loom-vineflower' version '1.11.0'
}

allprojects {
Expand Down Expand Up @@ -128,14 +128,14 @@ dependencies {
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}")

modCompileOnly("dev.emi:emi-fabric:${project.emi_version}")
modLocalRuntime("dev.emi:emi-fabric:${project.emi_version}")
// modLocalRuntime("dev.emi:emi-fabric:${project.emi_version}")

modCompileOnly("com.terraformersmc:modmenu:${project.modmenu_version}")
modLocalRuntime("com.terraformersmc:modmenu:${project.modmenu_version}")

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

modCompileOnly "fr.catcore:server-translations-api:${project.stapi_version}"
modCompileOnly "xyz.nucleoid:server-translations-api:${project.stapi_version}"

testmodImplementation sourceSets.main.output
testmodAnnotationProcessor sourceSets.main.output
Expand Down
24 changes: 12 additions & 12 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
org.gradle.jvmargs=-Xmx2G
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_base_version=1.20
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
loader_version=0.14.21
minecraft_base_version=1.20.2
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
# Mod Properties
mod_version=0.11.2-pre.9
mod_version=0.11.3
maven_group=io.wispforest
archives_base_name=owo-lib
# Dependencies
fabric_version=0.85.0+1.20.1
fabric_version=0.89.2+1.20.2

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=12.0.625
rei_version=13.0.661

# https://maven.terraformersmc.com/releases/dev/emi/emi/
emi_version=1.0.3+1.20
# https://maven.terraformersmc.com/releases/dev/emi/emi-fabric/
emi_version=1.0.19+1.20.1

# https://search.maven.org/artifact/blue.endless/jankson
jankson_version=1.2.2

# https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu
modmenu_version=7.0.1
modmenu_version=8.0.0

# https://maven.nucleoid.xyz/fr/catcore/server-translations-api/
stapi_version=1.4.19+1.19.3
# https://maven.nucleoid.xyz/xyz/nucleoid/server-translations-api/
stapi_version=2.0.0+1.20
8 changes: 8 additions & 0 deletions owo-ui.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="panel-with-inset" type="xs:unsignedInt">
<xs:annotation>
<xs:documentation>
A panel inset bordered by a standard light panel
of the specified width on each border
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="tiled">
<xs:annotation>
<xs:documentation>
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/io/wispforest/owo/client/screens/SlotGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

import java.util.function.Consumer;

/**
* Stateful slot generation utility for easily
* arranging the slot grid used in a {@link net.minecraft.screen.ScreenHandler}
*/
public final class SlotGenerator {

private int anchorX, anchorY;
Expand All @@ -21,16 +25,38 @@ private SlotGenerator(Consumer<Slot> slotConsumer, int anchorX, int anchorY) {
this.slotConsumer = slotConsumer;
}

/**
* Begin generating slots into {@code slotConsumer}, starting at
* ({@code anchorX}, {@code anchorY}). Usually, the {@code slotConsumer}
* will be the {@code addSlot} method of the screen handler for which
* slots are being generated
* <p>
* <pre>
* {@code
* SlotGenerator.begin(this::addSlot, 50, 10)
* .grid(someInventory, 0, 3, 3) // add a 3x3 grid of slots 0-8 of 'someInventory'
* .moveTo(10, 100)
* .playerInventory(playerInventory); // add the player inventory and hotbar slots
* }
* </pre>
*/
public static SlotGenerator begin(Consumer<Slot> slotConsumer, int anchorX, int anchorY) {
return new SlotGenerator(slotConsumer, anchorX, anchorY);
}

/**
* Move the top-left anchor point of generated grids to ({@code anchorX}, {@code anchorY})
*/
public SlotGenerator moveTo(int anchorX, int anchorY) {
this.anchorX = anchorX;
this.anchorY = anchorY;
return this;
}

/**
* Shorthand for calling both {@link #horizontalSpacing} and
* {@link #verticalSpacing} with {@code spacing}
*/
public SlotGenerator spacing(int spacing) {
this.horizontalSpacing = spacing;
this.verticalSpacing = spacing;
Expand All @@ -52,11 +78,19 @@ public SlotGenerator slotConsumer(Consumer<Slot> slotConsumer) {
return this;
}

/**
* Reset the slot factory of this generator
* to the default {@link Slot#Slot(Inventory, int, int, int)} constructor
*/
public SlotGenerator defaultSlotFactory() {
this.slotFactory = Slot::new;
return this;
}

/**
* Set the slot factory of this generator, used for instantiating
* each generated slot, to {@code slotFactory}
*/
public SlotGenerator slotFactory(SlotFactory slotFactory) {
this.slotFactory = slotFactory;
return this;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/wispforest/owo/compat/rei/ReiUIAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return this.adapter.mouseScrolled(mouseX - this.adapter.x(), mouseY - this.adapter.y(), amount);
public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) {
return this.adapter.mouseScrolled(mouseX - this.adapter.x(), mouseY - this.adapter.y(), horizontalAmount, verticalAmount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean onMouseUp(double mouseX, double mouseY, int button) {

@Override
public boolean onMouseScroll(double mouseX, double mouseY, double amount) {
return this.widget.mouseScrolled(this.x + mouseX, this.y + mouseY, amount)
return this.widget.mouseScrolled(this.x + mouseX, this.y + mouseY, 0, amount)
| super.onMouseScroll(mouseX, mouseY, amount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.google.common.collect.HashMultimap;
import io.wispforest.owo.Owo;
import io.wispforest.owo.mixin.ServerPlayNetworkHandlerAccessor;
import io.wispforest.owo.mixin.ServerCommonNetworkHandlerAccessor;
import io.wispforest.owo.ops.TextOps;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -56,7 +56,7 @@ static void register(ConfigWrapper<?> config) {
* or {@code null} if no config with the given name was synced
*/
public static @Nullable Map<Option.Key, ?> getClientOptions(ServerPlayerEntity player, String configName) {
var storage = CLIENT_OPTION_STORAGE.get(((ServerPlayNetworkHandlerAccessor) player.networkHandler).owo$getConnection());
var storage = CLIENT_OPTION_STORAGE.get(((ServerCommonNetworkHandlerAccessor) player.networkHandler).owo$getConnection());
if (storage == null) return null;

return storage.get(configName);
Expand Down Expand Up @@ -188,7 +188,7 @@ private static void applyClient(MinecraftClient client, ClientPlayNetworkHandler

private static void applyServer(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler, PacketByteBuf buf, PacketSender sender) {
Owo.LOGGER.info("Receiving client config");
var connection = ((ServerPlayNetworkHandlerAccessor) player.networkHandler).owo$getConnection();
var connection = ((ServerCommonNetworkHandlerAccessor) player.networkHandler).owo$getConnection();

read(buf, (option, optionBuf) -> {
var config = CLIENT_OPTION_STORAGE.computeIfAbsent(connection, $ -> new HashMap<>()).computeIfAbsent(option.configName(), s -> new HashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected void refreshOptions() {

final var box = new ConfigTextBox();
box.setText(this.backingList.get(i).toString());
box.setCursorToStart();
box.setCursorToStart(false);
box.setDrawsBackground(false);
box.margins(Insets.vertical(2));
box.horizontalSizing(Sizing.fill(95));
Expand Down
56 changes: 45 additions & 11 deletions src/main/java/io/wispforest/owo/itemgroup/OwoItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* {@link OwoItemSettings#tab(int)}. Furthermore, tags can be used for easily populating
* tabs from data
* <p>
* This concept originated in Biome Makeover, where it was written by Lemonszz
* The roots of this implementation originated in Biome Makeover, where it was written by Lemonszz
*/
public abstract class OwoItemGroup extends ItemGroup {

Expand All @@ -52,20 +52,25 @@ public abstract class OwoItemGroup extends ItemGroup {
private final IntSet activeTabsView = IntSets.unmodifiable(this.activeTabs);
private boolean initialized = false;

private final @Nullable Identifier backgroundTexture;
private final @Nullable ScrollerTextures scrollerTextures;
private final @Nullable TabTextures tabTextures;

private final int tabStackHeight;
private final int buttonStackHeight;
private final Identifier customTexture;
private final boolean useDynamicTitle;
private final boolean displaySingleTab;
private final boolean allowMultiSelect;

protected OwoItemGroup(Identifier id, Consumer<OwoItemGroup> initializer, Supplier<Icon> iconSupplier, int tabStackHeight, int buttonStackHeight, @Nullable Identifier customTexture, boolean useDynamicTitle, boolean displaySingleTab, boolean allowMultiSelect) {
protected OwoItemGroup(Identifier id, Consumer<OwoItemGroup> initializer, Supplier<Icon> iconSupplier, int tabStackHeight, int buttonStackHeight, @Nullable Identifier backgroundTexture, @Nullable ScrollerTextures scrollerTextures, @Nullable TabTextures tabTextures, boolean useDynamicTitle, boolean displaySingleTab, boolean allowMultiSelect) {
super(null, -1, Type.CATEGORY, Text.translatable("itemGroup.%s.%s".formatted(id.getNamespace(), id.getPath())), () -> ItemStack.EMPTY, (displayContext, entries) -> {});
this.initializer = initializer;
this.iconSupplier = iconSupplier;
this.tabStackHeight = tabStackHeight;
this.buttonStackHeight = buttonStackHeight;
this.customTexture = customTexture;
this.backgroundTexture = backgroundTexture;
this.scrollerTextures = scrollerTextures;
this.tabTextures = tabTextures;
this.useDynamicTitle = useDynamicTitle;
this.displaySingleTab = displaySingleTab;
this.allowMultiSelect = allowMultiSelect;
Expand Down Expand Up @@ -98,13 +103,15 @@ public void initialize() {
if (this.initialized) return;

if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) this.initializer.accept(this);
if (tabs.size() == 0) this.tabs.add(PLACEHOLDER_TAB);
if (this.tabs.isEmpty()) this.tabs.add(PLACEHOLDER_TAB);

if (this.allowMultiSelect) {
for (int tabIdx = 0; tabIdx < this.tabs.size(); tabIdx++) {
if (!this.tabs.get(tabIdx).primary()) continue;
this.activeTabs.add(tabIdx);
}

if (this.activeTabs.isEmpty()) this.activeTabs.add(0);
} else {
this.activeTabs.add(0);
}
Expand Down Expand Up @@ -306,8 +313,16 @@ public boolean isTabSelected(int tab) {
return this.activeTabs.contains(tab);
}

public Identifier getCustomTexture() {
return customTexture;
public @Nullable Identifier getBackgroundTexture() {
return this.backgroundTexture;
}

public @Nullable ScrollerTextures getScrollerTextures() {
return this.scrollerTextures;
}

public @Nullable TabTextures getTabTextures() {
return this.tabTextures;
}

public int getTabStackHeight() {
Expand All @@ -326,6 +341,10 @@ public boolean shouldDisplaySingleTab() {
return this.displaySingleTab;
}

public boolean canSelectMultipleTabs() {
return this.allowMultiSelect;
}

public List<ItemGroupButton> getButtons() {
return buttons;
}
Expand Down Expand Up @@ -357,7 +376,9 @@ public static class Builder {
private Consumer<OwoItemGroup> initializer = owoItemGroup -> {};
private int tabStackHeight = 4;
private int buttonStackHeight = 4;
private @Nullable Identifier customTexture = null;
private @Nullable Identifier backgroundTexture = null;
private @Nullable ScrollerTextures scrollerTextures = null;
private @Nullable TabTextures tabTextures = null;
private boolean useDynamicTitle = true;
private boolean displaySingleTab = false;
private boolean allowMultiSelect = true;
Expand All @@ -382,8 +403,18 @@ public Builder buttonStackHeight(int buttonStackHeight) {
return this;
}

public Builder customTexture(@Nullable Identifier customTexture) {
this.customTexture = customTexture;
public Builder backgroundTexture(@Nullable Identifier backgroundTexture) {
this.backgroundTexture = backgroundTexture;
return this;
}

public Builder scrollerTextures(ScrollerTextures scrollerTextures) {
this.scrollerTextures = scrollerTextures;
return this;
}

public Builder tabTextures(TabTextures tabTextures) {
this.tabTextures = tabTextures;
return this;
}

Expand All @@ -403,7 +434,7 @@ public Builder withoutMultipleSelection() {
}

public OwoItemGroup build() {
final var group = new OwoItemGroup(id, initializer, iconSupplier, tabStackHeight, buttonStackHeight, customTexture, useDynamicTitle, displaySingleTab, allowMultiSelect) {};
final var group = new OwoItemGroup(id, initializer, iconSupplier, tabStackHeight, buttonStackHeight, backgroundTexture, scrollerTextures, tabTextures, useDynamicTitle, displaySingleTab, allowMultiSelect) {};
Registry.register(Registries.ITEM_GROUP, this.id, group);
return group;
}
Expand All @@ -422,6 +453,9 @@ public void add(ItemStack stack, StackVisibility visibility) {
}
}

public record ScrollerTextures(Identifier enabled, Identifier disabled) {}
public record TabTextures(Identifier topSelected, Identifier topSelectedFirstColumn, Identifier topUnselected, Identifier bottomSelected, Identifier bottomSelectedFirstColumn, Identifier bottomUnselected) {}

// Utility

/**
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/wispforest/owo/itemgroup/OwoItemSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import net.fabricmc.fabric.api.item.v1.CustomDamageHandler;
import net.fabricmc.fabric.api.item.v1.EquipmentSlotProvider;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.FoodComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Hand;
import net.minecraft.util.Rarity;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.function.BiConsumer;
Expand All @@ -17,6 +20,7 @@ public class OwoItemSettings extends FabricItemSettings {
private OwoItemGroup group = null;
private int tab = 0;
private BiConsumer<Item, ItemGroup.Entries> stackGenerator = OwoItemGroup.DEFAULT_STACK_GENERATOR;
private boolean trackUsageStat = false;

public OwoItemSettings group(ItemGroupReference ref) {
this.group = ref.group();
Expand Down Expand Up @@ -58,6 +62,20 @@ public BiConsumer<Item, ItemGroup.Entries> stackGenerator() {
return this.stackGenerator;
}

/**
* Automatically increment {@link net.minecraft.stat.Stats#USED}
* for this item every time {@link Item#use(World, PlayerEntity, Hand)}
* returns an accepted result
*/
public OwoItemSettings trackUsageStat() {
this.trackUsageStat = true;
return this;
}

public boolean shouldTrackUsageStat() {
return this.trackUsageStat;
}

@Override
public OwoItemSettings equipmentSlot(EquipmentSlotProvider equipmentSlotProvider) {
return (OwoItemSettings) super.equipmentSlot(equipmentSlotProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float delt
RenderSystem.disableBlend();
}

public boolean isTab() {
return this.definition instanceof ItemGroupTab;
}

public boolean trulyHovered() {
return this.hovered;
}
Expand Down
Loading

0 comments on commit 92ef210

Please sign in to comment.