Added Vanilla module.

Added ID:Metadata display (optional)
This commit is contained in:
Thomas Guimbretiere committed 2013-06-15 18:09:22 +02:00
1 parent 78c8c9a2ad
commit e953471d3e
8 files changed
+119 -20

No files matched your search

+5 -1
View File
@@ -12,6 +12,7 @@ import mcp.mobius.waila.addons.buildcraft.HUDHandlerBCTanks;
import mcp.mobius.waila.addons.ic2.HUDHandlerIC2Generator;
import mcp.mobius.waila.addons.ic2.HUDHandlerIC2Machine;
import mcp.mobius.waila.addons.ic2.HUDHandlerIC2Storage;
import mcp.mobius.waila.addons.vanillamc.HUDHandlerVanilla;
import mcp.mobius.waila.gui.ConfigKeyHandler;
import mcp.mobius.waila.handlers.HUDHandlerExternal;
import mcp.mobius.waila.handlers.HUDHandlerWaila;
@@ -26,9 +27,10 @@ public class ProxyClient extends ProxyServer {
public void registerHandlers(){
GuiContainerManager.addTooltipHandler(new TooltipHandlerWaila());
//GuiContainerManager.addInputHandler(new EnchantementHandler());
API.registerHighlightHandler(new HUDHandlerWaila(), ItemInfo.Layout.FOOTER);
API.registerHighlightHandler(new HUDHandlerExternal(), ItemInfo.Layout.HEADER);
API.registerHighlightHandler(new HUDHandlerExternal(), ItemInfo.Layout.BODY);
API.registerHighlightHandler(new HUDHandlerWaila(), ItemInfo.Layout.FOOTER);
API.registerHighlightHandler(new HUDHandlerWaila(), ItemInfo.Layout.HEADER);
//API.registerHighlightIdentifier(2000, new HUDHandlerExternal());
KeyBindingRegistry.registerKeyBinding(new ConfigKeyHandler());
@@ -38,6 +40,8 @@ public class ProxyClient extends ProxyServer {
public void registerMods(){
HUDHandlerVanilla.register();
/* BETTER BARRELS */
/*
try {
+8 -3
View File
@@ -52,9 +52,14 @@ public class ConfigHandler implements IWailaConfigHandler {
}
@Override
public boolean getConfig(String key){
public boolean getConfig(String key, boolean defvalue){
mod_Waila.instance.config.load();
Property prop = mod_Waila.instance.config.get(Configuration.CATEGORY_GENERAL, key, true);
return prop.getBoolean(true);
Property prop = mod_Waila.instance.config.get(Configuration.CATEGORY_GENERAL, key, defvalue);
return prop.getBoolean(defvalue);
}
@Override
public boolean getConfig(String key){
return this.getConfig(key, true);
}
}
@@ -0,0 +1,74 @@
package mcp.mobius.waila.addons.vanillamc;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import mcp.mobius.waila.addons.ExternalModulesHandler;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataProvider;
public class HUDHandlerVanilla implements IWailaDataProvider {
static int mobSpawnerID = Block.mobSpawner.blockID;
static int cropsID = Block.crops.blockID;
static int melonStemID = Block.melonStem.blockID;
static int pumpkinStemID = Block.pumpkinStem.blockID;
static int carrotID = Block.carrot.blockID;
static int potatoID = Block.potato.blockID;
@Override
public ItemStack getWailaStack(World world, EntityPlayer player, MovingObjectPosition mop, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, IWailaConfigHandler config) {
int blockID = world.getBlockId(mop.blockX, mop.blockY, mop.blockZ);
TileEntity entity = world.getBlockTileEntity(mop.blockX, mop.blockY, mop.blockZ);
/* Mob spawner handler */
if (blockID == mobSpawnerID && entity instanceof TileEntityMobSpawner && config.getConfig("vanilla.showspawntype")){
String name = currenttip.get(0);
String mobname = ((TileEntityMobSpawner)entity).func_98049_a().getEntityNameToSpawn();
currenttip.set(0, String.format("%s (%s)", name, mobname));
}
return currenttip;
}
@Override
public List<String> getWailaBody(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, IWailaConfigHandler config) {
int blockID = world.getBlockId(mop.blockX, mop.blockY, mop.blockZ);
/* Crops */
if (config.getConfig("vanilla.showgrowthvalue"))
if (blockID == cropsID || blockID == melonStemID || blockID == pumpkinStemID || blockID == carrotID || blockID == potatoID){
float growthValue = ((float)world.getBlockMetadata(mop.blockX, mop.blockY, mop.blockZ) / 7.0F) * 100.0F;
if (growthValue != 100.0)
currenttip.add(String.format("Growth : %.0f %%", growthValue));
else
currenttip.add("Growth : Mature");
}
return currenttip;
}
public static void register(){
ExternalModulesHandler.instance().addConfig("VanillaMC", "vanilla.showspawntype", "Spawner type");
ExternalModulesHandler.instance().addConfig("VanillaMC", "vanilla.showgrowthvalue", "Growth value");
ExternalModulesHandler.instance().registerHeadProvider(new HUDHandlerVanilla(), mobSpawnerID);
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), cropsID);
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), melonStemID);
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), pumpkinStemID);
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), carrotID);
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), potatoID);
}
}
@@ -18,6 +18,9 @@ public interface IWailaConfigHandler {
* */
//public void addConfig(String modName, String key, String name);
/* Returns the current value of an option (true/false) */
public boolean getConfig(String key);
/* Returns the current value of an option (true/false) with a default value defvalue if not set*/
public boolean getConfig(String key, boolean defvalue);
/* Returns the current value of an option (true/false) with a default value true if not set*/
public boolean getConfig(String key);
}
+2 -1
View File
@@ -20,7 +20,8 @@ public class GuiWailaConfig extends GuiBaseConfigScreen {
ContainerButtons container = new ContainerButtons(this, 5, 0, width - 10, height);
container.addButton(new ButtonConfigNEI(-1, "Hidden", "Shown", "Show/Hide Waila", "options.inworld tooltips" ));
container.addButton(new ButtonConfigOption(-1, "Pressed", "Toggled", "Toggle/Maintened", "waila.showmode" ));
container.addButton(new ButtonConfigOption(-1, "Maintened", "Toggled", "Toggle/Maintened", "waila.showmode" ));
container.addButton(new ButtonConfigOption(-1, "Hidden", "Visible", "Show ID:Metadata", "waila.showmetadata", false ));
}
@@ -23,7 +23,7 @@ public class ButtonConfigNEI extends ButtonConfigOption {
}
@Override
public void setupInitialState(String _configKey){
public void setupInitialState(String _configKey, boolean _state){
this.configKey = _configKey;
this.state = NEIClientConfig.getSetting(this.configKey).getBooleanValue();
this.displayString = state ? stateTrue:stateFalse;
@@ -10,22 +10,27 @@ public class ButtonConfigOption extends Button2States {
public ButtonConfigOption(int par1, String _stateFalse, String _stateTrue, String _label, String _configKey) {
super(par1, 0, 0, 80, 20, _stateFalse, _stateTrue, _label, -1, false);
this.setupInitialState(_configKey);
this.setupInitialState(_configKey, true);
}
public ButtonConfigOption(int par1, String _stateFalse, String _stateTrue, String _label, String _configKey, boolean _state) {
super(par1, 0, 0, 80, 20, _stateFalse, _stateTrue, _label, -1, _state);
this.setupInitialState(_configKey, _state);
}
public ButtonConfigOption(int par1, int par2, int par3, String _stateFalse, String _stateTrue, String _label, int _labelSize, boolean _state, String _configKey) {
super(par1, par2, par3, _stateFalse, _stateTrue, _label, _labelSize, _state);
this.setupInitialState(_configKey);
this.setupInitialState(_configKey, true);
}
public ButtonConfigOption(int par1, int par2, int par3, int par4, int par5, String _stateFalse, String _stateTrue, String _label, int _labelSize, boolean _state, String _configKey) {
super(par1, par2, par3, par4, par5, _stateFalse, _stateTrue, _label, _labelSize, _state);
this.setupInitialState(_configKey);
this.setupInitialState(_configKey, true);
}
public void setupInitialState(String _configKey){
public void setupInitialState(String _configKey, boolean _state){
this.configKey = _configKey;
this.state = this.readConfigKey(this.configKey);
this.state = this.readConfigKey(this.configKey, _state);
this.displayString = state ? stateTrue:stateFalse;
}
@@ -40,10 +45,10 @@ public class ButtonConfigOption extends Button2States {
mod_Waila.instance.config.save();
}
protected boolean readConfigKey(String keyname){
protected boolean readConfigKey(String keyname, boolean _state){
mod_Waila.instance.config.load();
Property prop = mod_Waila.instance.config.get(Configuration.CATEGORY_GENERAL, keyname, true);
return prop.getBoolean(true);
Property prop = mod_Waila.instance.config.get(Configuration.CATEGORY_GENERAL, keyname, _state);
return prop.getBoolean(_state);
}
}
+11 -4
View File
@@ -3,6 +3,7 @@ package mcp.mobius.waila.handlers;
import java.util.List;
import mcp.mobius.waila.mod_Waila;
import mcp.mobius.waila.addons.ConfigHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
@@ -19,10 +20,16 @@ public class HUDHandlerWaila implements IHighlightHandler {
@Override
public List<String> handleTextData(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, Layout layout) {
String modName = mod_Waila.instance.getCanonicalName(itemStack);
if (modName != null && !modName.equals(""))
currenttip.add("\u00a79\u00a7o" + modName);
return currenttip;
if (layout == Layout.FOOTER){
String modName = mod_Waila.instance.getCanonicalName(itemStack);
if (modName != null && !modName.equals(""))
currenttip.add("\u00a79\u00a7o" + modName);
} else if (layout == Layout.HEADER && ConfigHandler.instance().getConfig("waila.showmetadata", false)){
String name = currenttip.get(0);
currenttip.set(0, name + String.format(" %s:%s", world.getBlockId(mop.blockX, mop.blockY, mop.blockZ), world.getBlockMetadata(mop.blockX, mop.blockY, mop.blockZ)));
}
return currenttip;
};
}