Skip to content

Commit e24e5f6

Browse files
author
Michael Hillcox
committed
Version match from 1.10.2 Fixing #11
1 parent fdf88cb commit e24e5f6

4 files changed

Lines changed: 95 additions & 81 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.world.getBlockState( xyz );
88+
IBlockState state = mc.world.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: 29 additions & 39 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;
@@ -29,51 +30,40 @@ private static boolean checkList( List<OreInfo> temp, OreInfo value, ItemStack s
2930
}
3031
return false;
3132
}
32-
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.
33+
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-
}
49-
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-
}
62-
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;
6342
}
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.") );
43+
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+
}
56+
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
}
76-
62+
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: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
public class GuiNewOre extends GuiScreen {
1616
private GuiTextField oreName;
17+
private GuiTextField oreMeta;
1718
private GuiTextField oreIdent;
1819
private GuiSlider redSlider;
1920
private GuiSlider greenSlider;
@@ -22,15 +23,16 @@ public class GuiNewOre extends GuiScreen {
2223

2324
private boolean oreNameCleared = false;
2425
private boolean oreIdentCleared = false;
25-
26+
private boolean oreMetaCleared = false;
27+
2628
@Override
2729
public void initGui()
28-
{
29-
// Called when the gui should be (re)created
30+
{
31+
// Called when the gui should be (re)created
3032
this.buttonList.add( new GuiButton( 98, width / 2 + 5, height / 2 + 58, 108, 20, "Add" ) ); // Add button
3133
this.buttonList.add( new GuiButton( 99, width / 2 - 108, height / 2 + 58, 108, 20, "Cancel" ) ); // Cancel button
3234

33-
//this.buttonList.add( new GuiButton( 8, width / 2 - 102, height / 2 + 80, 105, 20, "test" ) ); // Cancel button
35+
//this.buttonList.add( new GuiButton( 8, width / 2 - 102, height / 2 + 80, 105, 20, "test" ) ); // Cancel button
3436

3537
this.buttonList.add( new GuiSlider( 1, width / 2 - 108, height / 2 - 63, "Red", 0, 255 ) );
3638
this.buttonList.add( new GuiSlider( 2, width / 2 - 108, height / 2 - 40, "Green", 0, 255 ) );
@@ -57,13 +59,15 @@ public void initGui()
5759
redSlider.sliderValue = 0.0F;
5860
greenSlider.sliderValue = 1.0F;
5961
blueSlider.sliderValue = 0.0F;
60-
62+
6163
oreName = new GuiTextField( 1, this.fontRenderer, width / 2 - 108, height / 2 + 8, 220, 20 );
62-
oreIdent = new GuiTextField( 0, this.fontRenderer, width / 2 - 108, height / 2 + 32, 220, 20 );
63-
oreName.setText( "Block Name");
64-
oreIdent.setText( "ID:META" ); // TODO: oreName
64+
oreIdent = new GuiTextField( 0, this.fontRenderer, width / 2 - 108, height / 2 + 32, 185, 20 );
65+
oreMeta = new GuiTextField( 3, this.fontRenderer, width / 2 + 82, height / 2 + 32, 30, 20 );
66+
oreName.setText( "Gui Name");
67+
oreIdent.setText( "minecraft:grass" );
68+
oreMeta.setText( "Meta" );
6569
}
66-
70+
6771
@Override
6872
public void actionPerformed( GuiButton button ) // Called on left click of GuiButton
6973
{
@@ -72,22 +76,22 @@ public void actionPerformed( GuiButton button ) // Called on left click of GuiBu
7276
case 98: // Add
7377
int[] rgb = {(int)(redSlider.sliderValue * 255), (int)(greenSlider.sliderValue * 255), (int)(blueSlider.sliderValue * 255)};
7478

75-
OresSearch.add(oreIdent.getText(), oreName.getText(), rgb);
76-
79+
OresSearch.add(oreIdent.getText(), oreMeta.getText(), oreName.getText(), rgb);
80+
7781
mc.player.closeScreen();
7882
mc.displayGuiScreen( new GuiSettings() );
7983
break;
80-
84+
8185
case 99: // Cancel
8286
mc.player.closeScreen();
8387
mc.displayGuiScreen( new GuiSettings() );
8488
break;
85-
89+
8690
default:
8791
break;
8892
}
8993
}
90-
94+
9195
@Override
9296
protected void keyTyped( char par1, int par2 ) // par1 is char typed, par2 is ascii hex (tab=15 return=28)
9397
{
@@ -112,6 +116,17 @@ protected void keyTyped( char par1, int par2 ) // par1 is char typed, par2 is as
112116
else if( oreIdent.isFocused() )
113117
{
114118
oreIdent.textboxKeyTyped( par1, par2 );
119+
if( par2 == 15 )
120+
{
121+
oreIdent.setFocused( false );
122+
if( !oreMetaCleared )
123+
oreMeta.setText("");
124+
oreMeta.setFocused( true );
125+
}
126+
}
127+
else if( oreMeta.isFocused() )
128+
{
129+
oreMeta.textboxKeyTyped( par1, par2 );
115130
if( par2 == 28 )
116131
this.actionPerformed( addButton );
117132
}
@@ -125,25 +140,26 @@ else if( oreIdent.isFocused() )
125140
oreName.setFocused( true );
126141
break;
127142
case 1: // Exit on escape
128-
mc.displayGuiScreen( new GuiSettings() );
143+
mc.displayGuiScreen( new GuiSettings() );
129144
mc.player.closeScreen();
130145
default:
131146
break;
132147
}
133148
}
134149
}
135-
150+
136151
@Override
137152
public boolean doesGuiPauseGame() // Dont pause the game in single player.
138153
{
139154
return false;
140155
}
141-
156+
142157
@Override
143158
public void updateScreen()
144-
{
159+
{
145160
oreName.updateCursorCounter();
146161
oreIdent.updateCursorCounter();
162+
oreMeta.updateCursorCounter();
147163
}
148164

149165
@Override
@@ -158,6 +174,7 @@ public void drawScreen( int x, int y, float f )
158174

159175
oreName.drawTextBox();
160176
oreIdent.drawTextBox();
177+
oreMeta.drawTextBox();
161178

162179
Tessellator tessellator = Tessellator.getInstance();
163180
BufferBuilder tessellate = tessellator.getBuffer();
@@ -182,7 +199,7 @@ public void drawScreen( int x, int y, float f )
182199
// IIcon icon = net.minecraft.block.Block.getBlockById(3).getIcon( 1, 2 );
183200
// renderItem.renderIcon(50, 50, icon, 16, 16);
184201
}
185-
202+
186203
@Override
187204
public void mouseClicked( int x, int y, int mouse )
188205
{
@@ -191,9 +208,11 @@ public void mouseClicked( int x, int y, int mouse )
191208
} catch (IOException e) {
192209
e.printStackTrace();
193210
}
211+
194212
oreName.mouseClicked( x, y, mouse );
195213
oreIdent.mouseClicked( x, y, mouse );
196-
214+
oreMeta.mouseClicked( x, y, mouse );
215+
197216
if( oreName.isFocused() && !oreNameCleared )
198217
{
199218
oreName.setText( "" );
@@ -204,19 +223,29 @@ public void mouseClicked( int x, int y, int mouse )
204223
oreIdent.setText( "" );
205224
oreIdentCleared = true;
206225
}
226+
if( oreMeta.isFocused() && !oreMetaCleared )
227+
{
228+
oreMeta.setText( "" );
229+
oreMetaCleared = true;
230+
}
207231

208-
// TODO: fix bug where if you type then remove it the text will not be put back.
209-
if( !oreName.isFocused() && oreNameCleared && Objects.equals(oreName.getText(), ""))
210-
{
211-
oreNameCleared = false;
212-
oreName.setText( "Name of block");
213-
}
214-
215-
if( !oreIdent.isFocused() && oreIdentCleared && Objects.equals(oreIdent.getText(), ""))
216-
{
217-
oreIdentCleared = false;
218-
oreIdent.setText( "ID:META");
219-
}
232+
if( !oreName.isFocused() && oreNameCleared && Objects.equals(oreName.getText(), ""))
233+
{
234+
oreNameCleared = false;
235+
oreName.setText( "Gui Name");
236+
}
237+
238+
if( !oreIdent.isFocused() && oreIdentCleared && Objects.equals(oreIdent.getText(), ""))
239+
{
240+
oreIdentCleared = false;
241+
oreIdent.setText( "minecraft:grass");
242+
}
243+
244+
if( !oreMeta.isFocused() && oreMetaCleared && Objects.equals(oreMeta.getText(), ""))
245+
{
246+
oreMetaCleared = false;
247+
oreMeta.setText( "Meta");
248+
}
220249
//
221250
// if( mouse == 1 ) // Right clicked
222251
// {

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ else if( category.startsWith("customores.") )
4949
config.save();
5050
}
5151

52-
public static void add( String oreName, String ore, int[] color )
53-
{
52+
public static void add( String oreName, Integer id, Integer meta, int[] color )
53+
{
5454
config.load();
5555
String formattedname = oreName.replace("\\s+", "").toLowerCase();
5656

@@ -68,10 +68,6 @@ public static void add( String oreName, String ore, int[] color )
6868
}
6969
}
7070

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

8783
}

0 commit comments

Comments
 (0)