Skip to content

Commit dc02008

Browse files
author
Michael Hillcox
committed
Complete fix for #11
1 parent efaa917 commit dc02008

4 files changed

Lines changed: 68 additions & 52 deletions

File tree

src/main/java/com/fgtXray/client/ClientTick.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ static boolean blockFinder(boolean ForceAdd) {
8585
{
8686
for (int z = pz - radius; z < pz + radius; z++) // z axis.
8787
{
88-
BlockPos xyz = new BlockPos(x, y, z);
89-
IBlockState state = mc.theWorld.getBlockState( xyz );
88+
IBlockState state = mc.theWorld.getBlockState( new BlockPos(x, y, z) );
9089

9190
int id = Block.getIdFromBlock( state.getBlock() );
9291
int meta = state.getBlock().getMetaFromState(state);

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

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.*;
44

55
import com.fgtXray.config.ConfigHandler;
6+
import net.minecraft.block.Block;
67
import net.minecraft.client.Minecraft;
78
import net.minecraft.item.Item;
89
import net.minecraft.item.ItemStack;
@@ -30,50 +31,39 @@ private static boolean checkList( List<OreInfo> temp, OreInfo value, ItemStack s
3031
return false;
3132
}
3233

33-
public static void add( String oreIdent, String name, int[] color ) // Takes a string of id:meta or oreName to add to our search list.
34+
public static void add( String oreIdent, String oreMeta, String name, int[] color ) // Takes a string of id:meta or oreName to add to our search list.
3435
{
3536
oreIdent = oreIdent.replaceAll( "\\p{C}", "?" );
3637
int id, meta = 0;
3738

38-
if( oreIdent.contains( ":" ) ) // Hopefully a proper id:meta string.
39-
{
40-
String[] splitArray = oreIdent.split( ":" );
41-
42-
if( splitArray.length != 2 )
43-
{
44-
//System.out.println( String.format( "Can't add %s to searchList. Invalid format.", oreIdent ) );
45-
String notify = String.format( "[XRay] %s is not a valid identifier. Try id:meta (example 1:0 for stone) or oreName (example oreDiamond or mossyStone)", oreIdent );
46-
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString(notify));
47-
return;
48-
}
39+
if( oreIdent.equals("") || oreMeta.equals("") || name.equals("") ) {
40+
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString( "[XRay] You need to have all the inputs filled" ));
41+
return;
42+
}
4943

50-
try
51-
{
52-
id = Integer.parseInt( splitArray[0] );
53-
meta = Integer.parseInt( splitArray[1] );
54-
}
55-
catch( NumberFormatException e )
56-
{ // TODO: Some oredict ores are mod:block for some reason...
57-
//System.out.println( String.format( "%s is not a valid id:meta format.", oreIdent ) );
58-
String notify = String.format( "[XRay] %s contains data other than numbers and the colon. Failed to add.", oreIdent );
59-
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString(notify) );
60-
return;
61-
}
44+
if( oreIdent.contains( ":" ) ) {
45+
46+
Block tmpBlock = Block.getBlockFromName( oreIdent );
47+
if( tmpBlock != null ) {
48+
id = Block.getIdFromBlock( tmpBlock );
49+
try {
50+
meta = Integer.parseInt( oreMeta );
51+
} catch( NumberFormatException e ) {
52+
String notify = String.format( "[XRay] %s contains data other than numbers. Failed to add.", oreIdent );
53+
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString(notify) );
54+
return;
55+
}
6256

63-
}
64-
else
65-
{
66-
try
67-
{
68-
id = Integer.parseInt( oreIdent );
69-
meta = 0;
70-
}
71-
catch( NumberFormatException e )
72-
{
73-
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString("[XRay] Doesn't support in-game additions to the ore dictionary yet.. Failed to add.") );
57+
} else {
58+
String notify = String.format( "[XRay] %s is not a valid block name", oreIdent );
59+
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString(notify));
7460
return;
7561
}
7662

63+
} else {
64+
String notify = String.format( "[XRay] %s is not a valid identifier. Try modname:blockname (example minecraft:stone for stone)", oreIdent );
65+
mc.ingameGUI.getChatGUI().printChatMessage( new TextComponentString(notify));
66+
return;
7767
}
7868

7969
//System.out.println( String.format( "Adding ore: %s", oreIdent ) );
@@ -88,7 +78,7 @@ public static void add( String oreIdent, String name, int[] color ) // Takes a s
8878
String notify = String.format( "[XRay] successfully added %s.", oreIdent );
8979
mc.ingameGUI.getChatGUI().printChatMessage(new TextComponentString(notify));
9080

91-
ConfigHandler.add(name, oreIdent, color);
81+
ConfigHandler.add(name, id, meta, color);
9282
}
9383

9484
public static List<OreInfo> get() // Return the searchList, create it if needed.

src/main/java/com/fgtXray/client/gui/GuiNewOre.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fgtXray.client.OresSearch;
44
import com.fgtXray.reference.Ref;
5+
import net.minecraft.block.Block;
56
import net.minecraft.client.gui.FontRenderer;
67
import net.minecraft.client.gui.GuiButton;
78
import net.minecraft.client.gui.GuiScreen;
@@ -11,12 +12,14 @@
1112
import net.minecraft.client.renderer.VertexBuffer;
1213
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
1314
import net.minecraft.util.ResourceLocation;
15+
import net.minecraftforge.fml.common.registry.GameRegistry;
1416

1517
import java.io.IOException;
1618
import java.util.Objects;
1719

1820
public class GuiNewOre extends GuiScreen {
1921
private GuiTextField oreName;
22+
private GuiTextField oreMeta;
2023
private GuiTextField oreIdent;
2124
private GuiSlider redSlider;
2225
private GuiSlider greenSlider;
@@ -25,6 +28,7 @@ public class GuiNewOre extends GuiScreen {
2528

2629
private boolean oreNameCleared = false;
2730
private boolean oreIdentCleared = false;
31+
private boolean oreMetaCleared = false;
2832

2933
@Override
3034
public void initGui()
@@ -62,9 +66,11 @@ public void initGui()
6266
blueSlider.sliderValue = 0.0F;
6367

6468
oreName = new GuiTextField( 1, this.fontRendererObj, width / 2 - 108, height / 2 + 8, 220, 20 );
65-
oreIdent = new GuiTextField( 0, this.fontRendererObj, width / 2 - 108, height / 2 + 32, 220, 20 );
66-
oreName.setText( "Block Name");
67-
oreIdent.setText( "ID:META" ); // TODO: oreName
69+
oreIdent = new GuiTextField( 0, this.fontRendererObj, width / 2 - 108, height / 2 + 32, 185, 20 );
70+
oreMeta = new GuiTextField( 3, this.fontRendererObj, width / 2 + 82, height / 2 + 32, 30, 20 );
71+
oreName.setText( "Gui Name");
72+
oreIdent.setText( "minecraft:grass" );
73+
oreMeta.setText( "Meta" );
6874
}
6975

7076
@Override
@@ -75,7 +81,7 @@ public void actionPerformed( GuiButton button ) // Called on left click of GuiBu
7581
case 98: // Add
7682
int[] rgb = {(int)(redSlider.sliderValue * 255), (int)(greenSlider.sliderValue * 255), (int)(blueSlider.sliderValue * 255)};
7783

78-
OresSearch.add(oreIdent.getText(), oreName.getText(), rgb);
84+
OresSearch.add(oreIdent.getText(), oreMeta.getText(), oreName.getText(), rgb);
7985

8086
mc.thePlayer.closeScreen();
8187
mc.displayGuiScreen( new GuiSettings() );
@@ -115,6 +121,17 @@ protected void keyTyped( char par1, int par2 ) // par1 is char typed, par2 is as
115121
else if( oreIdent.isFocused() )
116122
{
117123
oreIdent.textboxKeyTyped( par1, par2 );
124+
if( par2 == 15 )
125+
{
126+
oreIdent.setFocused( false );
127+
if( !oreMetaCleared )
128+
oreMeta.setText("");
129+
oreMeta.setFocused( true );
130+
}
131+
}
132+
else if( oreMeta.isFocused() )
133+
{
134+
oreMeta.textboxKeyTyped( par1, par2 );
118135
if( par2 == 28 )
119136
this.actionPerformed( addButton );
120137
}
@@ -147,6 +164,7 @@ public void updateScreen()
147164
{
148165
oreName.updateCursorCounter();
149166
oreIdent.updateCursorCounter();
167+
oreMeta.updateCursorCounter();
150168
}
151169

152170
@Override
@@ -161,6 +179,7 @@ public void drawScreen( int x, int y, float f )
161179

162180
oreName.drawTextBox();
163181
oreIdent.drawTextBox();
182+
oreMeta.drawTextBox();
164183

165184
Tessellator tessellator = Tessellator.getInstance();
166185
VertexBuffer vertexbuffer = tessellator.getBuffer();
@@ -194,8 +213,10 @@ public void mouseClicked( int x, int y, int mouse )
194213
} catch (IOException e) {
195214
e.printStackTrace();
196215
}
216+
197217
oreName.mouseClicked( x, y, mouse );
198218
oreIdent.mouseClicked( x, y, mouse );
219+
oreMeta.mouseClicked( x, y, mouse );
199220

200221
if( oreName.isFocused() && !oreNameCleared )
201222
{
@@ -207,18 +228,28 @@ public void mouseClicked( int x, int y, int mouse )
207228
oreIdent.setText( "" );
208229
oreIdentCleared = true;
209230
}
231+
if( oreMeta.isFocused() && !oreMetaCleared )
232+
{
233+
oreMeta.setText( "" );
234+
oreMetaCleared = true;
235+
}
210236

211-
// TODO: fix bug where if you type then remove it the text will not be put back.
212237
if( !oreName.isFocused() && oreNameCleared && Objects.equals(oreName.getText(), ""))
213238
{
214239
oreNameCleared = false;
215-
oreName.setText( "Name of block");
240+
oreName.setText( "Gui Name");
216241
}
217242

218243
if( !oreIdent.isFocused() && oreIdentCleared && Objects.equals(oreIdent.getText(), ""))
219244
{
220245
oreIdentCleared = false;
221-
oreIdent.setText( "ID:META");
246+
oreIdent.setText( "minecraft:grass");
247+
}
248+
249+
if( !oreMeta.isFocused() && oreMetaCleared && Objects.equals(oreMeta.getText(), ""))
250+
{
251+
oreMetaCleared = false;
252+
oreMeta.setText( "Meta");
222253
}
223254
//
224255
// if( mouse == 1 ) // Right clicked

src/main/java/com/fgtXray/config/ConfigHandler.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ else if( category.startsWith("customores.") )
5050
config.save();
5151
}
5252

53-
public static void add( String oreName, String ore, int[] color )
53+
public static void add( String oreName, Integer id, Integer meta, int[] color )
5454
{
5555
config.load();
5656
String formattedname = oreName.replace("\\s+", "").toLowerCase();
@@ -69,10 +69,6 @@ public static void add( String oreName, String ore, int[] color )
6969
}
7070
}
7171

72-
int oreId = Integer.parseInt(ore.split( ":" )[0]);
73-
// Don't do this if it does not exist... Stupid me
74-
int oreMeta = ore.contains(":") ? Integer.parseInt(ore.split( ":" )[1]) : 0;
75-
7672
for( String category : config.getCategoryNames() )
7773
{
7874
if( category.startsWith("customores.") )
@@ -81,8 +77,8 @@ public static void add( String oreName, String ore, int[] color )
8177
config.get("customores."+formattedname, "green", "").set( color[1] );
8278
config.get("customores."+formattedname, "blue", "").set( color[2] );
8379
config.get("customores."+formattedname, "enabled", "false").set( true );
84-
config.get("customores."+formattedname, "id", "").set( oreId );
85-
config.get("customores."+formattedname, "meta", "").set( oreMeta );
80+
config.get("customores."+formattedname, "id", "").set( id );
81+
config.get("customores."+formattedname, "meta", "").set( meta );
8682
config.get("customores." + formattedname, "name", "").set(oreName);
8783

8884
}

0 commit comments

Comments
 (0)