次のコードの 3 行目で型の不一致エラーが発生し続けます。
try
{
int l = item.b(itemstack);
String s = itemstack.l() + "@" + l;
if (!hashset.contains(s))
{
list.add(itemstack);
hashset.add(s);
}
}
これを修正する方法がわかりません (IDE の推奨事項を使用すると、コードの機能が壊れてしまいます)。
私が取り組んでいる完全なクラスファイルは次のとおりです。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.text.FieldPosition;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.client.Minecraft;
public class TMIUtils
{
public static final String CONFIG_FILENAME = "TooManyItems.txt";
public static Minecraft getMinecraft()
{
try
{
Field field = Minecraft.class.getDeclaredField("a");
field.setAccessible(true);
return (Minecraft)field.get(null);
}
catch (IllegalAccessException illegalaccessexception)
{
illegalaccessexception.printStackTrace();
}
catch (NoSuchFieldException nosuchfieldexception)
{
nosuchfieldexception.printStackTrace();
}
return null;
}
public static void loadPreferences(TMIConfig tmiconfig)
{
try
{
Map map = tmiconfig.getSettings();
File file = new File(Minecraft.a("minecraft"), "TooManyItems.txt");
if (file.exists())
{
BufferedReader bufferedreader = new BufferedReader(new FileReader(file));
String s;
while ((s = bufferedreader.readLine()) != null)
{
String[] as = s.split(":", 2);
if ((as.length > 1) && (map.containsKey(as[0])))
{
map.put(as[0], as[1]);
}
}
bufferedreader.close();
for (int i = 0; i < tmiconfig.getNumSaves(); i++)
{
tmiconfig.decodeState(i, (String)map.get("save" + (i + 1)));
}
}
}
catch (Exception exception)
{
System.out.println(exception);
}
}
public static void savePreferences(TMIConfig tmiconfig)
{
try
{
Map map = tmiconfig.getSettings();
File file = new File(Minecraft.a("minecraft"), "TooManyItems.txt");
PrintWriter printwriter = new PrintWriter(new FileWriter(file));
String s;
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext(); printwriter.println(s + ":" + (String)map.get(s)))
{
s = (String)iterator.next();
}
printwriter.close();
}
catch (Exception exception)
{
System.out.println(exception);
}
}
public static void loadItems(TMIConfig tmiconfig)
{
List list = tmiconfig.getItems();
list.clear();
sv[] aitem = sv.f;
int i = aitem.length;
int WiringID = 0;
try
{
Class.forName("mod_RedPowerWiring");
WiringID = ((Integer)ModLoader.getPrivateValue(mod_RedPowerWiring.class, null, "WiringID")).intValue();
}
catch (Exception exception)
{
}
for (int j = 0; j < i; j++)
{
sv item = aitem[j];
if (item == null)
{
continue;
}
TMIConfig _tmp = tmiconfig;
if (!TMIConfig.isItemIncluded(item.br))
{
continue;
}
HashSet hashset = new HashSet();
short byte0 = (short)(tmiconfig.areDamageVariantsShown() ? 32767 : 0);
for (int k = 0; k <= byte0; k++)
{
ul itemstack = new ul(item, item.d(), k);
if ((k > 15) && (item.br != WiringID))
{
break;
}
try
{
int l = item.b(itemstack);
String s = itemstack.l() + "@" + l;
if (!hashset.contains(s))
{
list.add(itemstack);
hashset.add(s);
}
}
catch (NullPointerException nullpointerexception)
{
}
catch (IndexOutOfBoundsException indexoutofboundsexception)
{
}
}
}
}
public static void safeReportException(Exception exception) {
try {
SimpleDateFormat simpledateformat = new SimpleDateFormat(".yyyyMMdd.HHmmss");
StringBuffer stringbuffer = new StringBuffer();
simpledateformat.format(new Date(), stringbuffer, new FieldPosition(1));
String s = "tmi" + stringbuffer.toString() + ".txt";
File file = new File(Minecraft.a("minecraft"), s);
PrintWriter printwriter = new PrintWriter(new FileWriter(file));
printwriter.print("[code]TMI Version: 1.7.2 2011-07-01\n");
exception.printStackTrace(printwriter);
printwriter.println("[/code]");
printwriter.close();
getMinecraft().v.a("Error written to " + s);
}
catch (Exception exception1)
{
System.out.println("Error during safeReportException:");
exception1.printStackTrace();
}
}
public static String itemDisplayName(ul itemstack)
{
try
{
String s = wv.a().b(itemstack.l());
if (!s.trim().equals(""))
{
return s;
}
} catch (NullPointerException nullpointerexception) {
}
return "Unnamed";
}
public static boolean isValidItem(ul itemstack)
{
return (itemstack == null) || ((itemstack.c >= 0) && (itemstack.c < sv.f.length) && (sv.f[itemstack.c] != null));
}
public static ul getValidItem(ul itemstack)
{
if (isValidItem(itemstack))
{
return itemstack;
}
return new ul(lr.at);
}
public static String getValidItemDisplayName(ul itemstack)
{
if (isValidItem(itemstack))
{
return itemDisplayName(itemstack);
}
return "Undefined Item";
}
public static void deleteHeldItem()
{
getMinecraft().h.as.b((ul)null);
}
public static ul getHeldItem()
{
return getMinecraft().h.as.j();
}
public static void giveStack(ul itemstack, TMIConfig tmiconfig)
{
giveStack(itemstack, tmiconfig, itemstack.a);
}
public static void giveStack(ul itemstack, TMIConfig tmiconfig, int i)
{
ul itemstack1 = copyStack(itemstack, i);
Minecraft minecraft = getMinecraft();
if (TMIConfig.isMultiplayer())
{
NumberFormat numberformat = NumberFormat.getIntegerInstance();
numberformat.setGroupingUsed(false);
MessageFormat messageformat = new MessageFormat((String)tmiconfig.getSettings().get("give-command"));
messageformat.setFormatByArgumentIndex(1, numberformat);
messageformat.setFormatByArgumentIndex(2, numberformat);
messageformat.setFormatByArgumentIndex(3, numberformat);
Object[] aobj = { minecraft.h.l, Integer.valueOf(itemstack1.c), Integer.valueOf(itemstack1.a), Integer.valueOf(itemstack1.i()) };
minecraft.h.a(messageformat.format(aobj));
}
else {
minecraft.h.as.a(itemstack1);
}
}
public static ul copyStack(ul itemstack, int i)
{
if (itemstack == null)
{
return null;
}
itemstack.a += i;
return itemstack.a(i);
}
public static ul copyStack(ul itemstack)
{
if (itemstack == null)
{
return null;
}
return copyStack(itemstack, itemstack.a);
}
public static void updateUnlimitedItems()
{
if ((TMIConfig.isMultiplayer()) || (!TMIConfig.getInstance().isEnabled()))
{
return;
}
ul[] aitemstack = getMinecraft().h.as.a;
int i = aitemstack.length;
for (int j = 0; j < i; j++)
{
ul itemstack1 = aitemstack[j];
if (itemstack1 == null)
{
continue;
}
if ((itemstack1.a < 0) || (itemstack1.a > 64))
{
itemstack1.a = 111;
}
if (itemstack1.i() >= 0)
continue;
setStackDamage(itemstack1, -32000);
}
ul itemstack = getHeldItem();
if ((itemstack != null) && (itemstack.a > 64))
{
itemstack.a = -1;
}
}
public static void setStackDamage(ul itemstack, int i)
{
try
{
Field[] afield = ul.class.getDeclaredFields();
int j = afield.length;
int k = 0;
while (k < j)
{
Field field = afield[k];
if (field.getName().equals("d"))
{
field.setAccessible(true);
field.setInt(itemstack, i);
break;
}
k++;
}
}
catch (Exception exception)
{
System.out.println(exception);
}
}
}