Skip to content

Commit cff6cfd

Browse files
author
Michael Hillcox
committed
A butt load of changes to support real editing and deleting
1 parent 728d6f2 commit cff6cfd

6 files changed

Lines changed: 43 additions & 34 deletions

File tree

src/main/java/com/xray/client/OresSearch.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void add( int oreId, int oreMeta, String name, int[] color ) // Ta
4242
}
4343
}
4444

45-
OresSearch.searchList.add( new OreInfo( name, oreId, oreMeta, color, true ) );
45+
OresSearch.searchList.add( new OreInfo( name, name.replaceAll("\\s+", ""), oreId, oreMeta, color, true ) );
4646
String notify = String.format( "[XRay] successfully added %s.", name );
4747
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(notify));
4848

@@ -56,19 +56,21 @@ public static void update( OreInfo original, String name, int[] color ) {
5656
return;
5757
}
5858

59+
OreInfo preserve = new OreInfo( original.getDisplayName(), original.getOreName(), original.getId(), original.getMeta(), original.color, original.draw );
60+
5961
OreInfo tmpNew = null;
6062
for ( OreInfo ore : OresSearch.searchList ) {
6163
if( ore == original ) {
62-
ore.oreName = name;
64+
ore.displayName = name;
6365
ore.color = color;
6466
tmpNew = ore;
6567
break;
6668
}
6769
}
6870

6971
if( tmpNew != null ) {
70-
ConfigHandler.updateInfo(original, tmpNew);
71-
String notify = String.format( "[XRay] successfully updated %s.", original.getOreName() );
72+
ConfigHandler.updateInfo(preserve, tmpNew);
73+
String notify = String.format( "[XRay] successfully updated %s.", preserve.getOreName() );
7274
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(notify));
7375
} else {
7476
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString( "[XRay] Looks like the Ore you've tried to edit does not exist?" ));
@@ -137,7 +139,7 @@ public static List<OreInfo> get() // Return the searchList, create it if needed.
137139
System.out.println("[XRay] Duplicate ore found in Ore Dictionary!!! (" + key + ")");
138140
continue;
139141
}
140-
temp.add(new OreInfo(value.oreName, Item.getIdFromItem(oreItem.getItem()), oreItem.getItemDamage(), value.color, value.draw));
142+
temp.add(new OreInfo(value.displayName, value.oreName, Item.getIdFromItem(oreItem.getItem()), oreItem.getItemDamage(), value.color, value.draw));
141143
//System.out.println( String.format("[Fgt XRay] Adding OreInfo( %s, %d, %d, %s, %b ) ", value.oreName, Item.getIdFromItem( oreItem.getItem() ), oreItem.getItemDamage(), value.color[0], value.draw ) );
142144
}
143145
}

src/main/java/com/xray/client/gui/GuiEditOre.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void initGui()
5050
blueSlider.sliderValue = (float)oreInfo.color[2]/255;
5151

5252
oreName = new GuiTextField( 1, this.fontRenderer, width / 2 - 97 , height / 2 - 63, 202, 20 );
53-
oreName.setText(this.oreInfo.getOreName());
53+
oreName.setText(this.oreInfo.getDisplayName());
5454

5555
this.buttonList.add( new GuiButton( 99, width / 2 - 100, height / 2 + 86, 72, 20, "Cancel" ) ); // Cancel button
5656
}

src/main/java/com/xray/client/gui/helper/HelperGuiList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public HelperGuiList(int id, int pageId, int x, int y, OreInfo ore ) {
2222
this.x = x;
2323
this.y = y;
2424
this.ore = ore;
25-
this.button = new GuiButton(id, x+25, y, 181, 20, ore.oreName + ": " + (ore.draw ? "On" : "Off"));
25+
this.button = new GuiButton(id, x+25, y, 181, 20, ore.displayName + ": " + (ore.draw ? "On" : "Off"));
2626

2727
}
2828

src/main/java/com/xray/common/config/ConfigHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static void setup(FMLPreInitializationEvent event )
3232
int[] color = {cat.get("red").getInt(), cat.get("green").getInt(), cat.get("blue").getInt()};
3333
boolean enabled = cat.get("enabled").getBoolean(false);
3434

35-
XRay.oredictOres.put(dictName, new OreInfo( guiName, id, meta, color, enabled ) );
35+
XRay.oredictOres.put(dictName, new OreInfo( guiName, guiName.replaceAll("\\s+", ""), id, meta, color, enabled ) );
3636

3737
}
3838
else if( category.startsWith("customores.") )
@@ -43,7 +43,7 @@ else if( category.startsWith("customores.") )
4343
int[] color = {cat.get("red").getInt(), cat.get("green").getInt(), cat.get("blue").getInt()};
4444
boolean enabled = cat.get("enabled").getBoolean(false);
4545

46-
XRay.customOres.add( new OreInfo( name, id, meta, color, enabled ) );
46+
XRay.customOres.add( new OreInfo( name, name.replaceAll("\\s+", ""), id, meta, color, enabled ) );
4747
}
4848
}
4949
config.save();
@@ -52,7 +52,7 @@ else if( category.startsWith("customores.") )
5252
public static void add( String oreName, Integer id, Integer meta, int[] color )
5353
{
5454
config.load();
55-
String formattedname = oreName.replace("\\s+", "").toLowerCase();
55+
String formattedname = oreName.replaceAll("\\s+", "").toLowerCase();
5656

5757
// check if entry exists
5858
for( String category : config.getCategoryNames() )
@@ -132,7 +132,7 @@ public static void updateInfo( OreInfo original, OreInfo newInfo )
132132
config.get(tmpCategory, "red", "").set( newInfo.color[0] );
133133
config.get(tmpCategory, "green", "").set( newInfo.color[1] );
134134
config.get(tmpCategory, "blue", "").set( newInfo.color[2] );
135-
config.get(tmpCategory, "name", "").set( newInfo.oreName );
135+
config.get(tmpCategory, "name", "").set( newInfo.displayName );
136136
break;
137137
}
138138
}

src/main/java/com/xray/common/config/DefaultConfig.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ public class DefaultConfig {
1616
// Below are the 'default' ores/blocks to add through the ore dictionary.
1717
private final static Map<String, OreInfo> defaults = new HashMap<String, OreInfo>()
1818
{{
19-
put("oreLapis", new OreInfo("Lapis", 0, 0, new int[]{0, 0, 255}, false) );
20-
put("oreCopper", new OreInfo("Copper", 0, 0, new int[]{204, 102, 0}, true) );
21-
put("oreTin", new OreInfo("Tin", 0, 0, new int[]{161, 161, 161}, true) );
22-
put("oreCobalt", new OreInfo("Cobalt", 0, 0, new int[]{0, 0, 255}, false) );
23-
put("oreArdite", new OreInfo("Ardite", 0, 0, new int[]{255, 153, 0}, false) );
24-
put("oreCertusQuartz", new OreInfo("Certus Quartz", 0, 0, new int[]{255, 255, 255}, false) );
25-
put("oreUranium", new OreInfo("Uranium", 0, 0, new int[]{0, 255, 0}, true) );
26-
put("oreDiamond", new OreInfo("Diamond", 0, 0, new int[]{136, 136, 255}, false) );
27-
put("blockDiamond", new OreInfo("Diamond Block", 0, 0, new int[]{136, 136, 255}, false) );
28-
put("oreEmerald", new OreInfo("Emerald", 0, 0, new int[]{0, 136, 10}, true) );
29-
put("oreGold", new OreInfo("Gold", 0, 0, new int[]{255, 255, 0}, false) );
30-
put("oreRedstone", new OreInfo("Redstone", 0, 0, new int[]{255, 0, 0}, false) );
31-
put("oreIron", new OreInfo("Iron", 0, 0, new int[]{170, 117, 37}, false) );
32-
put("oreSilver", new OreInfo("Silver", 0, 0, new int[]{143,143,143}, false) );
33-
put("oreQuartz", new OreInfo("Quartz", 0, 0, new int[]{30,74,0}, false) );
34-
put("oreCoal", new OreInfo("Coal", 0, 0, new int[]{0, 0, 0}, false ) );
19+
put("oreLapis", new OreInfo("Lapis", "Lapis", 0, 0, new int[]{0, 0, 255}, false) );
20+
put("oreCopper", new OreInfo("Copper", "Copper", 0, 0, new int[]{204, 102, 0}, true) );
21+
put("oreTin", new OreInfo("Tin", "Tin", 0, 0, new int[]{161, 161, 161}, true) );
22+
put("oreCobalt", new OreInfo("Cobalt", "Cobalt", 0, 0, new int[]{0, 0, 255}, false) );
23+
put("oreArdite", new OreInfo("Ardite", "Ardite", 0, 0, new int[]{255, 153, 0}, false) );
24+
put("oreCertusQuartz", new OreInfo("Certus Quartz", "CertusQuartz", 0, 0, new int[]{255, 255, 255}, false) );
25+
put("oreUranium", new OreInfo("Uranium", "Uranium", 0, 0, new int[]{0, 255, 0}, true) );
26+
put("oreDiamond", new OreInfo("Diamond", "Diamond", 0, 0, new int[]{136, 136, 255}, false) );
27+
put("blockDiamond", new OreInfo("Diamond Block", "DiamondBlock", 0, 0, new int[]{136, 136, 255}, false) );
28+
put("oreEmerald", new OreInfo("Emerald", "Emerald", 0, 0, new int[]{0, 136, 10}, true) );
29+
put("oreGold", new OreInfo("Gold", "Gold", 0, 0, new int[]{255, 255, 0}, false) );
30+
put("oreRedstone", new OreInfo("Redstone", "Redstone", 0, 0, new int[]{255, 0, 0}, false) );
31+
put("oreIron", new OreInfo("Iron", "Iron", 0, 0, new int[]{170, 117, 37}, false) );
32+
put("oreSilver", new OreInfo("Silver", "Silver", 0, 0, new int[]{143,143,143}, false) );
33+
put("oreQuartz", new OreInfo("Quartz", "Quartz", 0, 0, new int[]{30,74,0}, false) );
34+
put("oreCoal", new OreInfo("Coal", "Coal", 0, 0, new int[]{0, 0, 0}, false ) );
3535
}};
3636

3737
// Default block to add. Mostly just so people can add custom blocks manually through the config until I setup a gui for it.
3838
private final static List<OreInfo> custom = new ArrayList<OreInfo>()
3939
{{
40-
add( new OreInfo("Redstone Wire", Block.getIdFromBlock( Blocks.REDSTONE_WIRE ), 0, new int[]{255, 0, 0}, false) );
41-
add( new OreInfo("Chest", Block.getIdFromBlock( Blocks.CHEST ), 0, new int[]{255, 0, 255}, true) );
40+
add( new OreInfo("Redstone Wire", "RedstoneWire", Block.getIdFromBlock( Blocks.REDSTONE_WIRE ), 0, new int[]{255, 0, 0}, false) );
41+
add( new OreInfo("Chest", "Chest", Block.getIdFromBlock( Blocks.CHEST ), 0, new int[]{255, 0, 255}, true) );
4242
}};
4343

4444

@@ -54,10 +54,10 @@ public static void create(Configuration config) // Put default blocks and settin
5454
if( !OreDictionary.doesOreNameExist( key ) )
5555
continue;
5656

57-
String category = value.oreName.replaceAll("\\s+", "").toLowerCase(); // No whitespace or capitals in the config file categories
57+
String category = value.oreName; // No whitespace or capitals in the config file categories
5858

5959
config.get("oredict."+category, "dictname", "SOMETHINGBROKE").set( key ); // We need the capitals for the ore dictionary.
60-
config.get("oredict."+category, "name", "SOMETHINGBROKE").set( value.oreName );
60+
config.get("oredict."+category, "name", "SOMETHINGBROKE").set( value.displayName );
6161
config.get("oredict."+category, "id", -1).set( OreDictionary.getOreID( key ) );
6262
config.get("oredict."+category, "meta", -1).set( value.meta );
6363
config.get("oredict."+category, "red", -1).set( value.color[0] );
@@ -68,8 +68,8 @@ public static void create(Configuration config) // Put default blocks and settin
6868

6969
for( OreInfo ore : custom ) // Put custom block into the config file.
7070
{
71-
String name = ore.oreName.replaceAll("\\s+", "").toLowerCase(); // No whitespace or capitals in the config file categories.
72-
config.get("customores."+name, "name", "SOMETHINGBROKE").set( ore.oreName );
71+
String name = ore.oreName; // No whitespace or capitals in the config file categories.
72+
config.get("customores."+name, "name", "SOMETHINGBROKE").set( ore.displayName );
7373
config.get("customores."+name, "id", -1).set( ore.id );
7474
config.get("customores."+name, "meta", -1).set( ore.meta );
7575
config.get("customores."+name, "red", -1).set( ore.color[0] );

src/main/java/com/xray/common/reference/OreInfo.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Structure for damn near everything.
12
package com.xray.common.reference;
23

34
public class OreInfo
@@ -7,16 +8,22 @@ public class OreInfo
78
public int meta; // Metadata value of this block. 0 otherwise.
89
public int[] color; // Color in 0xRRGGBB to draw.
910
public boolean draw; // Should we draw this ore?
11+
public String displayName;
1012

11-
public OreInfo( String name, int id, int meta, int[] color, boolean draw )
13+
public OreInfo( String displayName, String name, int id, int meta, int[] color, boolean draw )
1214
{
1315
this.oreName = name;
16+
this.displayName = displayName;
1417
this.id = id;
1518
this.meta = meta;
1619
this.color = color;
1720
this.draw = draw;
1821
}
1922

23+
public String getDisplayName() {
24+
return displayName;
25+
}
26+
2027
public String getOreName() {
2128
return oreName;
2229
}

0 commit comments

Comments
 (0)