Added default block summary.

Added csv reader.
This commit is contained in:
Thomas Guimbretiere committed 2013-07-03 21:11:50 +02:00
1 parent 00ea3d77cc
commit 4cbe727b81
7 files changed
+83 -15

No files matched your search

@@ -10,8 +10,11 @@ import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.logging.Level;
import au.com.bytecode.opencsv.CSVReader;
import net.minecraft.block.Block;
import codechicken.nei.api.API;
@@ -220,10 +223,11 @@ public class ExternalModulesHandler implements IWailaRegistrar {
}
@Override
public void registerDocTextFile(String modid, String filename) {
String docData = null;
public void registerDocTextFile(String filename) {
List<String[]> docData = null;
int nentries = 0;
try{
docData = this.readFileAsString(filename);
} catch (IOException e){
@@ -231,6 +235,19 @@ public class ExternalModulesHandler implements IWailaRegistrar {
return;
}
for (String[] ss : docData){
String modid = ss[0];
String name = ss[1];
String desc = "";
for (int i = 3; i < ss.length; i++)
desc += ss[i] + "\n";
if (!this.wikiDescriptions.containsKey(modid))
this.wikiDescriptions.put(modid, new LinkedHashMap <String, String>());
this.wikiDescriptions.get(modid).put(name, desc);
nentries += 1;
}
/*
String[] sections = docData.split(">>>>");
for (String s : sections){
s.trim();
@@ -247,6 +264,7 @@ public class ExternalModulesHandler implements IWailaRegistrar {
}
}
}
*/
mod_Waila.instance.log.log(Level.INFO, String.format("Registered %s entries from %s", nentries, filename));
}
@@ -261,14 +279,20 @@ public class ExternalModulesHandler implements IWailaRegistrar {
return this.wikiDescriptions.get(modid).get(name);
}
private String readFileAsString(String filePath) throws IOException {
private List<String[]> readFileAsString(String filePath) throws IOException {
// URL fileURL = this.getClass().getResource(filePath);
// File filedata = new File(fileURL);
// Reader paramReader = new InputStreamReader(this.getClass().getResourceAsStream(filePath));
// Reader paramReader = new InputStreamReader(this.getClass().getResourceAsStream(filePath));
InputStream in = getClass().getResourceAsStream(filePath);
BufferedReader input = new BufferedReader(new InputStreamReader(in));
CSVReader reader = new CSVReader(input);
List<String[]> myEntries = reader.readAll();
reader.close();
return myEntries;
/*
StringBuffer fileData = new StringBuffer();
//BufferedReader reader = new BufferedReader(paramReader);
@@ -280,5 +304,6 @@ public class ExternalModulesHandler implements IWailaRegistrar {
}
input.close();
return fileData.toString();
*/
}
}
@@ -139,7 +139,7 @@ public class HUDHandlerVanilla implements IWailaDataProvider {
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), redstone);
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), jukebox);
ExternalModulesHandler.instance().registerDocTextFile("Minecraft", "/mcp/mobius/waila/addons/vanillamc/WikiData.txt");
ExternalModulesHandler.instance().registerDocTextFile("/mcp/mobius/waila/addons/vanillamc/WikiData.csv");
}
@@ -0,0 +1,5 @@
Minecraft,tile.stone,,This is basic stone.,
Minecraft,item.swordDiamond,,This is a diamond sword.,Good at killing zombies and creepers.
Minecraft,item.pickaxeWood,,Your very first pickaxe.,"Not good at anything, beside getting splinters."
Minecraft,item.pickaxeDiamond,,"The ultimate pickaxe, made out of refined diamonds.",
Minecraft,item.pickaxeIron,,"Sturdy, solid, efficient. Your best friend.",
1 Minecraft tile.stone This is basic stone.
2 Minecraft item.swordDiamond This is a diamond sword. Good at killing zombies and creepers.
3 Minecraft item.pickaxeWood Your very first pickaxe. Not good at anything, beside getting splinters.
4 Minecraft item.pickaxeDiamond The ultimate pickaxe, made out of refined diamonds.
5 Minecraft item.pickaxeIron Sturdy, solid, efficient. Your best friend.
+1 -1
View File
@@ -18,7 +18,7 @@ public interface IWailaRegistrar {
public void registerHeadProvider (IWailaDataProvider dataProvider, Class block);
public void registerBodyProvider (IWailaDataProvider dataProvider, Class block);
public void registerDocTextFile (String modid, String filename);
public void registerDocTextFile (String filename);
public void registerShortDataProvider (IWailaSummaryProvider dataProvider, Class item);
}
+5 -5
View File
@@ -21,14 +21,14 @@ public class GuiIngameWiki extends BaseWailaScreen {
this.widTable = new ContainerTable(this);
this.widItemName = new Label("");
this.widReader.setWidth(this.res.getScaledWidth()-this.res.getScaledWidth()/4 - 16);
this.widReader.setWidth(this.res.getScaledWidth()-this.res.getScaledWidth()/3 - 16);
this.widReader.setHeight(this.res.getScaledHeight() - 24);
this.widReader.setBackgroundColor(0x66888888);
this.widStack.setScale(4.0f);
this.widTable.setAutosize(false);
this.widTable.setWidth(this.res.getScaledWidth()/4 - 8);
this.widTable.setWidth(this.res.getScaledWidth()/3 - 8);
this.widTable.setHeight(this.res.getScaledHeight() - 16 - this.widStack.getHeight());
this.widTable.setColumns(8, "\u00a7a\u00a7oEntry", "\u00a7a\u00a7oValue");
@@ -42,9 +42,9 @@ public class GuiIngameWiki extends BaseWailaScreen {
{
super.drawScreen(i, j, f);
widTable.draw(4, this.widStack.getHeight() + 16, 1000);
widItemName.draw(this.res.getScaledWidth()/8-widItemName.getWidth()/2, this.widStack.getHeight(), 0);
widReader.draw(this.res.getScaledWidth()/4 + 8, 8, 0);
widStack.draw(this.res.getScaledWidth()/8-widStack.getWidth()/2, 0, 0);
widItemName.draw(this.res.getScaledWidth()/6-widItemName.getWidth()/2, this.widStack.getHeight(), 0);
widReader.draw(this.res.getScaledWidth()/3 + 8, 8, 0);
widStack.draw(this.res.getScaledWidth()/6-widStack.getWidth()/2, 0, 0);
}
@Override
@@ -7,11 +7,13 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.item.EnumArmorMaterial;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IShearable;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaSummaryProvider;
@@ -44,6 +46,33 @@ public class SummaryProviderDefault implements IWailaSummaryProvider {
currentSummary.put("Armor Value", this.getDamageReduction(stack) != null?String.valueOf(this.getDamageReduction(stack)):null);
currentSummary.put("Enchant", this.getArmorEnchantability(stack) != null?String.valueOf(this.getArmorEnchantability(stack)):null);
}
} else {
//We have an ItemBlock
ItemBlock itemBlock = (ItemBlock)stack.getItem();
Block block = Block.blocksList[itemBlock.getBlockID()];
try{currentSummary.put("Hardness", String.valueOf(block.getBlockHardness(Minecraft.getMinecraft().theWorld, 0, 0, 0)));} catch (Exception e){};
try{currentSummary.put("Resistance", String.valueOf(block.getExplosionResistance(null)));} catch (Exception e){};
try{
ArrayList<ItemStack> droppedStacks = block.getBlockDropped(Minecraft.getMinecraft().theWorld, 0, 0, 0, stack.getItemDamage(), 3);
if (droppedStacks.size() == 1)
currentSummary.put("Drop", droppedStacks.get(0).getDisplayName());
else
for (int i=0; i < droppedStacks.size(); i++)
currentSummary.put(String.format("Drop %s", i), droppedStacks.get(i).getDisplayName());
}catch (Exception e){System.out.printf("%s\n",e);};
try{
if (block instanceof IShearable){
IShearable shearable = (IShearable)block;
ArrayList<ItemStack> droppedStacks = shearable.onSheared(null, Minecraft.getMinecraft().theWorld, 0, 0, 0, 3);
if (droppedStacks.size() == 1)
currentSummary.put("Sheared", droppedStacks.get(0).getDisplayName());
else
for (int i=0; i < droppedStacks.size(); i++)
currentSummary.put(String.format("Sheared %s", i), droppedStacks.get(i).getDisplayName());
}
}catch (Exception e){System.out.printf("%s\n",e);};
}
+12 -3
View File
@@ -64,10 +64,19 @@ public class WikiHandler implements IContainerInputHandler {
wikiScreen.widStack.setStack(stackover);
wikiScreen.widItemName.setLabel(stackover.getDisplayName());
LinkedHashMap<String, String> entries = SummaryProvider.instance().getSummary(stackover, (IWailaConfigHandler)(ConfigHandler.instance()));
LinkedHashMap<String, String> entries = SummaryProvider.instance().getSummary(stackover, (IWailaConfigHandler)(ConfigHandler.instance()));
int nvalidentries = 0;
for (String s : entries.keySet())
if (entries.get(s) != null)
wikiScreen.widTable.addRow(new Label(s), new Label(entries.get(s)));
if (entries.get(s) != null)
nvalidentries += 1;
if (nvalidentries == 0)
for (int i = 0; i < 6; i++)
wikiScreen.widTable.addRow(new Label(""), new Label(entries.get("")));
else
for (String s : entries.keySet())
if (entries.get(s) != null)
wikiScreen.widTable.addRow(new Label(s), new Label(entries.get(s)));
mc.displayGuiScreen(wikiScreen);