Skip to content
Closed
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
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.9
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.8
loader_version=0.16.10

# Fabric API
fabric_version=0.110.0+1.21.3
fabric_version=0.115.0+1.21.4

# Mod Properties
mod_version=1.2.5
mod_version=1.2.6
maven_group=xyz.imcodist.quickmenu
archives_base_name=quick-menu

# owo-lib
owo_version=0.12.18+1.21.2
owo_version=0.12.20+1.21.4
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import xyz.imcodist.quickmenu.other.ModConfigModel;

import java.util.ArrayList;
import java.util.List;

public class ActionButtonData {
public String name;
Expand Down Expand Up @@ -45,7 +46,7 @@ public ActionButtonDataJSON toJSON() {
jsonData.icon = icon.getRegistryEntry().getKey().get().getValue().toString();
}

jsonData.customModelData = icon.getOrDefault(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelDataComponent.DEFAULT).value();
jsonData.modelData = new ActionButtonDataJSON.ModelData(icon.getOrDefault(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelDataComponent.DEFAULT));
}

return jsonData;
Expand All @@ -66,7 +67,10 @@ public static ActionButtonData fromJSON(ActionButtonDataJSON json) {

if (json.icon != null) {
data.icon = new ItemStack(Registries.ITEM.get(Identifier.of(json.icon)));
data.icon.set(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(json.customModelData));

if (json.modelData != null) {
data.icon.set(DataComponentTypes.CUSTOM_MODEL_DATA, json.modelData.toComponent());
}
}

return data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
package xyz.imcodist.quickmenu.data;

import net.minecraft.component.type.CustomModelDataComponent;

import java.util.ArrayList;
import java.util.List;

public class ActionButtonDataJSON {
public String name;
public ArrayList<ArrayList<String>> actions;
public String icon;
public int customModelData;
public ModelData modelData;
public ArrayList<Integer> keybind = new ArrayList<>();

public static class ModelData {
public ModelData(CustomModelDataComponent originalComponent) {
this.floats = originalComponent.floats();
this.flags = originalComponent.flags();
this.strings = originalComponent.strings();
this.colors = originalComponent.colors();
}

public ModelData() {}

public CustomModelDataComponent toComponent() {
return new CustomModelDataComponent(this.floats, this.flags, this.strings, this.colors);
}

public List<Float> floats;
public List<Boolean> flags;
public List<String> strings;
public List<Integer> colors;
}
}
46 changes: 31 additions & 15 deletions src/main/java/xyz/imcodist/quickmenu/ui/ActionEditorUI.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package xyz.imcodist.quickmenu.ui;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.wispforest.owo.ui.base.BaseOwoScreen;
import io.wispforest.owo.ui.component.ButtonComponent;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.component.LabelComponent;
import io.wispforest.owo.ui.component.TextBoxComponent;
import io.wispforest.owo.ui.component.*;
import io.wispforest.owo.ui.container.Containers;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.OverlayContainer;
Expand All @@ -21,6 +20,7 @@
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;
import xyz.imcodist.quickmenu.data.ActionButtonData;
import xyz.imcodist.quickmenu.data.ActionButtonDataJSON;
import xyz.imcodist.quickmenu.data.command_actions.BaseActionData;
import xyz.imcodist.quickmenu.data.command_actions.CommandActionData;
import xyz.imcodist.quickmenu.data.command_actions.KeybindActionData;
Expand All @@ -31,7 +31,11 @@
import xyz.imcodist.quickmenu.ui.popups.KeybindPickerUI;
import xyz.imcodist.quickmenu.ui.surfaces.SwitcherSurface;

import java.io.StringReader;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class ActionEditorUI extends BaseOwoScreen<FlowLayout> {
Expand All @@ -44,7 +48,7 @@ public class ActionEditorUI extends BaseOwoScreen<FlowLayout> {

private OverlayContainer<FlowLayout> pickerUI;

private TextBoxComponent customModelDataTextBox;
private TextAreaComponent customModelDataTextBox;
private ButtonComponent keybindButton;
private boolean settingKeybind = false;
private boolean boundKeybind = false;
Expand Down Expand Up @@ -159,14 +163,15 @@ protected void build(FlowLayout rootComponent) {
FlowLayout customModelDataProperty = createNewProperty("custommodeldata", false);
advancedLayout.child(customModelDataProperty);

Integer customModelData = getCustomModelData(iconButton.itemIcon);
String cmdText = customModelData != 0 ? customModelData.toString() : "";
ActionButtonDataJSON.ModelData customModelData = new ActionButtonDataJSON.ModelData(getCustomModelData(iconButton.itemIcon));

customModelDataTextBox = Components.textBox(Sizing.fixed(75), cmdText);
Gson gson = new Gson();
String cmdText = gson.toJson(customModelData);

customModelDataTextBox = Components.textArea(Sizing.fixed(75), Sizing.fixed(50), cmdText);
customModelDataTextBox.cursorStyle(CursorStyle.TEXT);

customModelDataTextBox.onChanged().subscribe((text) -> {
customModelDataTextBox.setText(text.replaceAll("^0+|\\D", ""));
updateCustomModelData(iconButton.itemIcon);
});

Expand Down Expand Up @@ -214,20 +219,31 @@ protected void build(FlowLayout rootComponent) {
buttonsLayout.child(cancelButton);
}

private Integer getCustomModelData(ItemStack item) {
if (item == null) return CustomModelDataComponent.DEFAULT.value();
return item.getOrDefault(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelDataComponent.DEFAULT).value();
private CustomModelDataComponent getCustomModelData(ItemStack item) {
if (item == null) return CustomModelDataComponent.DEFAULT;
return item.getOrDefault(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelDataComponent.DEFAULT);
}

private void updateCustomModelData(ItemStack itemStack) {
// updates the items custom model data to that of the users input.
String text = customModelDataTextBox.getText();
Gson gson = new Gson();
Type modelDataType = new TypeToken<ActionButtonDataJSON.ModelData>(){}.getType();

String jsonText = customModelDataTextBox.getText();

ActionButtonDataJSON.ModelData newModelData = null;

try (StringReader reader = new StringReader(jsonText)) {
newModelData = gson.fromJson(reader, modelDataType);
} catch (Exception e) {
e.printStackTrace();
}

if (itemStack == null) return;

try {
if (!text.equals("")) {
itemStack.set(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(Integer.parseInt(text)));
if (newModelData != null) {
itemStack.set(DataComponentTypes.CUSTOM_MODEL_DATA, newModelData.toComponent());
} else {
itemStack.remove(DataComponentTypes.CUSTOM_MODEL_DATA);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class ItemPickerUI extends OverlayContainer<FlowLayout> {
public ItemStack selectedItem;
public Integer customModelData;
public CustomModelDataComponent customModelData;

public Consumer<ItemStack> onSelectedItem;

Expand Down Expand Up @@ -104,7 +104,7 @@ public void createItemButtons(FlowLayout parent, String search) {
ItemStack item = items.get(curItem).getDefaultStack();

if (customModelData != null) {
item.set(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(customModelData));
item.set(DataComponentTypes.CUSTOM_MODEL_DATA, customModelData);
}

ButtonComponent button = new QuickMenuButton(item, (buttonComponent) -> {
Expand Down
Loading