Skip to content

Commit f9818fe

Browse files
committed
add prefixed version for replacements
1 parent 4f78e47 commit f9818fe

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

src/main/java/fn10/bedrockr/addons/source/SourceBiomeElement.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import java.util.List;
1616
import java.util.Map;
1717

18-
import javax.swing.DefaultComboBoxModel;
1918
import javax.swing.ImageIcon;
20-
import javax.swing.JComboBox;
2119
import javax.swing.SpringLayout;
2220

2321
import com.google.gson.internal.LinkedTreeMap;
@@ -35,8 +33,14 @@
3533
public class SourceBiomeElement implements ElementSource<BiomeFile> {
3634

3735
private static transient String[] vanillaBiomeNames = null;
36+
private static transient String[] prefixedVanillaBiomeNames = null;
37+
38+
public static String[] getPrefixedVanillaBiomeNames() {
39+
if (prefixedVanillaBiomeNames == null)
40+
getVanillaBiomeNames();
41+
return prefixedVanillaBiomeNames;
42+
}
3843

39-
@SuppressWarnings("unchecked")
4044
public static String[] getVanillaBiomeNames() {
4145
if (vanillaBiomeNames != null) {
4246
return vanillaBiomeNames;
@@ -63,11 +67,14 @@ public static String[] getVanillaBiomeNames() {
6367

6468
HttpResponse<String> biomesRes = client.send(biomesJsonReq, BodyHandlers.ofString());
6569
List<String> biomeNames = new ArrayList<String>();
70+
List<String> biomeNamesPrefix = new ArrayList<String>();
6671
for (Map<String, Object> biomeEntry : (ArrayList<LinkedTreeMap<String, Object>>) gson
6772
.fromJson(biomesRes.body(), List.class)) {
6873
biomeNames.add(biomeEntry.get("name").toString());
74+
biomeNamesPrefix.add("minecraft:" + biomeEntry.get("name").toString());
6975
}
7076
vanillaBiomeNames = biomeNames.toArray(new String[0]);
77+
prefixedVanillaBiomeNames = biomeNamesPrefix.toArray(vanillaBiomeNames);
7178
return vanillaBiomeNames;
7279
} catch (Exception e) {
7380
fn10.bedrockr.Launcher.LOG.log(java.util.logging.Level.SEVERE, "Exception thrown", e);
@@ -143,11 +150,13 @@ public RElementEditingScreen getBuilderWindow(Window Parent, ElementCreationList
143150
"BiomeID", "Biome ID", false, getSerilizedClass(), serilized, Workspace);
144151
RElementValue compsVal = new RElementValue(screen, HashMap.class, new FieldFilters.IDStringFilter(),
145152
"Comps", "Biome Components", false, getSerilizedClass(), serilized, Workspace);
146-
/*if (idVal.Input instanceof JComboBox input) {
147-
input.setModel(new DefaultComboBoxModel<String>(vanillaBiomeNames));
148-
input.setName("dd");
149-
input.setSelectedItem(serilized.BiomeID);
150-
}*/
153+
/*
154+
* if (idVal.Input instanceof JComboBox input) {
155+
* input.setModel(new DefaultComboBoxModel<String>(vanillaBiomeNames));
156+
* input.setName("dd");
157+
* input.setSelectedItem(serilized.BiomeID);
158+
* }
159+
*/
151160
screen.addField(elementnameVal);
152161
screen.addField(idVal);
153162
screen.addField(compsVal);

src/main/java/fn10/bedrockr/addons/source/supporting/BiomeComponents.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.List;
44

55
import fn10.bedrockr.addons.RMapElement;
6-
import fn10.bedrockr.addons.source.SourceBiomeElement;
76
import fn10.bedrockr.addons.source.interfaces.RMapElementProvider;
87
import fn10.bedrockr.utils.RAnnotation.StringDropdownField;
98

@@ -85,7 +84,7 @@ public static class Replacement {
8584
* must not contain namespaces (yes they have too microsoft). Value must have at
8685
* least 1 items.
8786
*/
88-
@StringDropdownField({"_VANILLABIOMES"})
87+
@StringDropdownField({"_PREFIXEDVANILLABIOMES"})
8988
public List<String> targets;
9089
}
9190

src/main/java/fn10/bedrockr/windows/componets/RElementMapValue.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import javax.naming.NameNotFoundException;
1717
import javax.swing.BoxLayout;
1818
import javax.swing.JButton;
19-
import javax.swing.JCheckBox;
2019
import javax.swing.JColorChooser;
2120
import javax.swing.JComboBox;
2221
import javax.swing.JLabel;

src/main/java/fn10/bedrockr/windows/componets/RElementValue.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ protected RElementValue(Window parentFrame, Class<?> InputType, FieldFilter Filt
256256
JComboBox<String> newInput;
257257
if (anno.value()[0].equals("_VANILLABIOMES"))
258258
newInput = new JComboBox<String>(SourceBiomeElement.getVanillaBiomeNames());
259+
else if (anno.value()[0].equals("_PREFIXEDVANILLABIOMES"))
260+
newInput = new JComboBox<String>(SourceBiomeElement.getPrefixedVanillaBiomeNames());
259261
else
260262
newInput = new JComboBox<String>(anno.value());
261263

@@ -272,6 +274,19 @@ protected RElementValue(Window parentFrame, Class<?> InputType, FieldFilter Filt
272274
}
273275
}
274276

277+
JButton removeButton = new JButton("-");
278+
279+
toAdd.Lay.putConstraint(SpringLayout.VERTICAL_CENTER, removeButton, 0,
280+
SpringLayout.VERTICAL_CENTER, toAdd);
281+
toAdd.Lay.putConstraint(SpringLayout.WEST, toAdd.Input, 3, SpringLayout.EAST, removeButton);
282+
283+
toAdd.add(removeButton);
284+
removeButton.addActionListener(ac -> {
285+
HashMapInnerPane.remove(toAdd);
286+
HashMapInnerPane.repaint();
287+
HashMapInnerPane.revalidate();
288+
});
289+
275290
toAdd.setAlignmentX(0.5f);
276291

277292
HashMapInnerPane.add(Box.createVerticalStrut(10));
@@ -341,19 +356,17 @@ protected RElementValue(Window parentFrame, Class<?> InputType, FieldFilter Filt
341356
} else if (anno != null && field != null) { // dropdown string
342357
if (anno.value()[0].equals("_VANILLABIOMES"))
343358
Input = new JComboBox<String>(SourceBiomeElement.getVanillaBiomeNames());
359+
else if (anno.value()[0].equals("_PREFIXEDVANILLABIOMES"))
360+
Input = new JComboBox<String>(SourceBiomeElement.getPrefixedVanillaBiomeNames());
344361
else
345362
Input = new JComboBox<String>(anno.value());
346363
try {
347364
// if its strict, dont make it editable
348365
((JComboBox<String>) Input).setEditable(!anno.strict());
349366
if (!FromEmpty) {
350367
((JComboBox<String>) Input).setSelectedItem(field.get(TargetFile));
351-
} else {
352-
if (anno.value()[0].equals("_VANILLABIOMES"))
353-
((JComboBox<String>) Input)
354-
.setSelectedItem(SourceBiomeElement.getVanillaBiomeNames()[0]);
355-
else
356-
((JComboBox<String>) Input).setSelectedItem(anno.value()[0]);
368+
} else if (anno.strict()) {
369+
((JComboBox<String>) Input).setSelectedIndex(0);
357370
}
358371
} catch (Exception e) {
359372

@@ -935,6 +948,8 @@ else if (!InputType.isAssignableFrom(value.getClass())) {
935948
JComboBox<String> newInput;
936949
if (anno.value()[0].equals("_VANILLABIOMES")) {
937950
newInput = new JComboBox<String>(SourceBiomeElement.getVanillaBiomeNames());
951+
} else if (anno.value()[0].equals("_PREFIXEDVANILLABIOMES")) {
952+
newInput = new JComboBox<String>(SourceBiomeElement.getPrefixedVanillaBiomeNames());
938953
} else {
939954
newInput = new JComboBox<String>(anno.value());
940955
}
@@ -952,6 +967,19 @@ else if (!InputType.isAssignableFrom(value.getClass())) {
952967
((JComboBox<String>) newInput).setSelectedItem(entry);
953968
}
954969

970+
JButton removeButton = new JButton("-");
971+
972+
toAdd.Lay.putConstraint(SpringLayout.VERTICAL_CENTER, removeButton, 0, SpringLayout.VERTICAL_CENTER,
973+
toAdd);
974+
toAdd.Lay.putConstraint(SpringLayout.WEST, toAdd.Input, 3, SpringLayout.EAST, removeButton);
975+
976+
toAdd.add(removeButton);
977+
removeButton.addActionListener(ac -> {
978+
HashMapInnerPane.remove(toAdd);
979+
HashMapInnerPane.repaint();
980+
HashMapInnerPane.revalidate();
981+
});
982+
955983
HashMapInnerPane.add(Box.createRigidArea(new Dimension(100, 10)));
956984
HashMapInnerPane.add(toAdd);
957985
}
@@ -961,7 +989,7 @@ else if (!InputType.isAssignableFrom(value.getClass())) {
961989
} else if (Map.class.isAssignableFrom(InputType)) {
962990
try {
963991
for (Map.Entry<Object, Object> entry : ((HashMap<Object, Object>) value).entrySet()) {
964-
var ToAdd = new RElementMapValue(parentFrame,
992+
RElementMapValue ToAdd = new RElementMapValue(parentFrame,
965993
RMapElement.LookupMap.get(entry.getKey().toString()));
966994
ToAdd.setVal(entry.getValue());
967995

@@ -1060,7 +1088,7 @@ public Object getValue() {
10601088
var casted = ((JComboBox<String>) Input);
10611089
return (casted.getSelectedIndex() == 0);
10621090
} else if (Map.class.isAssignableFrom(InputType)) {
1063-
var mapToBuild = new HashMap<RMapElement, Object>();
1091+
HashMap<RMapElement, Object> mapToBuild = new HashMap<RMapElement, Object>();
10641092
for (Component comp : HashMapInnerPane.getComponents()) {
10651093
if (comp instanceof RElementMapValue remv) {
10661094
RElementMapValue mapElement = remv;

0 commit comments

Comments
 (0)