Skip to content

Commit 9d594d7

Browse files
committed
-module priority for gui sorting
1 parent a29270a commit 9d594d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+97
-8
lines changed

common/src/main/java/smartin/miapi/client/gui/crafting/crafter/replace/ReplaceView.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
import smartin.miapi.modules.ItemModule;
1616
import smartin.miapi.modules.properties.AllowedSlots;
1717
import smartin.miapi.modules.properties.CraftingConditionProperty;
18+
import smartin.miapi.modules.properties.PriorityProperty;
1819
import smartin.miapi.modules.properties.SlotProperty;
1920

2021
import java.util.ArrayList;
22+
import java.util.Comparator;
2123
import java.util.List;
2224
import java.util.function.Consumer;
2325

@@ -39,14 +41,16 @@ public ReplaceView(int x, int y, int width, int height, SlotProperty.ModuleSlot
3941
addChild(headerHolder);
4042

4143

42-
ScrollingTextWidget header = new ScrollingTextWidget((int) ((this.getX() + 5) / headerScale), (int) (this.getY() / headerScale)+3, (int) ((this.width - 10) / headerScale), Text.translatable(Miapi.MOD_ID + ".ui.replace.header"), ColorHelper.Argb.getArgb(255, 255, 255, 255));
44+
ScrollingTextWidget header = new ScrollingTextWidget((int) ((this.getX() + 5) / headerScale), (int) (this.getY() / headerScale) + 3, (int) ((this.width - 10) / headerScale), Text.translatable(Miapi.MOD_ID + ".ui.replace.header"), ColorHelper.Argb.getArgb(255, 255, 255, 255));
4345
headerHolder.addChild(header);
4446
ScrollList list = new ScrollList(x, y + 14, width, height - 16, new ArrayList<>());
4547
addChild(list);
4648
list.children().clear();
4749
ArrayList<InteractAbleWidget> toList = new ArrayList<>();
4850
toList.add(new SlotButton(0, 0, this.width, 15, null));
49-
AllowedSlots.allowedIn(slot).forEach(module -> {
51+
AllowedSlots.allowedIn(slot).stream()
52+
.sorted(Comparator.comparingDouble(PriorityProperty::getFor))
53+
.forEach(module -> {
5054
if (CraftingConditionProperty.isVisible(slot, module, MinecraftClient.getInstance().player, null)) {
5155
toList.add(new SlotButton(0, 0, this.width, 15, module));
5256
}
@@ -95,10 +99,10 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta)
9599
if (isMouseOver(mouseX, mouseY)) {
96100
hoverOffset = 14;
97101
}
98-
if(!isAllowed){
102+
if (!isAllowed) {
99103
hoverOffset = 28;
100104
}
101-
drawTextureWithEdge(drawContext, CraftingScreen.BACKGROUND_TEXTURE, getX(), getY(), 404, 54+hoverOffset, 108, 14, getWidth(), getHeight(), 512, 512, 3);
105+
drawTextureWithEdge(drawContext, CraftingScreen.BACKGROUND_TEXTURE, getX(), getY(), 404, 54 + hoverOffset, 108, 14, getWidth(), getHeight(), 512, 512, 3);
102106
textWidget.setX(this.getX() + 2);
103107
textWidget.setY(this.getY() + 3);
104108

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package smartin.miapi.modules.properties;
2+
3+
import net.minecraft.item.ItemStack;
4+
import smartin.miapi.modules.ItemModule;
5+
import smartin.miapi.modules.properties.util.DoubleProperty;
6+
7+
public class PriorityProperty extends DoubleProperty {
8+
public static final String KEY = "priority";
9+
public static PriorityProperty property;
10+
11+
12+
public PriorityProperty() {
13+
super(KEY);
14+
property = this;
15+
}
16+
17+
@Override
18+
public Double getValue(ItemStack stack) {
19+
return getValueRaw(stack);
20+
}
21+
22+
public static double getFor(ItemModule module) {
23+
return property.getValueForModule(new ItemModule.ModuleInstance(module));
24+
}
25+
26+
@Override
27+
public double getValueSafe(ItemStack stack) {
28+
return getValueSafeRaw(stack);
29+
}
30+
}

common/src/main/java/smartin/miapi/modules/properties/RepairPriority.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ private List<Material> getRepairMaterialsPrivate(ItemStack itemStack) {
4040
double lowest = Double.MAX_VALUE;
4141
List<Material> materials = new ArrayList<>();
4242
for (ItemModule.ModuleInstance moduleInstance : ItemModule.getModules(itemStack).allSubModules()) {
43-
Double value = getValueForModule(itemStack, this, moduleInstance);
43+
Double value = getValueForModule(moduleInstance);
4444
Material material = MaterialProperty.getMaterial(moduleInstance);
4545
if (value != null && material != null && lowest > value) {
4646
lowest = value;
4747
}
4848
}
4949
for (ItemModule.ModuleInstance moduleInstance : ItemModule.getModules(itemStack).allSubModules()) {
50-
Double value = getValueForModule(itemStack, this, moduleInstance);
50+
Double value = getValueForModule(moduleInstance);
5151
Material material = MaterialProperty.getMaterial(moduleInstance);
5252
if (value != null && material != null && Math.abs(lowest - value) < 0.001) {
5353
materials.add(material);

common/src/main/java/smartin/miapi/modules/properties/util/DoubleProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ private static Double createValue(ItemStack itemStack, ModuleProperty property)
102102
}
103103
}
104104

105-
public Double getValueForModule(ItemStack itemStack, ModuleProperty property, ItemModule.ModuleInstance moduleInstance) {
105+
public Double getValueForModule(ItemModule.ModuleInstance moduleInstance) {
106106
double value = 0;
107107
boolean hasValue = false;
108108
List<Double> addition = new ArrayList<>();
109109
List<Double> multiplyBase = new ArrayList<>();
110110
List<Double> multiplyTotal = new ArrayList<>();
111-
JsonElement element = moduleInstance.getProperties().get(property);
111+
JsonElement element = moduleInstance.getProperties().get(this);
112112
if (element != null) {
113113
if (element.isJsonArray()) {
114114
for (JsonElement innerElement : element.getAsJsonArray()) {

common/src/main/java/smartin/miapi/registries/RegistryInventory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ public static void setup() {
430430
registerMiapi(moduleProperties, CanWalkOnSnow.KEY, new CanWalkOnSnow());
431431
registerMiapi(moduleProperties, FireProof.KEY, new FireProof());
432432
registerMiapi(moduleProperties, RepairPriority.KEY, new RepairPriority());
433+
registerMiapi(moduleProperties, PriorityProperty.KEY, new PriorityProperty());
433434

434435
//compat
435436
registerMiapi(moduleProperties, BetterCombatProperty.KEY, new BetterCombatProperty());

common/src/main/resources/data/miapi/modules/armor/boots/boot_left.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/boots/boot_right.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/boots/wing_boot_left.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 1,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/boots/wing_boot_right.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 1,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/chest/arm_left.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/chest/arm_right.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/chest/back_chestplate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
}
2525
],
26+
"priority": 0,
2627
"repairPriority": 1,
2728
"materialProperty": [
2829
"default",

common/src/main/resources/data/miapi/modules/armor/chest/elytra_backplate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
}
5252
}
5353
},
54+
"priority": 1,
5455
"repairPriority": 1,
5556
"materialProperty": [
5657
"default",

common/src/main/resources/data/miapi/modules/armor/chest/front_chestplate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 1,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/chest/wing_arm_left.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 1,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/chest/wing_arm_right.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 1,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/helmet/helmet_plate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"armor",
2626
"helmet"
2727
],
28+
"priority": 0,
2829
"repairPriority": 0,
2930
"tag": [
3031
"background_icon",

common/src/main/resources/data/miapi/modules/armor/pants/belt.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/pants/leg_left.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/pants/leg_right.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 0,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/pants/wing_leg_left.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 1,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/armor/pants/wing_leg_right.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
}
4545
}
4646
],
47+
"priority": 1,
4748
"repairPriority": 0,
4849
"materialProperty": [
4950
"default",

common/src/main/resources/data/miapi/modules/arrow/head/arrow_custom_head.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"tag": [
77
"arrow_head"
88
],
9+
"priority": 1,
910
"attributes": [
1011
{
1112
"attribute": "miapi:generic.projectile_damage",

common/src/main/resources/data/miapi/modules/arrow/head/arrow_head.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"default",
2525
"arrow"
2626
],
27+
"priority": 0,
2728
"allowedInSlots": [
2829
"arrow_head"
2930
],

common/src/main/resources/data/miapi/modules/bow/arm/long_bow_arms.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 3,
2324
"repairPriority": 1,
2425
"materialProperty": [
2526
"default",

common/src/main/resources/data/miapi/modules/bow/arm/normal_bow_arms.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 1,
2324
"repairPriority": 1,
2425
"materialProperty": [
2526
"default",

common/src/main/resources/data/miapi/modules/bow/arm/recurve_bow_arms.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 2,
2324
"repairPriority": 1,
2425
"materialProperty": [
2526
"default",

common/src/main/resources/data/miapi/modules/bow/arm/short_bow_arms.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 0,
2324
"repairPriority": 1,
2425
"materialProperty": [
2526
"default",

common/src/main/resources/data/miapi/modules/sword/blade/blade_dagger.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"blade",
3434
"polearm_spear"
3535
],
36+
"priority": 5,
3637
"repairPriority": -1,
3738
"allowedInSlots": [
3839
"sword_blade_small"

common/src/main/resources/data/miapi/modules/sword/blade/blade_greatsword.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 4,
2324
"materialProperty": [
2425
"default",
2526
"handheld",

common/src/main/resources/data/miapi/modules/sword/blade/blade_katana.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 2,
2324
"materialProperty": [
2425
"default",
2526
"handheld",

common/src/main/resources/data/miapi/modules/sword/blade/blade_longsword.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 1,
2324
"materialProperty": [
2425
"default",
2526
"handheld",

common/src/main/resources/data/miapi/modules/sword/blade/blade_rapier.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 3,
2324
"repairPriority": -1,
2425
"materialProperty": [
2526
"default",

common/src/main/resources/data/miapi/modules/sword/blade/blade_scythe.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
}
2525
],
26+
"priority": 3,
2627
"repairPriority": -1,
2728
"materialProperty": [
2829
"default",

common/src/main/resources/data/miapi/modules/sword/blade/blade_sickle.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
}
2525
],
26+
"priority": 6,
2627
"repairPriority": -1,
2728
"materialProperty": [
2829
"default",

common/src/main/resources/data/miapi/modules/sword/blade/blade_spear.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
}
2525
],
26+
"priority": 1,
2627
"repairPriority": -1,
2728
"materialProperty": [
2829
"default",

common/src/main/resources/data/miapi/modules/sword/blade/blade_sword.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 0,
2324
"repairPriority": -1,
2425
"materialProperty": [
2526
"default",

common/src/main/resources/data/miapi/modules/sword/blade/blade_throwing_knife.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
}
2222
},
23+
"priority": 7,
2324
"repairPriority": -1,
2425
"materialProperty": [
2526
"default",

common/src/main/resources/data/miapi/modules/sword/blade/blade_trident.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
}
2424
}
2525
],
26+
"priority": 2,
2627
"repairPriority": -1,
2728
"enchantments": {
2829
"allowed": [

common/src/main/resources/data/miapi/modules/sword/guard/guard_katana.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"default",
1818
"handheld"
1919
],
20+
"priority": 2,
2021
"repairPriority": 0,
2122
"durability": "[material.durability]* 0.25",
2223
"allowedMaterial": {

0 commit comments

Comments
 (0)