Compare commits

...
16 Commits
73 changed files with 2627 additions and 104 deletions

No files matched your search

+1 -1
View File
@@ -80,7 +80,7 @@ apiPackage = api
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# There can be multiple files in a space-separated list.
# Example value: mymodid_at.cfg nei_at.cfg
accessTransformersFile =
accessTransformersFile = Waila_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
+22 -10
View File
@@ -11,25 +11,21 @@ import org.apache.logging.log4j.Logger;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLModContainer;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.*;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.*;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.common.versioning.ArtifactVersion;
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
import cpw.mods.fml.relauncher.Side;
import mcp.mobius.waila.addons.harvestability.MissingHarvestInfo;
import mcp.mobius.waila.addons.harvestability.proxy.ProxyIguanaTweaks;
import mcp.mobius.waila.addons.vanillamc.TestRegistrar;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.api.impl.elements.ModuleProbeRegistrar;
import mcp.mobius.waila.client.KeyEvent;
import mcp.mobius.waila.commands.CommandDumpHandlers;
import mcp.mobius.waila.network.NetworkHandler;
@@ -83,12 +79,19 @@ public class Waila {
}
FMLCommonHandler.instance().bus().register(new NetworkHandler());
MissingHarvestInfo.init();
TestRegistrar.init();
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.registerHandlers();
ModIdentification.init();
if (Loader.isModLoaded("IguanaTweaksTConstruct")) {
ProxyIguanaTweaks.init();
}
}
@Subscribe
@@ -128,6 +131,15 @@ public class Waila {
imcMessage.getStringValue()));
ModuleRegistrar.instance().addIMCRequest(imcMessage.getStringValue(), imcMessage.getSender());
}
if (imcMessage.key.equalsIgnoreCase("elementregister")) {
Waila.log.info(
String.format(
"Receiving registration request from [ %s ] for method %s",
imcMessage.getSender(),
imcMessage.getStringValue()));
ModuleProbeRegistrar.instance().addIMCRequest(imcMessage.getStringValue(), imcMessage.getSender());
}
}
}
@@ -0,0 +1,44 @@
package mcp.mobius.waila.addons;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.elements.IProbeInfo;
import mcp.mobius.waila.handlers.HUDHandlerBlocks;
import mcp.mobius.waila.utils.ModIdentification;
public class DefaultProbeInfoProvider {
public static void addStandardBlockInfo(ItemStack itemStack, IProbeInfo probeInfo, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
// TODO: item icon, horizontal layout
// if (!itemStack.isEmpty()) {
// if (Tools.show(mode, config.getShowModName())) {
// probeInfo.horizontal().item(pickBlock).vertical().itemLabel(pickBlock).text(TextStyleClass.MODNAME + modid);
// } else {
// probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)).item(pickBlock).itemLabel(pickBlock);
// }
// } else if (Tools.show(mode, config.getShowModName())) {
// probeInfo.vertical().text(TextStyleClass.NAME + getBlockUnlocalizedName(block)).text(TextStyleClass.MODNAME +
// modid);
// } else {
// probeInfo.vertical().text(TextStyleClass.NAME + getBlockUnlocalizedName(block));
// }
HUDHandlerBlocks hudHandlerBlocks = new HUDHandlerBlocks();
IProbeInfo row = probeInfo.horizontal();
row.item(itemStack);
IProbeInfo row_vertical = row.vertical();
row_vertical.text(hudHandlerBlocks.getWailaHead(itemStack, new ArrayList<>(), accessor, config).get(0));
String modName = ModIdentification.nameFromStack(itemStack);
if (modName != null && !modName.isEmpty()) {
row_vertical.text(BLUE + ITALIC + modName);
}
}
}
@@ -1,9 +1,6 @@
package mcp.mobius.waila.addons.enderio;
import static mcp.mobius.waila.api.SpecialChars.ALIGNRIGHT;
import static mcp.mobius.waila.api.SpecialChars.RESET;
import static mcp.mobius.waila.api.SpecialChars.TAB;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -1,8 +1,6 @@
package mcp.mobius.waila.addons.enderio;
import static mcp.mobius.waila.api.SpecialChars.RESET;
import static mcp.mobius.waila.api.SpecialChars.TAB;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -0,0 +1,14 @@
package mcp.mobius.waila.addons.harvestability;
public class Config {
public static final String MINIMAL_SEPARATOR_STRING = " : ";
public static final String CURRENTLY_HARVESTABLE_STRING = "\u2714";
public static final String NOT_CURRENTLY_HARVESTABLE_STRING = "\u2718";
public static final String SHEARABILITY_STRING = "\u2702";
public static final String SILK_TOUCHABILITY_STRING = "\u2712";
}
@@ -0,0 +1,338 @@
package mcp.mobius.waila.addons.harvestability;
import java.util.*;
import net.minecraft.block.Block;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.config.Configuration;
import mcp.mobius.waila.addons.harvestability.helpers.*;
import mcp.mobius.waila.addons.harvestability.proxy.ProxyCreativeBlocks;
import mcp.mobius.waila.addons.harvestability.proxy.ProxyGregTech;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.ProbeMode;
import mcp.mobius.waila.api.elements.IProbeDataProvider;
import mcp.mobius.waila.api.elements.IProbeInfo;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.api.impl.elements.ModuleProbeRegistrar;
import mcp.mobius.waila.utils.Constants;
public class HUDHandlerHarvestability implements IWailaDataProvider, IProbeDataProvider {
@Override
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
return toolTip;
}
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
if (!ConfigHandler.instance()
.getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_FORCE_LEGACY_MODE, false)) {
return toolTip;
}
Block block = accessor.getBlock();
int meta = accessor.getMetadata();
if (ProxyCreativeBlocks.isCreativeBlock(block, meta)) return toolTip;
EntityPlayer player = accessor.getPlayer();
// for disguised blocks
if (itemStack.getItem() instanceof ItemBlock && !ProxyGregTech.isOreBlock(block)
&& !ProxyGregTech.isCasing(block)
&& !ProxyGregTech.isMachine(block)) {
block = Block.getBlockFromItem(itemStack.getItem());
meta = itemStack.getItemDamage();
}
boolean minimalLayout = config.getConfig("harvestability.minimal", false);
List<String> stringParts = new ArrayList<String>();
getHarvestability(stringParts, player, block, meta, accessor.getPosition(), config, minimalLayout);
if (!stringParts.isEmpty()) {
if (minimalLayout) toolTip.add(
StringHelper.concatenateStringList(
stringParts,
EnumChatFormatting.RESET + Config.MINIMAL_SEPARATOR_STRING));
else toolTip.addAll(stringParts);
}
return toolTip;
}
public void getHarvestability(List<String> stringList, EntityPlayer player, Block block, int meta,
MovingObjectPosition position, IWailaConfigHandler config, boolean minimalLayout) {
boolean isSneaking = player.isSneaking();
boolean showHarvestLevel = config.getConfig("harvestability.harvestlevel")
&& (!config.getConfig("harvestability.harvestlevel.sneakingonly") || isSneaking);
boolean showHarvestLevelNum = config.getConfig("harvestability.harvestlevelnum")
&& (!config.getConfig("harvestability.harvestlevelnum.sneakingonly") || isSneaking);
boolean showEffectiveTool = config.getConfig("harvestability.effectivetool")
&& (!config.getConfig("harvestability.effectivetool.sneakingonly") || isSneaking);
boolean showCurrentlyHarvestable = config.getConfig("harvestability.currentlyharvestable")
&& (!config.getConfig("harvestability.currentlyharvestable.sneakingonly") || isSneaking);
boolean hideWhileHarvestable = config.getConfig("harvestability.unharvestableonly", false);
boolean showOresOnly = config.getConfig("harvestability.oresonly", false);
boolean toolRequiredOnly = config.getConfig("harvestability.toolrequiredonly");
if (showHarvestLevel || showEffectiveTool || showCurrentlyHarvestable) {
if (showOresOnly && !OreHelper.isBlockAnOre(block, meta)) {
return;
}
if (!player.isCurrentToolAdventureModeExempt(position.blockX, position.blockY, position.blockZ)
|| BlockHelper.isBlockUnbreakable(
block,
player.worldObj,
position.blockX,
position.blockY,
position.blockZ)) {
String unbreakableString = ColorHelper.getBooleanColor(false) + Config.NOT_CURRENTLY_HARVESTABLE_STRING
+ (!minimalLayout
? EnumChatFormatting.RESET
+ StatCollector.translateToLocal("wailaharvestability.harvestable")
: "");
stringList.add(unbreakableString);
return;
}
// needed to stop array index out of bounds exceptions on mob spawners
// block.getHarvestLevel/getHarvestTool are only 16 elements big
if (meta >= 16) meta = 0;
int harvestLevel = block.getHarvestLevel(meta);
String effectiveTool = BlockHelper.getEffectiveToolOf(
player.worldObj,
position.blockX,
position.blockY,
position.blockZ,
block,
meta);
if (effectiveTool != null && harvestLevel < 0) harvestLevel = 0;
boolean blockHasEffectiveTools = harvestLevel >= 0 && effectiveTool != null;
String shearability = getShearabilityString(player, block, meta, position, config);
String silkTouchability = getSilkTouchabilityString(player, block, meta, position, config);
if (toolRequiredOnly && block.getMaterial().isToolNotRequired()
&& !blockHasEffectiveTools
&& shearability.isEmpty()
&& silkTouchability.isEmpty())
return;
boolean canHarvest = false;
boolean isEffective = false;
boolean isAboveMinHarvestLevel = false;
boolean isHoldingTinkersTool = false;
boolean isHoldingGTTool = false;
ItemStack itemHeld = player.getHeldItem();
if (itemHeld != null) {
isHoldingTinkersTool = ToolHelper.hasToolTag(itemHeld);
isHoldingGTTool = ProxyGregTech.isGTTool(itemHeld);
isAboveMinHarvestLevel = (showCurrentlyHarvestable || showHarvestLevel)
&& ToolHelper.canToolHarvestLevel(itemHeld, block, meta, harvestLevel);
isEffective = showEffectiveTool
&& ToolHelper.isToolEffectiveAgainst(itemHeld, block, meta, effectiveTool);
if (isHoldingGTTool) {
// GT tool don't care net.minecraft.block.material.Material#isToolNotRequired
canHarvest = itemHeld.func_150998_b(block);
} else {
canHarvest = ToolHelper.canToolHarvestBlock(itemHeld, block, meta)
|| (!isHoldingTinkersTool && block.canHarvestBlock(player, meta));
}
}
boolean isCurrentlyHarvestable = (canHarvest && isAboveMinHarvestLevel)
|| (!isHoldingTinkersTool && ForgeHooks.canHarvestBlock(block, player, meta));
if (hideWhileHarvestable && isCurrentlyHarvestable) return;
String currentlyHarvestable = showCurrentlyHarvestable
? ColorHelper.getBooleanColor(isCurrentlyHarvestable)
+ (isCurrentlyHarvestable ? Config.CURRENTLY_HARVESTABLE_STRING
: Config.NOT_CURRENTLY_HARVESTABLE_STRING)
+ (!minimalLayout
? EnumChatFormatting.RESET
+ StatCollector.translateToLocal("wailaharvestability.currentlyharvestable")
: "")
: "";
if (!currentlyHarvestable.isEmpty() || !shearability.isEmpty() || !silkTouchability.isEmpty()) {
String separator = (!shearability.isEmpty() || !silkTouchability.isEmpty() ? " " : "");
stringList.add(
currentlyHarvestable + separator
+ silkTouchability
+ (!silkTouchability.isEmpty() ? separator : "")
+ shearability);
}
if (harvestLevel != -1 && showEffectiveTool && effectiveTool != null) {
String effectiveToolString;
if (StatCollector.canTranslate("wailaharvestability.toolclass." + effectiveTool))
effectiveToolString = StatCollector
.translateToLocal("wailaharvestability.toolclass." + effectiveTool);
else effectiveToolString = effectiveTool.substring(0, 1).toUpperCase() + effectiveTool.substring(1);
stringList.add(
(!minimalLayout ? StatCollector.translateToLocal("wailaharvestability.effectivetool") : "")
+ ColorHelper.getBooleanColor(
isEffective && (!isHoldingTinkersTool || canHarvest),
isHoldingTinkersTool && isEffective && !canHarvest)
+ effectiveToolString);
}
if (harvestLevel >= 1 && (showHarvestLevel || showHarvestLevelNum)) {
String harvestLevelString = "";
String harvestLevelName = StringHelper.stripFormatting(StringHelper.getHarvestLevelName(harvestLevel));
String harvestLevelNum = String.valueOf(harvestLevel);
// only show harvest level number and name if they are different
showHarvestLevelNum = showHarvestLevelNum
&& (!showHarvestLevel || !harvestLevelName.equals(harvestLevelNum));
if (showHarvestLevel) harvestLevelString = harvestLevelName
+ (showHarvestLevelNum ? String.format(" (%d)", harvestLevel) : "");
else if (showHarvestLevelNum) harvestLevelString = harvestLevelNum;
stringList.add(
(!minimalLayout ? StatCollector.translateToLocal("wailaharvestability.harvestlevel") : "")
+ ColorHelper.getBooleanColor(isAboveMinHarvestLevel && canHarvest)
+ harvestLevelString);
}
}
}
public String getShearabilityString(EntityPlayer player, Block block, int meta, MovingObjectPosition position,
IWailaConfigHandler config) {
boolean isSneaking = player.isSneaking();
boolean showShearability = config.getConfig("harvestability.shearability")
&& (!config.getConfig("harvestability.shearability.sneakingonly") || isSneaking);
if (showShearability && (block instanceof IShearable || block == Blocks.deadbush
|| (block == Blocks.double_plant && block.getItemDropped(meta, new Random(), 0) == null))) {
ItemStack itemHeld = player.getHeldItem();
boolean isHoldingShears = itemHeld != null && itemHeld.getItem() instanceof ItemShears;
boolean isShearable = isHoldingShears && ((IShearable) block)
.isShearable(itemHeld, player.worldObj, position.blockX, position.blockY, position.blockZ);
return ColorHelper.getBooleanColor(isShearable, !isShearable && isHoldingShears)
+ Config.SHEARABILITY_STRING;
}
return "";
}
public String getSilkTouchabilityString(EntityPlayer player, Block block, int meta, MovingObjectPosition position,
IWailaConfigHandler config) {
boolean isSneaking = player.isSneaking();
boolean showSilkTouchability = config.getConfig("harvestability.silktouchability")
&& (!config.getConfig("harvestability.silktouchability.sneakingonly") || isSneaking);
if (showSilkTouchability && block
.canSilkHarvest(player.worldObj, player, position.blockX, position.blockY, position.blockZ, meta)) {
Item itemDropped = block.getItemDropped(meta, new Random(), 0);
boolean silkTouchMatters = (itemDropped instanceof ItemBlock && itemDropped != Item.getItemFromBlock(block))
|| block.quantityDropped(new Random()) <= 0;
if (silkTouchMatters) {
boolean hasSilkTouch = EnchantmentHelper.getSilkTouchModifier(player);
return ColorHelper.getBooleanColor(hasSilkTouch) + Config.SILK_TOUCHABILITY_STRING;
}
}
return "";
}
@Override
public List<String> getWailaTail(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
return toolTip;
}
public static HashMap<String, Boolean> configOptions = new HashMap<String, Boolean>();
static {
configOptions.put("harvestability.harvestlevel", true);
configOptions.put("harvestability.harvestlevelnum", false);
configOptions.put("harvestability.effectivetool", true);
configOptions.put("harvestability.currentlyharvestable", true);
configOptions.put("harvestability.harvestlevel.sneakingonly", false);
configOptions.put("harvestability.harvestlevelnum.sneakingonly", false);
configOptions.put("harvestability.effectivetool.sneakingonly", false);
configOptions.put("harvestability.currentlyharvestable.sneakingonly", false);
configOptions.put("harvestability.oresonly", false);
configOptions.put("harvestability.minimal", false);
configOptions.put("harvestability.unharvestableonly", false);
configOptions.put("harvestability.toolrequiredonly", true);
configOptions.put("harvestability.shearability", true);
configOptions.put("harvestability.shearability.sneakingonly", false);
configOptions.put("harvestability.silktouchability", true);
configOptions.put("harvestability.silktouchability.sneakingonly", false);
}
public void addProbeInfo(ProbeMode probeMode, ItemStack itemStack, IProbeInfo probeInfo,
IWailaDataAccessor accessor, IWailaConfigHandler config) {
Block block = accessor.getBlock();
int meta = accessor.getMetadata();
if (ProxyCreativeBlocks.isCreativeBlock(block, meta)) return;
EntityPlayer player = accessor.getPlayer();
// for disguised blocks
if (itemStack.getItem() instanceof ItemBlock && !ProxyGregTech.isOreBlock(block)
&& !ProxyGregTech.isCasing(block)
&& !ProxyGregTech.isMachine(block)) {
block = Block.getBlockFromItem(itemStack.getItem());
meta = itemStack.getItemDamage();
}
List<String> stringParts = new ArrayList<String>();
getHarvestability(stringParts, player, block, meta, accessor.getPosition(), config, true);
if (!stringParts.isEmpty()) {
probeInfo.text(
StringHelper.concatenateStringList(
stringParts,
EnumChatFormatting.RESET + Config.MINIMAL_SEPARATOR_STRING));
}
}
public static void register() {
for (Map.Entry<String, Boolean> entry : configOptions.entrySet()) {
// hacky way to set default values to anything but true
ConfigHandler.instance().getConfig(entry.getKey(), entry.getValue());
ModuleRegistrar.instance().addConfig("Harvestability", entry.getKey(), "option." + entry.getKey());
}
ModuleProbeRegistrar.instance().registerProbeProvider(new HUDHandlerHarvestability(), Block.class);
ModuleRegistrar.instance().registerBodyProvider(new HUDHandlerHarvestability(), Block.class);
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x,
int y, int z) {
return tag;
}
}
@@ -0,0 +1,14 @@
package mcp.mobius.waila.addons.harvestability;
import net.minecraft.init.Blocks;
public class MissingHarvestInfo {
public static void init() {
vanilla();
}
public static void vanilla() {
Blocks.web.setHarvestLevel("sword", 0);
}
}
@@ -0,0 +1,43 @@
package mcp.mobius.waila.addons.harvestability.helpers;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.world.World;
public class BlockHelper {
private static final HashMap<String, ItemStack> testTools = new HashMap<String, ItemStack>();
static {
testTools.put("pickaxe", new ItemStack(Items.wooden_pickaxe));
testTools.put("shovel", new ItemStack(Items.wooden_shovel));
testTools.put("axe", new ItemStack(Items.wooden_axe));
}
public static String getEffectiveToolOf(World world, int x, int y, int z, Block block, int metadata) {
String effectiveTool = block.getHarvestTool(metadata);
if (effectiveTool == null) {
float hardness = block.getBlockHardness(world, x, y, z);
if (hardness > 0f) {
for (Map.Entry<String, ItemStack> testToolEntry : testTools.entrySet()) {
ItemStack testTool = testToolEntry.getValue();
if (testTool != null && testTool.getItem() instanceof ItemTool
&& testTool.func_150997_a(block) >= ((ItemTool) testTool.getItem()).func_150913_i()
.getEfficiencyOnProperMaterial()) {
effectiveTool = testToolEntry.getKey();
break;
}
}
}
}
return effectiveTool;
}
public static boolean isBlockUnbreakable(Block block, World world, int x, int y, int z) {
return block.getBlockHardness(world, x, y, z) == -1.0f;
}
}
@@ -0,0 +1,32 @@
package mcp.mobius.waila.addons.harvestability.helpers;
import net.minecraft.util.EnumChatFormatting;
public class ColorHelper {
private static final EnumChatFormatting colorRange[] = { EnumChatFormatting.DARK_RED, EnumChatFormatting.RED,
EnumChatFormatting.GOLD, EnumChatFormatting.YELLOW, EnumChatFormatting.DARK_GREEN, EnumChatFormatting.GREEN,
EnumChatFormatting.AQUA };
private static final EnumChatFormatting booleanColorRange[] = { EnumChatFormatting.DARK_RED, EnumChatFormatting.RED,
EnumChatFormatting.DARK_GREEN, EnumChatFormatting.GREEN };
public static String getRelativeColor(double val, double min, double max) {
if (min == max) return EnumChatFormatting.RESET.toString();
else if ((max > min && val > max) || (min > max && val < max))
return EnumChatFormatting.WHITE.toString() + EnumChatFormatting.BOLD;
else if ((max > min && val < min) || (min > max && val > min))
return colorRange[0].toString() + EnumChatFormatting.BOLD;
int index = (int) (((val - min) / (max - min)) * (colorRange.length - 1));
return colorRange[Math.max(0, Math.min(colorRange.length - 1, index))].toString();
}
public static String getBooleanColor(boolean val) {
return getBooleanColor(val, false);
}
public static String getBooleanColor(boolean val, boolean modified) {
return booleanColorRange[(val ? 2 : 0) + (modified ? 1 : 0)].toString();
}
}
@@ -0,0 +1,22 @@
package mcp.mobius.waila.addons.harvestability.helpers;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;
public class KeyHelper {
public static boolean isCtrlKeyDown() {
// prioritize CONTROL, but allow OPTION as well on Mac (note: GuiScreen's isCtrlKeyDown only checks for the
// OPTION key on Mac)
boolean isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
if (!isCtrlKeyDown && Minecraft.isRunningOnMac)
isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA);
return isCtrlKeyDown;
}
public static boolean isShiftKeyDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
}
}
@@ -0,0 +1,32 @@
package mcp.mobius.waila.addons.harvestability.helpers;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class OreHelper {
public static boolean isBlockAnOre(Block block) {
return isBlockAnOre(block, 0);
}
public static boolean isBlockAnOre(Block block, int metadata) {
return isItemAnOre(new ItemStack(block, 1, metadata));
}
public static boolean isItemAnOre(ItemStack itemStack) {
// check the ore dictionary to see if it starts with "ore"
int[] oreIDs = OreDictionary.getOreIDs(itemStack);
for (int oreID : oreIDs) {
if (OreDictionary.getOreName(oreID).startsWith("ore")) return true;
}
// ore in the display name (but not part of another word)
if (itemStack.getDisplayName().matches(".*(^|\\s)([oO]re)($|\\s).*")) return true;
// ore as the start of the unlocalized name
if (itemStack.getUnlocalizedName().startsWith("ore")) return true;
return false;
}
}
@@ -0,0 +1,52 @@
package mcp.mobius.waila.addons.harvestability.helpers;
import java.lang.reflect.Method;
import java.util.List;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import cpw.mods.fml.common.Loader;
import mcp.mobius.waila.addons.harvestability.proxy.ProxyIguanaTweaks;
public class StringHelper {
public static Class<?> HarvestLevels = null;
public static Method getHarvestLevelName = null;
static {
try {
HarvestLevels = Class.forName("tconstruct.library.util.HarvestLevels");
getHarvestLevelName = HarvestLevels.getDeclaredMethod("getHarvestLevelName", int.class);
} catch (Exception e) {}
}
public static String getHarvestLevelName(int num) {
if (getHarvestLevelName != null) {
try {
return (String) getHarvestLevelName.invoke(null, num);
} catch (Exception e) {}
}
if (Loader.isModLoaded("IguanaTweaksTConstruct")) return ProxyIguanaTweaks.getHarvestLevelName(num);
String unlocalized = "wailaharvestability.harvestlevel" + (num + 1);
if (StatCollector.canTranslate(unlocalized)) return StatCollector.translateToLocal(unlocalized);
return String.valueOf(num);
}
public static String concatenateStringList(List<String> strings, String separator) {
StringBuilder sb = new StringBuilder();
String sep = "";
for (String s : strings) {
sb.append(sep).append(s);
sep = separator;
}
return sb.toString();
}
public static String stripFormatting(String str) {
return EnumChatFormatting.getTextWithoutFormattingCodes(str);
}
}
@@ -0,0 +1,115 @@
package mcp.mobius.waila.addons.harvestability.helpers;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeHooks;
import cpw.mods.fml.common.Loader;
public class ToolHelper {
// tinkers construct
private static Class<?> HarvestTool = null;
private static Class<?> DualHarvestTool = null;
private static Method getHarvestType = null;
private static Method getSecondHarvestType = null;
public static boolean tinkersConstructLoaded = false;
public static void init() {
if (Loader.isModLoaded("TConstruct")) {
try {
HarvestTool = Class.forName("tconstruct.library.tools.HarvestTool");
DualHarvestTool = Class.forName("tconstruct.library.tools.DualHarvestTool");
getHarvestType = HarvestTool.getDeclaredMethod("getHarvestType");
getSecondHarvestType = DualHarvestTool.getDeclaredMethod("getSecondHarvestType");
getHarvestType.setAccessible(true);
getSecondHarvestType.setAccessible(true);
tinkersConstructLoaded = true;
} catch (Exception e) {
return;
}
}
}
public static boolean hasToolTag(ItemStack itemStack) {
return itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("InfiTool");
}
public static NBTTagCompound getToolTag(ItemStack tool) {
NBTTagCompound tag = null;
if (tool.hasTagCompound()) tag = tool.getTagCompound().getCompoundTag("InfiTool");
return tag;
}
public static int getPrimaryHarvestLevel(NBTTagCompound toolTag) {
return toolTag.getInteger("HarvestLevel");
}
public static int getSecondaryHarvestLevel(NBTTagCompound toolTag) {
return toolTag.getInteger("HarvestLevel2");
}
public static Set<String> getToolClassesOf(ItemStack tool) {
return tool.getItem().getToolClasses(tool);
}
public static boolean isToolOfClass(ItemStack tool, String toolClass) {
return getToolClassesOf(tool).contains(toolClass);
}
public static boolean toolHasAnyToolClass(ItemStack tool) {
return !getToolClassesOf(tool).isEmpty();
}
public static boolean isToolEffectiveAgainst(ItemStack tool, Block block, int metadata, String effectiveToolClass) {
if (tinkersConstructLoaded && HarvestTool.isInstance(tool.getItem())) {
Item item = tool.getItem();
List<String> harvestTypes = new ArrayList<String>();
try {
harvestTypes.add((String) getHarvestType.invoke(item));
} catch (Exception e) {
e.printStackTrace();
tinkersConstructLoaded = false;
}
if (DualHarvestTool.isInstance(item)) {
try {
harvestTypes.add((String) getSecondHarvestType.invoke(item));
} catch (Exception e) {
e.printStackTrace();
tinkersConstructLoaded = false;
}
}
return harvestTypes.contains(effectiveToolClass);
}
return ForgeHooks.isToolEffective(tool, block, metadata)
|| (toolHasAnyToolClass(tool) ? isToolOfClass(tool, effectiveToolClass)
: tool.getItem().getDigSpeed(tool, block, metadata) > 1.5f);
}
public static boolean canToolHarvestLevel(ItemStack tool, Block block, int metadata, int harvestLevel) {
boolean canTinkersToolHarvestBlock = false;
NBTTagCompound toolTag = ToolHelper.getToolTag(tool);
if (toolTag != null) {
int toolHarvestLevel = Math
.max(ToolHelper.getPrimaryHarvestLevel(toolTag), ToolHelper.getSecondaryHarvestLevel(toolTag));
canTinkersToolHarvestBlock = toolHarvestLevel >= harvestLevel;
}
return canTinkersToolHarvestBlock || ForgeHooks.canToolHarvestBlock(block, metadata, tool);
}
public static boolean canToolHarvestBlock(ItemStack tool, Block block, int metadata) {
return block.getMaterial().isToolNotRequired() || tool.func_150998_b(block); // func_150998_b = canHarvestBlock
}
}
@@ -0,0 +1,33 @@
package mcp.mobius.waila.addons.harvestability.proxy;
import java.lang.reflect.Method;
import net.minecraft.block.Block;
import cpw.mods.fml.common.Loader;
public class ProxyCreativeBlocks {
private static Class<?> CreativeBlocks = null;
private static Method isCreativeBlock = null;
static {
if (Loader.isModLoaded("CreativeBlocks")) {
try {
CreativeBlocks = Class.forName("squeek.creativeblocks.CreativeBlocks");
isCreativeBlock = CreativeBlocks.getDeclaredMethod("isCreativeBlock", Block.class, int.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static boolean isCreativeBlock(Block block, int meta) {
if (isCreativeBlock != null) {
try {
return (Boolean) isCreativeBlock.invoke(null, block, meta);
} catch (Exception e) {}
}
return false;
}
}
@@ -0,0 +1,35 @@
package mcp.mobius.waila.addons.harvestability.proxy;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameRegistry;
public class ProxyGregTech {
public static final String modID = "gregtech";
public static final String oreBlockID = "gt.blockores";
public static final String oreBlockUniqueIdentifier = modID + ":" + oreBlockID;
public static final String casingID = "gt.blockcasings";
public static final String casingUniqueIdentifier = modID + ":" + casingID;
public static final String machineID = "gt.blockmachines";
public static final String machineUniqueIdentifier = modID + ":" + machineID;
public static boolean isModLoaded = Loader.isModLoaded(modID);
public static boolean isOreBlock(Block block) {
return isModLoaded && GameRegistry.findUniqueIdentifierFor(block).toString().equals(oreBlockUniqueIdentifier);
}
public static boolean isCasing(Block block) {
return isModLoaded && GameRegistry.findUniqueIdentifierFor(block).toString().equals(casingUniqueIdentifier);
}
public static boolean isMachine(Block block) {
return isModLoaded && GameRegistry.findUniqueIdentifierFor(block).toString().equals(machineUniqueIdentifier);
}
public static boolean isGTTool(ItemStack itemStack) {
return isModLoaded && itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("GT.ToolStats");
}
}
@@ -0,0 +1,30 @@
package mcp.mobius.waila.addons.harvestability.proxy;
import java.lang.reflect.Method;
public class ProxyIguanaTweaks {
private static Class<?> HarvestLevels = null;
private static Method proxyGetHarvestLevelName;
public static void init() {
try {
HarvestLevels = Class.forName("iguanaman.iguanatweakstconstruct.util.HarvestLevels");
proxyGetHarvestLevelName = HarvestLevels.getDeclaredMethod("getHarvestLevelName", int.class);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getHarvestLevelName(int num) {
String harvestLevelName = "<Unknown>";
try {
harvestLevelName = (String) proxyGetHarvestLevelName.invoke(null, num);
} catch (Exception e) {
e.printStackTrace();
}
return harvestLevelName;
}
}
@@ -1,9 +1,6 @@
package mcp.mobius.waila.addons.projectred;
import static mcp.mobius.waila.api.SpecialChars.ALIGNRIGHT;
import static mcp.mobius.waila.api.SpecialChars.GRAY;
import static mcp.mobius.waila.api.SpecialChars.TAB;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -1,8 +1,6 @@
package mcp.mobius.waila.addons.statues;
import static mcp.mobius.waila.api.SpecialChars.BLUE;
import static mcp.mobius.waila.api.SpecialChars.ITALIC;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -1,10 +1,6 @@
package mcp.mobius.waila.addons.stevescarts;
import static mcp.mobius.waila.api.SpecialChars.ALIGNRIGHT;
import static mcp.mobius.waila.api.SpecialChars.GRAY;
import static mcp.mobius.waila.api.SpecialChars.ITALIC;
import static mcp.mobius.waila.api.SpecialChars.TAB;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.ArrayList;
import java.util.List;
@@ -1,10 +1,6 @@
package mcp.mobius.waila.addons.stevescarts;
import static mcp.mobius.waila.api.SpecialChars.ALIGNRIGHT;
import static mcp.mobius.waila.api.SpecialChars.GRAY;
import static mcp.mobius.waila.api.SpecialChars.ITALIC;
import static mcp.mobius.waila.api.SpecialChars.TAB;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -1,10 +1,6 @@
package mcp.mobius.waila.addons.stevescarts;
import static mcp.mobius.waila.api.SpecialChars.ALIGNRIGHT;
import static mcp.mobius.waila.api.SpecialChars.GRAY;
import static mcp.mobius.waila.api.SpecialChars.ITALIC;
import static mcp.mobius.waila.api.SpecialChars.TAB;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -1,8 +1,6 @@
package mcp.mobius.waila.addons.thaumcraft;
import static mcp.mobius.waila.api.SpecialChars.ALIGNRIGHT;
import static mcp.mobius.waila.api.SpecialChars.TAB;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
@@ -0,0 +1,83 @@
package mcp.mobius.waila.addons.vanillamc;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.NumberFormat;
import mcp.mobius.waila.api.ProbeMode;
import mcp.mobius.waila.api.elements.IProbeDataProvider;
import mcp.mobius.waila.api.elements.IProbeInfo;
import mcp.mobius.waila.api.elements.ITextStyle;
import mcp.mobius.waila.overlay.DisplayUtil;
/**
* Example class for testing various elements
*/
public class HUDElementHandlerFurnace implements IProbeDataProvider {
@Override
public void addProbeInfo(ProbeMode probeMode, ItemStack itemStack, IProbeInfo probeInfo, IWailaDataAccessor data,
IWailaConfigHandler config) {
int cookTime = data.getNBTData().getShort("CookTime");
if (cookTime != 0) {
cookTime = Math.round(cookTime / 20.0f);
probeInfo.vertical().progress(
cookTime,
10,
probeInfo.defaultProgressStyle().text("Smelting: " + cookTime + " / 10 s").filledColor(0xFF4CBB17)
.alternateFilledColor(0xFF4CBB17).borderColor(0xFF555555)
.numberFormat(NumberFormat.COMMAS));
}
if (probeMode != ProbeMode.EXTENDED) {
return;
}
int burnTime = data.getNBTData().getInteger("BurnTime") / 20;
if (burnTime > 0) {
probeInfo.horizontal().text("Burn")
.item(new ItemStack(Blocks.fire), probeInfo.defaultItemStyle().width(8).height(8))
.text(": " + burnTime + " " + "Seconds Remaining");
}
ItemStack[] items = new ItemStack[3];
NBTTagList itemsTag = data.getNBTData().getTagList("Items", 10);
for (int i = 0; i < itemsTag.tagCount(); i++) {
NBTTagCompound itemTag = itemsTag.getCompoundTagAt(i);
byte slot = itemTag.getByte("Slot");
if (slot >= 0 && slot < items.length) {
items[slot] = ItemStack.loadItemStackFromNBT(itemTag);
}
}
ITextStyle itemPaddedStyle = probeInfo.defaultTextStyle().vPadding(2);
IProbeInfo itemSection = probeInfo.vertical(probeInfo.defaultLayoutStyle().borderColor(0xff00ffff));
if (items[0] != null) {
itemSection.horizontal().text("In: ", itemPaddedStyle)
.item(items[0], probeInfo.defaultItemStyle().width(10).height(10)).text(
" " + DisplayUtil.itemDisplayNameShort(items[0]) + " x" + items[0].stackSize,
itemPaddedStyle);
}
if (items[2] != null) {
itemSection.horizontal().text("Out: ", itemPaddedStyle)
.item(items[2], probeInfo.defaultItemStyle().width(10).height(10)).text(
" " + DisplayUtil.itemDisplayNameShort(items[2]) + " x" + items[2].stackSize,
itemPaddedStyle);
}
if (items[1] != null) {
itemSection.horizontal().text("Fuel: ", itemPaddedStyle)
.item(items[1], probeInfo.defaultItemStyle().width(10).height(10)).text(
" " + DisplayUtil.itemDisplayNameShort(items[1]) + " x" + items[1].stackSize,
itemPaddedStyle);
}
}
}
@@ -0,0 +1,18 @@
package mcp.mobius.waila.addons.vanillamc;
import net.minecraft.block.BlockFurnace;
import cpw.mods.fml.common.event.FMLInterModComms;
import mcp.mobius.waila.api.elements.IProbeRegistrar;
// example class for registering IMC
public class TestRegistrar {
public static void callbackRegister(IProbeRegistrar register) {
register.registerProbeProvider(new HUDElementHandlerFurnace(), BlockFurnace.class);
}
public static void init() {
FMLInterModComms.sendMessage("Waila", "elementregister", TestRegistrar.class.getName() + ".callbackRegister");
}
}
@@ -49,4 +49,6 @@ public interface IWailaDataAccessor {
ForgeDirection getSide();
ItemStack getStack();
float getBlockBreakDamage();
}
@@ -1,6 +1,6 @@
package mcp.mobius.waila.api;
import java.awt.Dimension;
import java.awt.*;
public interface IWailaTooltipRenderer {
@@ -0,0 +1,11 @@
package mcp.mobius.waila.api;
public enum NumberFormat {
FULL,
COMPACT,
COMMAS,
NONE;
private NumberFormat() {}
}
@@ -0,0 +1,7 @@
package mcp.mobius.waila.api;
public enum ProbeMode {
NORMAL, // Normal display. What a user expects to see
EXTENDED, // Extended. This is used when the player is sneaking
DEBUG // Creative only. This is used when the player holds a creative probe
}
@@ -0,0 +1,7 @@
package mcp.mobius.waila.api.elements;
public enum ElementAlignment {
ALIGN_TOPLEFT,
ALIGN_CENTER,
ALIGN_BOTTOMRIGHT
}
@@ -0,0 +1,10 @@
package mcp.mobius.waila.api.elements;
public interface IElement {
void render(int var1, int var2);
int getWidth();
int getHeight();
}
@@ -0,0 +1,12 @@
package mcp.mobius.waila.api.elements;
public interface IItemStyle {
IItemStyle width(int var1);
IItemStyle height(int var1);
int getWidth();
int getHeight();
}
@@ -0,0 +1,16 @@
package mcp.mobius.waila.api.elements;
public interface ILayoutStyle {
ILayoutStyle borderColor(Integer var1);
ILayoutStyle spacing(int var1);
ILayoutStyle alignment(ElementAlignment var1);
Integer getBorderColor();
int getSpacing();
ElementAlignment getAlignment();
}
@@ -0,0 +1,23 @@
package mcp.mobius.waila.api.elements;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.ProbeMode;
public interface IProbeDataProvider {
default void addProbeInfo(ProbeMode probeMode, ItemStack itemStack, IProbeInfo probeInfo,
IWailaDataAccessor accessor, IWailaConfigHandler config) {}
default NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x,
int y, int z) {
if (te != null) te.writeToNBT(tag);
return tag;
}
}
@@ -0,0 +1,50 @@
package mcp.mobius.waila.api.elements;
import net.minecraft.item.ItemStack;
public interface IProbeInfo {
/**
* Create a default layout style for the horizontal or vertical elements
*/
ILayoutStyle defaultLayoutStyle();
/**
* Create a default style for the progress bar
*/
IProgressStyle defaultProgressStyle();
/**
* Create a default style for the text element
*/
ITextStyle defaultTextStyle();
/**
* Create a default style for the item element
*/
IItemStyle defaultItemStyle();
IProbeInfo text(String text, ITextStyle style);
IProbeInfo text(String text);
IProbeInfo vertical(ILayoutStyle style);
IProbeInfo vertical();
IProbeInfo horizontal(ILayoutStyle style);
IProbeInfo horizontal();
IProbeInfo item(ItemStack stack, IItemStyle style);
IProbeInfo item(ItemStack stack);
IProbeInfo progress(int var1, int var2, IProgressStyle var3);
IProbeInfo progress(int var1, int var2);
IProbeInfo progress(long var1, long var3, IProgressStyle var5);
IProbeInfo progress(long var1, long var3);
}
@@ -0,0 +1,6 @@
package mcp.mobius.waila.api.elements;
public interface IProbeRegistrar {
void registerProbeProvider(IProbeDataProvider dataProvider, Class<?> block);
}
@@ -0,0 +1,65 @@
package mcp.mobius.waila.api.elements;
import mcp.mobius.waila.api.NumberFormat;
public interface IProgressStyle {
/// The color that is used for the border of the progress bar
IProgressStyle borderColor(int c);
/// The color that is used for the background of the progress bar
IProgressStyle backgroundColor(int c);
/// The color that is used for the filled part of the progress bar
IProgressStyle filledColor(int c);
/// If this is different from the filledColor then the fill color will alternate
IProgressStyle alternateFilledColor(int c);
/// If true then text is shown inside the progress bar
IProgressStyle showText(boolean b);
/// The number format to use for the text inside the progress bar
IProgressStyle numberFormat(NumberFormat f);
IProgressStyle text(String text);
IProgressStyle textColor(int color);
IProgressStyle textShadow(boolean b);
/// If the progressbar is a lifebar then this is the maximum width
IProgressStyle width(int w);
IProgressStyle height(int h);
IProgressStyle lifeBar(boolean b);
IProgressStyle armorBar(boolean b);
int getBorderColor();
int getBackgroundColor();
int getFilledColor();
int getAlternatefilledColor();
boolean isShowText();
NumberFormat getNumberFormat();
String getText();
int getTextColor();
boolean isTextShadow();
int getWidth();
int getHeight();
boolean isLifeBar();
boolean isArmorBar();
}
@@ -0,0 +1,61 @@
package mcp.mobius.waila.api.elements;
import mcp.mobius.waila.api.impl.elements.TextStyle;
public interface ITextStyle {
/// Allows copying the state for easier template creation
ITextStyle copy();
default ITextStyle padding(int padding) {
return topPadding(padding).bottomPadding(padding).leftPadding(padding).rightPadding(padding);
}
default ITextStyle vPadding(int padding) {
return topPadding(padding).bottomPadding(padding);
}
default ITextStyle hPadding(int padding) {
return leftPadding(padding).rightPadding(padding);
}
ITextStyle topPadding(int padding);
ITextStyle bottomPadding(int padding);
ITextStyle leftPadding(int padding);
ITextStyle rightPadding(int padding);
default ITextStyle bounds(Integer width, Integer height) {
return width(width).height(height);
}
ITextStyle width(Integer width);
ITextStyle height(Integer height);
ITextStyle alignment(ElementAlignment align);
TextStyle color(int color);
TextStyle shadow(boolean shadow);
int getLeftPadding();
int getRightPadding();
int getTopPadding();
int getBottomPadding();
Integer getWidth();
Integer getHeight();
ElementAlignment getAlignment();
int getColor();
boolean getShadow();
}
@@ -145,6 +145,7 @@ public class ConfigHandler implements IWailaConfigHandler {
config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_METADATA, false);
config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_KEYBIND, true);
config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_NEWFILTERS, true);
config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_FORCE_LEGACY_MODE, false);
OverlayConfig.posX = config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_POSX, 5000).getInt();
OverlayConfig.posY = config.get(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_POSY, 100).getInt();
@@ -1,6 +1,7 @@
package mcp.mobius.waila.api.impl;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -21,6 +22,8 @@ import mcp.mobius.waila.utils.NBTUtil;
public class DataAccessorCommon implements IWailaCommonAccessor, IWailaDataAccessor, IWailaEntityAccessor {
private static final Minecraft mc = Minecraft.getMinecraft();
public World world;
public EntityPlayer player;
public MovingObjectPosition mop;
@@ -37,6 +40,7 @@ public class DataAccessorCommon implements IWailaCommonAccessor, IWailaDataAcces
public ItemStack stack;
public static DataAccessorCommon instance = new DataAccessorCommon();
public float blockBreakDamage;
public void set(World _world, EntityPlayer _player, MovingObjectPosition _mop) {
this.set(_world, _player, _mop, null, 0.0);
@@ -55,6 +59,7 @@ public class DataAccessorCommon implements IWailaCommonAccessor, IWailaDataAcces
this.entity = null;
this.blockID = Block.getIdFromBlock(this.block);
this.blockResource = GameData.getBlockRegistry().getNameForObject(this.block);
this.blockBreakDamage = mc.playerController.curBlockDamageMP;
try {
this.stack = new ItemStack(this.block, 1, this.metadata);
} catch (Exception ignored) {}
@@ -200,6 +205,11 @@ public class DataAccessorCommon implements IWailaCommonAccessor, IWailaDataAcces
return this.stack;
}
@Override
public float getBlockBreakDamage() {
return this.blockBreakDamage;
}
public boolean isTimeElapsed(long time) {
return System.currentTimeMillis() - this.timeLastUpdate >= time;
}
@@ -12,6 +12,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.config.Configuration;
import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.IWailaBlock;
@@ -21,6 +22,7 @@ import mcp.mobius.waila.cbcore.Layout;
import mcp.mobius.waila.network.Message0x01TERequest;
import mcp.mobius.waila.network.Message0x03EntRequest;
import mcp.mobius.waila.network.WailaPacketHandler;
import mcp.mobius.waila.utils.Constants;
import mcp.mobius.waila.utils.WailaExceptionHandler;
public class MetaDataProvider {
@@ -66,7 +68,9 @@ public class MetaDataProvider {
if (accessor.getTileEntity() != null && Waila.instance.serverPresent
&& accessor.isTimeElapsed(250)
&& ConfigHandler.instance().showTooltip()) {
&& ConfigHandler.instance().showTooltip()
&& ConfigHandler.instance()
.getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_FORCE_LEGACY_MODE, false)) {
accessor.resetTimer();
HashSet<String> keys = new HashSet<>();
@@ -78,7 +82,8 @@ public class MetaDataProvider {
if (!keys.isEmpty() || ModuleRegistrar.instance().hasNBTProviders(block)
|| ModuleRegistrar.instance().hasNBTProviders(accessor.getTileEntity()))
WailaPacketHandler.INSTANCE.sendToServer(new Message0x01TERequest(accessor.getTileEntity(), keys));
WailaPacketHandler.INSTANCE
.sendToServer(new Message0x01TERequest(accessor.getTileEntity(), keys, false));
} else if (accessor.getTileEntity() != null && !Waila.instance.serverPresent
&& accessor.isTimeElapsed(250)
@@ -4,24 +4,11 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.*;
import au.com.bytecode.opencsv.CSVReader;
import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.IWailaBlockDecorator;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.IWailaEntityProvider;
import mcp.mobius.waila.api.IWailaFMPDecorator;
import mcp.mobius.waila.api.IWailaFMPProvider;
import mcp.mobius.waila.api.IWailaRegistrar;
import mcp.mobius.waila.api.IWailaSummaryProvider;
import mcp.mobius.waila.api.IWailaTooltipRenderer;
import mcp.mobius.waila.api.*;
import mcp.mobius.waila.cbcore.LangUtil;
import mcp.mobius.waila.utils.Constants;
@@ -1,12 +1,7 @@
package mcp.mobius.waila.api.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import mcp.mobius.waila.api.ITaggedList;
@@ -0,0 +1,126 @@
package mcp.mobius.waila.api.impl.elements;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.Gui;
import net.minecraft.item.ItemStack;
import mcp.mobius.waila.api.elements.*;
public abstract class AbstractElementPanel implements IElement, IProbeInfo {
protected List<IElement> children = new ArrayList();
protected Integer borderColor;
protected int spacing;
protected ElementAlignment alignment;
public void render(int x, int y) {
if (this.borderColor != null) {
int w = this.getWidth();
int h = this.getHeight();
drawHorizontalLine(x, y, x + w - 1, this.borderColor);
drawHorizontalLine(x, y + h - 1, x + w - 1, this.borderColor);
drawVerticalLine(x, y, y + h - 1, this.borderColor);
drawVerticalLine(x + w - 1, y, y + h, this.borderColor);
}
}
public AbstractElementPanel(Integer borderColor, int spacing, ElementAlignment alignment) {
this.borderColor = borderColor;
this.spacing = spacing;
this.alignment = alignment;
}
public IProbeInfo text(String text, ITextStyle style) {
this.children.add(new ElementText(text, style));
return this;
}
public IProbeInfo text(String text) {
this.children.add(new ElementText(text));
return this;
}
public IProbeInfo vertical(ILayoutStyle style) {
ElementVertical e = new ElementVertical(style.getBorderColor(), style.getSpacing(), style.getAlignment());
this.children.add(e);
return e;
}
public IProbeInfo vertical() {
ElementVertical e = new ElementVertical(null, 2, ElementAlignment.ALIGN_TOPLEFT);
this.children.add(e);
return e;
}
public IProbeInfo horizontal(ILayoutStyle style) {
ElementHorizontal e = new ElementHorizontal(style.getBorderColor(), style.getSpacing(), style.getAlignment());
this.children.add(e);
return e;
}
public IProbeInfo horizontal() {
ElementHorizontal e = new ElementHorizontal((Integer) null, this.spacing, ElementAlignment.ALIGN_TOPLEFT);
this.children.add(e);
return e;
}
public IProbeInfo item(ItemStack stack, IItemStyle style) {
this.children.add(new ElementItemStack(stack, style));
return this;
}
public IProbeInfo item(ItemStack stack) {
return this.item(stack, new ItemStyle());
}
public IProbeInfo progress(int current, int max) {
return this.progress(current, max, new ProgressStyle());
}
public IProbeInfo progress(int current, int max, IProgressStyle style) {
this.children.add(new ElementProgress((long) current, (long) max, style));
return this;
}
public IProbeInfo progress(long current, long max) {
return this.progress(current, max, new ProgressStyle());
}
public IProbeInfo progress(long current, long max, IProgressStyle style) {
this.children.add(new ElementProgress(current, max, style));
return this;
}
// tmp
public static void drawHorizontalLine(int x1, int y1, int x2, int color) {
Gui.drawRect(x1, y1, x2, y1 + 1, color);
}
// tmp
public static void drawVerticalLine(int x1, int y1, int y2, int color) {
Gui.drawRect(x1, y1, x1 + 1, y2, color);
}
@Override
public ILayoutStyle defaultLayoutStyle() {
return new LayoutStyle();
}
@Override
public IProgressStyle defaultProgressStyle() {
return new ProgressStyle();
}
@Override
public ITextStyle defaultTextStyle() {
return new TextStyle();
}
@Override
public IItemStyle defaultItemStyle() {
return new ItemStyle();
}
}
@@ -0,0 +1,64 @@
package mcp.mobius.waila.api.impl.elements;
import mcp.mobius.waila.api.elements.ElementAlignment;
import mcp.mobius.waila.api.elements.IElement;
public class ElementHorizontal extends AbstractElementPanel {
public static final int SPACING = 5;
public ElementHorizontal(Integer borderColor, int spacing, ElementAlignment alignment) {
super(borderColor, spacing, alignment);
}
@Override
public void render(int x, int y) {
super.render(x, y);
if (borderColor != null) {
x += 3;
y += 3;
}
int totHeight = getHeight();
for (IElement element : children) {
int h = element.getHeight();
int cy = y;
switch (alignment) {
case ALIGN_TOPLEFT:
break;
case ALIGN_CENTER:
cy = y + (totHeight - h) / 2;
break;
case ALIGN_BOTTOMRIGHT:
cy = y + totHeight - h;
break;
}
element.render(x, cy);
x += element.getWidth() + spacing;
}
}
private int getBorderSpacing() {
return borderColor == null ? 0 : 6;
}
@Override
public int getWidth() {
int w = 0;
for (IElement element : children) {
w += element.getWidth();
}
return w + spacing * (children.size() - 1) + getBorderSpacing();
}
@Override
public int getHeight() {
int h = 0;
for (IElement element : children) {
int hh = element.getHeight();
if (hh > h) {
h = hh;
}
}
return h + getBorderSpacing();
}
}
@@ -0,0 +1,37 @@
package mcp.mobius.waila.api.impl.elements;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import mcp.mobius.waila.api.elements.IElement;
import mcp.mobius.waila.api.elements.IItemStyle;
import mcp.mobius.waila.overlay.DisplayUtil;
public class ElementItemStack implements IElement {
private final ItemStack itemStack;
private final IItemStyle style;
public ElementItemStack(ItemStack itemStack, IItemStyle style) {
this.itemStack = itemStack;
this.style = style;
}
@Override
public void render(int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
DisplayUtil.elementRenderStack(x, y, itemStack, style);
}
@Override
public int getWidth() {
return style.getWidth();
}
@Override
public int getHeight() {
return style.getHeight();
}
}
@@ -0,0 +1,117 @@
package mcp.mobius.waila.api.impl.elements;
import java.text.DecimalFormat;
import mcp.mobius.waila.api.NumberFormat;
import mcp.mobius.waila.api.elements.IElement;
import mcp.mobius.waila.api.elements.IProgressStyle;
import mcp.mobius.waila.overlay.DisplayUtil;
public class ElementProgress implements IElement {
private final long current;
private final long max;
private final IProgressStyle style;
public ElementProgress(long current, long max, IProgressStyle style) {
this.current = current;
this.max = max;
this.style = style;
}
private static DecimalFormat dfCommas = new DecimalFormat("###,###");
/**
* If the suffix starts with 'm' we can possibly drop that
*/
public static String format(long in, NumberFormat style, String suffix) {
switch (style) {
case FULL:
return Long.toString(in) + suffix;
case COMPACT: {
int unit = 1000;
if (in < unit) {
return Long.toString(in) + " " + suffix;
}
int exp = (int) (Math.log(in) / Math.log(unit));
char pre;
if (suffix.startsWith("m")) {
suffix = suffix.substring(1);
if (exp - 2 >= 0) {
pre = "kMGTPE".charAt(exp - 2);
return String.format("%.1f %s", in / Math.pow(unit, exp), pre) + suffix;
} else {
return String.format("%.1f %s", in / Math.pow(unit, exp), suffix);
}
} else {
pre = "kMGTPE".charAt(exp - 1);
return String.format("%.1f %s", in / Math.pow(unit, exp), pre) + suffix;
}
}
case COMMAS:
return dfCommas.format(in) + suffix;
case NONE:
return suffix;
}
return Long.toString(in);
}
@Override
public void render(int x, int y) {
render(style, current, max, x, y, getWidth(), getHeight());
}
private static void render(IProgressStyle style, long current, long max, int x, int y, int w, int h) {
DisplayUtil.drawThickBeveledBox(
x,
y,
x + w,
y + h,
1,
style.getBorderColor(),
style.getBorderColor(),
style.getBackgroundColor());
if (current > 0L && max > 0L) {
int dx = (int) Math.min(current * (long) (w - 2) / max, (long) (w - 2));
if (style.getFilledColor() == style.getAlternatefilledColor()) {
if (dx > 0) {
DisplayUtil.drawThickBeveledBox(
x + 1,
y + 1,
x + dx + 1,
y + h - 1,
1,
style.getFilledColor(),
style.getFilledColor(),
style.getFilledColor());
}
} else {
for (int xx = x + 1; xx <= x + dx + 1; ++xx) {
int color = (xx & 1) == 0 ? style.getFilledColor() : style.getAlternatefilledColor();
DisplayUtil.drawVerticalLine(xx, y + 1, y + h - 1, color);
}
}
}
if (style.isShowText()) {
DisplayUtil.drawString(style.getText(), x + 3, y + 2, style.getTextColor(), style.isTextShadow());
}
}
@Override
public int getWidth() {
if (style.isLifeBar()) {
if (current * 4 >= style.getWidth()) {
return 100;
} else {
return (int) (current * 4 + 2);
}
}
return style.getWidth();
}
@Override
public int getHeight() {
return style.getHeight();
}
}
@@ -0,0 +1,68 @@
package mcp.mobius.waila.api.impl.elements;
import net.minecraft.client.Minecraft;
import mcp.mobius.waila.api.elements.IElement;
import mcp.mobius.waila.api.elements.ITextStyle;
import mcp.mobius.waila.overlay.DisplayUtil;
public class ElementText implements IElement {
private final String text;
private final ITextStyle style;
private static final int DEFAULT_HEIGHT = 10;
public ElementText(String text) {
this(text, new TextStyle());
}
public ElementText(String text, ITextStyle style) {
this.text = text;
this.style = style;
}
public void render(int x, int y) {
int width = getTextWidth();
switch (style.getAlignment()) {
case ALIGN_BOTTOMRIGHT -> DisplayUtil.drawString(
text,
(x + getInternalWidth() - width) + style.getLeftPadding(),
y + style.getTopPadding(),
style.getColor(),
style.getShadow());
case ALIGN_CENTER -> DisplayUtil.drawString(
text,
((x + (getInternalWidth() / 2)) - (width / 2)) + style.getLeftPadding(),
y + style.getTopPadding(),
style.getColor(),
style.getShadow());
case ALIGN_TOPLEFT -> DisplayUtil.drawString(
text,
x + style.getLeftPadding(),
y + style.getTopPadding(),
style.getColor(),
style.getShadow());
}
}
public int getTextWidth() {
return Minecraft.getMinecraft().fontRenderer.getStringWidth(text);
}
protected int getInternalWidth() {
return (style.getWidth() != null ? style.getWidth() : getTextWidth());
}
@Override
public int getWidth() {
return style.getLeftPadding() + (style.getWidth() != null ? style.getWidth() : getTextWidth())
+ style.getRightPadding();
}
@Override
public int getHeight() {
return style.getTopPadding() + (style.getHeight() != null ? style.getHeight() : DEFAULT_HEIGHT)
+ style.getBottomPadding();
}
}
@@ -0,0 +1,73 @@
package mcp.mobius.waila.api.impl.elements;
import java.util.Iterator;
import mcp.mobius.waila.api.elements.ElementAlignment;
import mcp.mobius.waila.api.elements.IElement;
public class ElementVertical extends AbstractElementPanel {
public ElementVertical(Integer borderColor, int spacing, ElementAlignment alignment) {
super(borderColor, spacing, alignment);
}
public void render(int x, int y) {
super.render(x, y);
if (this.borderColor != null) {
x += 3;
y += 3;
}
int totWidth = this.getWidth();
IElement element;
for (Iterator var4 = this.children.iterator(); var4.hasNext(); y += element.getHeight() + this.spacing) {
element = (IElement) var4.next();
int w = element.getWidth();
int cx = x;
switch (this.alignment) {
case ALIGN_TOPLEFT:
default:
break;
case ALIGN_CENTER:
cx = x + (totWidth - w) / 2;
break;
case ALIGN_BOTTOMRIGHT:
cx = x + totWidth - w;
}
element.render(cx, y);
}
}
private int getBorderSpacing() {
return this.borderColor == null ? 0 : 6;
}
public int getHeight() {
int h = 0;
IElement element;
for (Iterator var2 = this.children.iterator(); var2.hasNext(); h += element.getHeight()) {
element = (IElement) var2.next();
}
return h + this.spacing * (this.children.size() - 1) + this.getBorderSpacing();
}
public int getWidth() {
int w = 0;
Iterator var2 = this.children.iterator();
while (var2.hasNext()) {
IElement element = (IElement) var2.next();
int ww = element.getWidth();
if (ww > w) {
w = ww;
}
}
return w + this.getBorderSpacing();
}
}
@@ -0,0 +1,34 @@
package mcp.mobius.waila.api.impl.elements;
import mcp.mobius.waila.api.elements.IItemStyle;
public class ItemStyle implements IItemStyle {
private int width = 20;
private int height = 20;
public ItemStyle(int w, int h) {
width = w;
height = h;
}
public ItemStyle() {}
public IItemStyle width(int w) {
this.width = w;
return this;
}
public IItemStyle height(int h) {
this.height = h;
return this;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
}
@@ -0,0 +1,43 @@
package mcp.mobius.waila.api.impl.elements;
import mcp.mobius.waila.api.elements.ElementAlignment;
import mcp.mobius.waila.api.elements.ILayoutStyle;
public class LayoutStyle implements ILayoutStyle {
private Integer borderColor = null;
private ElementAlignment alignment;
private int spacing;
public LayoutStyle() {
this.alignment = ElementAlignment.ALIGN_TOPLEFT;
this.spacing = -1;
}
public ILayoutStyle alignment(ElementAlignment alignment) {
this.alignment = alignment;
return this;
}
public ElementAlignment getAlignment() {
return this.alignment;
}
public LayoutStyle borderColor(Integer c) {
this.borderColor = c;
return this;
}
public LayoutStyle spacing(int f) {
this.spacing = f;
return this;
}
public Integer getBorderColor() {
return this.borderColor;
}
public int getSpacing() {
return this.spacing;
}
}
@@ -0,0 +1,99 @@
package mcp.mobius.waila.api.impl.elements;
import java.util.HashSet;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.config.Configuration;
import mcp.mobius.waila.Waila;
import mcp.mobius.waila.addons.DefaultProbeInfoProvider;
import mcp.mobius.waila.api.ProbeMode;
import mcp.mobius.waila.api.elements.IProbeDataProvider;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.DataAccessorCommon;
import mcp.mobius.waila.network.Message0x01TERequest;
import mcp.mobius.waila.network.WailaPacketHandler;
import mcp.mobius.waila.utils.Constants;
import mcp.mobius.waila.utils.WailaExceptionHandler;
public class MetaProbeDataProvider {
public ProbeInfo handleBlockElementData(ItemStack itemStack, World world, EntityPlayer player,
MovingObjectPosition mop, DataAccessorCommon accessor) {
Block block = accessor.getBlock();
ProbeInfo probeInfo = new ProbeInfo();
DefaultProbeInfoProvider.addStandardBlockInfo(itemStack, probeInfo, accessor, ConfigHandler.instance());
if (!ModuleProbeRegistrar.instance().hasProviders(block)
&& !ModuleProbeRegistrar.instance().hasProviders(accessor.getTileEntity())) {
return probeInfo;
}
ProbeMode probeMode = player.isSneaking() ? ProbeMode.EXTENDED
: player.capabilities.isCreativeMode ? ProbeMode.DEBUG : ProbeMode.NORMAL;
if (accessor.getTileEntity() != null && Waila.instance.serverPresent
&& accessor.isTimeElapsed(250)
&& ConfigHandler.instance().showTooltip()
&& !ConfigHandler.instance()
.getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_FORCE_LEGACY_MODE, false)) {
accessor.resetTimer();
HashSet<String> keys = new HashSet<>();
if (ModuleProbeRegistrar.instance().hasProviders(block)
|| ModuleProbeRegistrar.instance().hasProviders(accessor.getTileEntity()))
WailaPacketHandler.INSTANCE
.sendToServer(new Message0x01TERequest(accessor.getTileEntity(), keys, true));
} else if (accessor.getTileEntity() != null && !Waila.instance.serverPresent
&& accessor.isTimeElapsed(250)
&& ConfigHandler.instance().showTooltip()) {
try {
NBTTagCompound tag = new NBTTagCompound();
accessor.getTileEntity().writeToNBT(tag);
accessor.setNBTData(tag);
} catch (Exception e) {
WailaExceptionHandler.handleErr(e, this.getClass().getName(), null);
}
}
/* Lookup by class (for blocks) */
if (ModuleProbeRegistrar.instance().hasProviders(block)) {
List<IProbeDataProvider> probeDataProviders = ModuleProbeRegistrar.instance().getProviders(block);
for (IProbeDataProvider probeDataProvider : probeDataProviders) {
probeDataProvider.addProbeInfo(probeMode, itemStack, probeInfo, accessor, ConfigHandler.instance());
}
}
/* Lookup by class (for tileentities) */
if (ModuleProbeRegistrar.instance().hasProviders(accessor.getTileEntity())) {
List<IProbeDataProvider> probeDataProviders = ModuleProbeRegistrar.instance()
.getProviders(accessor.getTileEntity());
for (IProbeDataProvider probeDataProvider : probeDataProviders) {
probeDataProvider.addProbeInfo(probeMode, itemStack, probeInfo, accessor, ConfigHandler.instance());
}
}
return probeInfo;
}
// append legacy Tooltip into new ProbeInfo if possible
public ProbeInfo appendTooltipData(ProbeInfo probeInfo, List<String> tooltip, ItemStack itemStack,
DataAccessorCommon accessor) {
if (tooltip.isEmpty()) {
return probeInfo;
}
for (String s : tooltip) {
probeInfo.text(s);
}
return probeInfo;
}
}
@@ -0,0 +1,64 @@
package mcp.mobius.waila.api.impl.elements;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import mcp.mobius.waila.api.elements.IProbeDataProvider;
import mcp.mobius.waila.api.elements.IProbeRegistrar;
public class ModuleProbeRegistrar implements IProbeRegistrar {
private static ModuleProbeRegistrar instance = null;
public LinkedHashMap<Class<?>, ArrayList<IProbeDataProvider>> probeProviders = new LinkedHashMap<>();;
public LinkedHashMap<String, String> IMCRequests = new LinkedHashMap<>();
private ModuleProbeRegistrar() {
instance = this;
}
public static ModuleProbeRegistrar instance() {
if (ModuleProbeRegistrar.instance == null) ModuleProbeRegistrar.instance = new ModuleProbeRegistrar();
return ModuleProbeRegistrar.instance;
}
/* IMC HANDLING */
public void addIMCRequest(String method, String modname) {
this.IMCRequests.put(method, modname);
}
@Override
public void registerProbeProvider(IProbeDataProvider dataProvider, Class<?> block) {
this.registerProvider(dataProvider, block, this.probeProviders);
}
private void registerProvider(IProbeDataProvider dataProvider, Class<?> clazz,
LinkedHashMap<Class<?>, ArrayList<IProbeDataProvider>> target) {
if (clazz == null || dataProvider == null) throw new RuntimeException(
"Trying to register a null provider or null block ! Please check the stacktrace to know what was the original registration method.");
if (!target.containsKey(clazz)) target.put(clazz, new ArrayList<>());
ArrayList<IProbeDataProvider> providers = target.get(clazz);
if (providers.contains(dataProvider)) return;
target.get(clazz).add(dataProvider);
}
public boolean hasProviders(Object obj) {
for (Class clazz : probeProviders.keySet()) if (clazz.isInstance(obj)) return true;
return false;
}
public List<IProbeDataProvider> getProviders(Object obj) {
List<IProbeDataProvider> returnList = new ArrayList<>();
for (Class clazz : probeProviders.keySet()) {
if (clazz.isInstance(obj)) returnList.addAll(probeProviders.get(clazz));
}
return returnList;
}
}
@@ -0,0 +1,21 @@
package mcp.mobius.waila.api.impl.elements;
import java.util.List;
import mcp.mobius.waila.api.elements.ElementAlignment;
import mcp.mobius.waila.api.elements.IElement;
public class ProbeInfo extends ElementVertical {
public List<IElement> getElements() {
return this.children;
}
public ProbeInfo() {
super(null, 2, ElementAlignment.ALIGN_TOPLEFT);
}
public void removeElement(IElement element) {
this.getElements().remove(element);
}
}
@@ -0,0 +1,142 @@
package mcp.mobius.waila.api.impl.elements;
import mcp.mobius.waila.api.NumberFormat;
import mcp.mobius.waila.api.elements.IProgressStyle;
public class ProgressStyle implements IProgressStyle {
private int borderColor = -1;
private int backgroundColor = -16777216;
private int filledColor = -5592406;
private int alternatefilledColor = -5592406;
private boolean showText = true;
private String text;
private int textColor = 0xffffffff;
private boolean textShadow = true;
private int width = 100;
private int height = 12;
private boolean lifeBar = false;
private boolean armorBar = false;
private NumberFormat numberFormat;
public ProgressStyle() {
this.numberFormat = NumberFormat.COMPACT;
}
public ProgressStyle borderColor(int c) {
this.borderColor = c;
return this;
}
public ProgressStyle backgroundColor(int c) {
this.backgroundColor = c;
return this;
}
public ProgressStyle filledColor(int c) {
this.filledColor = c;
return this;
}
public ProgressStyle alternateFilledColor(int c) {
this.alternatefilledColor = c;
return this;
}
public ProgressStyle showText(boolean b) {
this.showText = b;
return this;
}
public ProgressStyle numberFormat(NumberFormat f) {
this.numberFormat = f;
return this;
}
public ProgressStyle text(String text) {
this.text = text;
return this;
}
public ProgressStyle textColor(int color) {
this.textColor = color;
return this;
}
public ProgressStyle textShadow(boolean b) {
this.textShadow = b;
return this;
}
public ProgressStyle width(int w) {
this.width = w;
return this;
}
public ProgressStyle height(int h) {
this.height = h;
return this;
}
public IProgressStyle lifeBar(boolean b) {
this.lifeBar = b;
return this;
}
public IProgressStyle armorBar(boolean b) {
this.armorBar = b;
return this;
}
public int getBorderColor() {
return this.borderColor;
}
public int getBackgroundColor() {
return this.backgroundColor;
}
public int getFilledColor() {
return this.filledColor;
}
public int getAlternatefilledColor() {
return this.alternatefilledColor;
}
public boolean isShowText() {
return this.showText;
}
public NumberFormat getNumberFormat() {
return this.numberFormat;
}
public String getText() {
return this.text;
}
public int getTextColor() {
return this.textColor;
}
public boolean isTextShadow() {
return this.textShadow;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public boolean isLifeBar() {
return this.lifeBar;
}
public boolean isArmorBar() {
return this.armorBar;
}
}
@@ -0,0 +1,123 @@
package mcp.mobius.waila.api.impl.elements;
import mcp.mobius.waila.api.elements.ElementAlignment;
import mcp.mobius.waila.api.elements.ITextStyle;
import mcp.mobius.waila.overlay.OverlayConfig;
public class TextStyle implements ITextStyle {
int top = 0;
int bottom = 0;
int left = 0;
int right = 0;
Integer width = null;
Integer height = null;
ElementAlignment align = ElementAlignment.ALIGN_TOPLEFT;
int color = OverlayConfig.fontcolor;
boolean shadow = false;
@Override
public ITextStyle copy() {
return new TextStyle().bottomPadding(bottom).leftPadding(left).rightPadding(right).topPadding(top)
.bounds(width, height).alignment(align);
}
@Override
public TextStyle topPadding(int padding) {
top = padding;
return this;
}
@Override
public TextStyle bottomPadding(int padding) {
bottom = padding;
return this;
}
@Override
public TextStyle leftPadding(int padding) {
left = padding;
return this;
}
@Override
public TextStyle rightPadding(int padding) {
right = padding;
return this;
}
@Override
public TextStyle alignment(ElementAlignment align) {
this.align = align;
return this;
}
@Override
public TextStyle width(Integer width) {
this.width = width;
return this;
}
@Override
public TextStyle height(Integer height) {
this.height = height;
return this;
}
@Override
public TextStyle color(int color) {
this.color = color;
return this;
}
@Override
public TextStyle shadow(boolean shadow) {
this.shadow = shadow;
return this;
}
@Override
public int getLeftPadding() {
return left;
}
@Override
public int getRightPadding() {
return right;
}
@Override
public int getTopPadding() {
return top;
}
@Override
public int getBottomPadding() {
return bottom;
}
@Override
public ElementAlignment getAlignment() {
return align;
}
@Override
public Integer getWidth() {
return width;
}
@Override
public Integer getHeight() {
return height;
}
@Override
public int getColor() {
return color;
}
@Override
public boolean getShadow() {
return shadow;
}
}
@@ -5,11 +5,7 @@ import net.minecraftforge.common.config.Configuration;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.gui.events.MouseEvent;
import mcp.mobius.waila.gui.interfaces.CType;
import mcp.mobius.waila.gui.interfaces.IWidget;
import mcp.mobius.waila.gui.interfaces.RenderPriority;
import mcp.mobius.waila.gui.interfaces.Signal;
import mcp.mobius.waila.gui.interfaces.WAlign;
import mcp.mobius.waila.gui.interfaces.*;
import mcp.mobius.waila.gui.screens.ScreenBase;
import mcp.mobius.waila.gui.widgets.LabelFixedFont;
import mcp.mobius.waila.gui.widgets.LayoutBase;
@@ -2,7 +2,10 @@ package mcp.mobius.waila.gui.screens.config;
import net.minecraft.client.gui.GuiScreen;
import org.lwjgl.util.Point;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.gui.events.MouseEvent;
import mcp.mobius.waila.gui.interfaces.CType;
import mcp.mobius.waila.gui.interfaces.WAlign;
import mcp.mobius.waila.gui.screens.ScreenBase;
@@ -19,9 +22,27 @@ public class ScreenModuleConfig extends ScreenBase {
public ScreenModuleConfig(GuiScreen parent, String modname) {
super(parent);
this.getRoot().addWidget("ButtonContainer", new ButtonContainerLabel(this.getRoot(), 2, 100, 25.0));
this.getRoot().addWidget("ButtonContainer", new ButtonContainerLabel(this.getRoot(), 2, 100, 25.0) {
protected int scrollValue = 0;
@Override
public void onMouseWheel(MouseEvent event) {
scrollValue += event.z * 4;
if (scrollValue > 0) {
scrollValue = 0;
}
}
@Override
public void draw(Point pos) {
if (scrollValue <= 0) {
geom.setPos(0, 20.0 + scrollValue, true, true);
}
}
});
this.getRoot().getWidget("ButtonContainer").setGeometry(
new WidgetGeometry(0.0, 20.0, 100.0, 60.0, CType.RELXY, CType.RELXY, WAlign.LEFT, WAlign.TOP));
new WidgetGeometry(0.0, 20.0, 100.0, 200.0, CType.RELXY, CType.RELXY, WAlign.LEFT, WAlign.TOP));
ButtonContainerLabel buttonContainer = ((ButtonContainerLabel) this.getRoot().getWidget("ButtonContainer"));
@@ -84,6 +84,16 @@ public class ScreenWailaConfig extends ScreenBase {
"screen.button.no",
"screen.button.yes"),
"choice.shifttoggledents");
buttonContainer.addButton(
new ButtonBooleanConfig(
this.getRoot(),
Configuration.CATEGORY_GENERAL,
Constants.CFG_WAILA_FORCE_LEGACY_MODE,
true,
false,
"screen.button.no",
"screen.button.yes"),
"choice.forcelegacymode");
this.getRoot().addWidget("LayoutConfigPos", new LayoutBase(this.getRoot()));
this.getRoot().getWidget("LayoutConfigPos")
@@ -7,11 +7,7 @@ import mcp.mobius.waila.cbcore.LangUtil;
import mcp.mobius.waila.gui.interfaces.CType;
import mcp.mobius.waila.gui.interfaces.WAlign;
import mcp.mobius.waila.gui.screens.ScreenBase;
import mcp.mobius.waila.gui.widgets.ItemStackDisplay;
import mcp.mobius.waila.gui.widgets.LabelFixedFont;
import mcp.mobius.waila.gui.widgets.LayoutBase;
import mcp.mobius.waila.gui.widgets.ViewTable;
import mcp.mobius.waila.gui.widgets.WidgetGeometry;
import mcp.mobius.waila.gui.widgets.*;
public class ScreenEnchants extends ScreenBase {
@@ -14,7 +14,7 @@ package mcp.mobius.waila.gui.truetyper;
* <http://www.gnu.org/licenses/>.
*/
import java.awt.Font;
import java.awt.*;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
@@ -1,11 +1,6 @@
package mcp.mobius.waila.gui.truetyper;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
@@ -1,8 +1,6 @@
package mcp.mobius.waila.handlers;
import static mcp.mobius.waila.api.SpecialChars.BLUE;
import static mcp.mobius.waila.api.SpecialChars.ITALIC;
import static mcp.mobius.waila.api.SpecialChars.RENDER;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -1,10 +1,6 @@
package mcp.mobius.waila.handlers;
import static mcp.mobius.waila.api.SpecialChars.BLUE;
import static mcp.mobius.waila.api.SpecialChars.GRAY;
import static mcp.mobius.waila.api.SpecialChars.ITALIC;
import static mcp.mobius.waila.api.SpecialChars.WHITE;
import static mcp.mobius.waila.api.SpecialChars.getRenderString;
import static mcp.mobius.waila.api.SpecialChars.*;
import java.util.List;
@@ -19,7 +19,9 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.elements.IProbeDataProvider;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.api.impl.elements.ModuleProbeRegistrar;
import mcp.mobius.waila.utils.AccessHelper;
import mcp.mobius.waila.utils.NBTUtil;
import mcp.mobius.waila.utils.WailaExceptionHandler;
@@ -41,15 +43,17 @@ public class Message0x01TERequest extends SimpleChannelInboundHandler<Message0x0
public int posY;
public int posZ;
public HashSet<String> keys = new HashSet<>();
public boolean useNewAPI;
public Message0x01TERequest() {}
public Message0x01TERequest(TileEntity ent, HashSet<String> keys) {
public Message0x01TERequest(TileEntity ent, HashSet<String> keys, boolean useNewAPI) {
this.dim = ent.getWorldObj().provider.dimensionId;
this.posX = ent.xCoord;
this.posY = ent.yCoord;
this.posZ = ent.zCoord;
this.keys = keys;
this.useNewAPI = useNewAPI;
}
@Override
@@ -61,6 +65,8 @@ public class Message0x01TERequest extends SimpleChannelInboundHandler<Message0x0
target.writeInt(this.keys.size());
for (String key : keys) WailaPacketHandler.INSTANCE.writeString(target, key);
target.writeBoolean(useNewAPI);
}
@Override
@@ -76,6 +82,8 @@ public class Message0x01TERequest extends SimpleChannelInboundHandler<Message0x0
for (int i = 0; i < nkeys; i++) this.keys.add(WailaPacketHandler.INSTANCE.readString(dat));
msg.useNewAPI = dat.readBoolean();
} catch (Exception e) {
WailaExceptionHandler.handleErr(e, this.getClass().toString(), null);
}
@@ -91,10 +99,41 @@ public class Message0x01TERequest extends SimpleChannelInboundHandler<Message0x0
if (entity == null) return;
try {
NBTTagCompound tag = new NBTTagCompound();
boolean hasProbeBlock = ModuleProbeRegistrar.instance().hasProviders(block);
boolean hasProbeEntity = ModuleProbeRegistrar.instance().hasProviders(entity);
boolean hasNBTBlock = ModuleRegistrar.instance().hasNBTProviders(block);
boolean hasNBTEnt = ModuleRegistrar.instance().hasNBTProviders(entity);
if (hasNBTBlock || hasNBTEnt) {
if ((hasProbeBlock || hasProbeEntity) && msg.useNewAPI) {
tag.setInteger("x", msg.posX);
tag.setInteger("y", msg.posY);
tag.setInteger("z", msg.posZ);
tag.setString("id", (String) ((HashMap) classToNameMap.get(null)).get(entity.getClass()));
EntityPlayerMP player = ((NetHandlerPlayServer) ctx.channel().attr(NetworkRegistry.NET_HANDLER)
.get()).playerEntity;
for (IProbeDataProvider provider : ModuleProbeRegistrar.instance().getProviders(block)) {
try {
tag = provider.getNBTData(player, entity, tag, world, msg.posX, msg.posY, msg.posZ);
} catch (AbstractMethodError | NoSuchMethodError ame) {
// tag = AccessHelper.getNBTData(provider, entity, tag, world, msg.posX, msg.posY, msg.posZ);
}
}
for (IProbeDataProvider provider : ModuleProbeRegistrar.instance().getProviders(entity)) {
try {
tag = provider.getNBTData(player, entity, tag, world, msg.posX, msg.posY, msg.posZ);
} catch (AbstractMethodError | NoSuchMethodError ame) {
// tag = AccessHelper.getNBTData(provider, entity, tag, world, msg.posX, msg.posY, msg.posZ);
}
}
}
// We will try to use old tooltips regardless of the mode
if ((hasNBTBlock || hasNBTEnt)) {
tag.setInteger("x", msg.posX);
tag.setInteger("y", msg.posY);
tag.setInteger("z", msg.posZ);
@@ -15,14 +15,17 @@ import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import mcp.mobius.waila.api.IWailaTooltipRenderer;
import mcp.mobius.waila.api.elements.IItemStyle;
import mcp.mobius.waila.api.impl.DataAccessorCommon;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.utils.WailaExceptionHandler;
@@ -83,6 +86,44 @@ public class DisplayUtil {
enable2DRender();
}
public static void elementRenderStack(int x, int y, ItemStack stack, IItemStyle itemStyle) {
enable3DRender();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
float xScale = (float) itemStyle.getWidth() / 16;
float yScale = (float) itemStyle.getHeight() / 16;
try {
GL11.glPushMatrix(); // マトリックスを保存
// スケールを適用
GL11.glScalef(xScale, yScale, 1);
// アイテムを描画
RenderHelper.enableGUIStandardItemLighting();
renderItem.renderItemAndEffectIntoGUI(
fontRenderer,
textureManager,
stack,
(int) (x / xScale),
(int) (y / yScale));
renderItem.renderItemOverlayIntoGUI(
fontRenderer,
textureManager,
stack,
(int) (x / xScale),
(int) (y / yScale));
RenderHelper.disableStandardItemLighting();
} catch (Exception e) {
String stackStr = stack != null ? stack.toString() : "NullStack";
WailaExceptionHandler.handleErr(e, "renderStack | " + stackStr, null);
} finally {
GL11.glPopMatrix(); // マトリックスを復元
}
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
enable2DRender();
}
public static void enable3DRender() {
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_DEPTH_TEST);
@@ -177,4 +218,19 @@ public class DisplayUtil {
DisplayUtil.drawTexturedModalRect(x, y, icon.u, icon.v, sx, sy, icon.su, icon.sv);
}
public static void drawThickBeveledBox(int x1, int y1, int x2, int y2, int thickness, int topleftcolor,
int botrightcolor, int fillcolor) {
if (fillcolor != -1) {
Gui.drawRect(x1 + 1, y1 + 1, x2 - 1, y2 - 1, fillcolor);
}
Gui.drawRect(x1, y1, x2 - 1, y1 + thickness, topleftcolor);
Gui.drawRect(x1, y1, x1 + thickness, y2 - 1, topleftcolor);
Gui.drawRect(x2 - thickness, y1, x2, y2 - 1, botrightcolor);
Gui.drawRect(x1, y2 - thickness, x2, y2, botrightcolor);
}
public static void drawVerticalLine(int x1, int y1, int y2, int color) {
Gui.drawRect(x1, y1, x1 + 1, y2, color);
}
}
@@ -0,0 +1,152 @@
package mcp.mobius.waila.overlay;
import java.awt.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraftforge.common.config.Configuration;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.elements.ProbeInfo;
import mcp.mobius.waila.utils.Constants;
public class TOPOverlayRenderer {
protected static boolean hasBlending;
protected static boolean hasLight;
protected static boolean hasDepthTest;
protected static boolean hasLight0;
protected static boolean hasLight1;
protected static boolean hasRescaleNormal;
protected static boolean hasColorMaterial;
protected static int boundTexIndex;
static int w, h, x, y, ty;
private static float progressAlpha = 0;
private static long lastMilliSecond;
private static float savedProgress = 0;
private static final int MARGIN = 5;
private static final int DEFAULT_COLOR = 0xFFA0A0A0;
private static final int FAILURE_COLOR = 0xFFAA0000;
public static void renderOverlay() {
Minecraft mc = Minecraft.getMinecraft();
if (!(mc.currentScreen == null && mc.theWorld != null
&& Minecraft.isGuiEnabled()
&& !mc.gameSettings.keyBindPlayerList.getIsKeyPressed()
&& ConfigHandler.instance().showTooltip()
&& RayTracing.instance().getTarget() != null))
return;
computePositionAndSize(WailaTickHandler.instance().probe);
renderElements(WailaTickHandler.instance().probe);
}
public static void renderElements(ProbeInfo probeInfo) {
GL11.glPushMatrix();
saveGLState();
GL11.glScalef(OverlayConfig.scale, OverlayConfig.scale, 1.0f);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
drawTooltipBox(x, y, w, h, OverlayConfig.bgcolor, OverlayConfig.gradient1, OverlayConfig.gradient2);
drawProgressBar();
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
probeInfo.render(x + MARGIN, y + MARGIN);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
loadGLState();
GL11.glPopMatrix();
}
private static void drawProgressBar() {
float elapsedSecond = (float) (System.currentTimeMillis() - lastMilliSecond) / 1000;
float damage = Minecraft.getMinecraft().playerController.curBlockDamageMP;
if (damage == 0 && progressAlpha <= 0) {
lastMilliSecond = System.currentTimeMillis();
return;
}
int drawX = x + 1;
int drawY = y; // TODO: configurable top / bottom drawing
if (damage > 0) {
progressAlpha = Math.min(damage, 0.6F);
progressAlpha += 0.4F * damage;
savedProgress = damage;
} else {
progressAlpha -= elapsedSecond;
}
int color = applyAlpha(DEFAULT_COLOR, progressAlpha); // TODO: change color with harvestability
int width = (int) ((w - 1) * savedProgress);
DisplayUtil.drawGradientRect(drawX, drawY, width - 1, 2, color, color);
lastMilliSecond = System.currentTimeMillis();
}
private static int applyAlpha(int color, float alpha) {
int red = (color >> 16) & 0xFF;
int green = (color >> 8) & 0xFF;
int blue = color & 0xFF;
int appliedAlpha = (int) (alpha * 255); // アルファ値を0〜255の範囲に変換
return (appliedAlpha << 24) | (red << 16) | (green << 8) | blue;
}
public static void saveGLState() {
hasBlending = GL11.glGetBoolean(GL11.GL_BLEND);
hasLight = GL11.glGetBoolean(GL11.GL_LIGHTING);
hasDepthTest = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
boundTexIndex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
GL11.glPushAttrib(GL11.GL_CURRENT_BIT);
}
public static void loadGLState() {
if (hasBlending) GL11.glEnable(GL11.GL_BLEND);
else GL11.glDisable(GL11.GL_BLEND);
if (hasLight1) GL11.glEnable(GL11.GL_LIGHT1);
else GL11.glDisable(GL11.GL_LIGHT1);
if (hasDepthTest) GL11.glEnable(GL11.GL_DEPTH_TEST);
else GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, boundTexIndex);
GL11.glPopAttrib();
}
public static void drawTooltipBox(int x, int y, int w, int h, int bg, int grad1, int grad2) {
DisplayUtil.drawGradientRect(x + 1, y, w - 1, 1, bg, bg);
DisplayUtil.drawGradientRect(x + 1, y + h, w - 1, 1, bg, bg);
DisplayUtil.drawGradientRect(x + 1, y + 1, w - 1, h - 1, bg, bg);// center
DisplayUtil.drawGradientRect(x, y + 1, 1, h - 1, bg, bg);
DisplayUtil.drawGradientRect(x + w, y + 1, 1, h - 1, bg, bg);
DisplayUtil.drawGradientRect(x + 1, y + 2, 1, h - 3, grad1, grad2);
DisplayUtil.drawGradientRect(x + w - 1, y + 2, 1, h - 3, grad1, grad2);
DisplayUtil.drawGradientRect(x + 1, y + 1, w - 1, 1, grad1, grad1);
DisplayUtil.drawGradientRect(x + 1, y + h - 1, w - 1, 1, grad2, grad2);
}
private static void computePositionAndSize(ProbeInfo probeInfo) {
Point pos = new Point(
ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_POSX, 0),
ConfigHandler.instance().getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_POSY, 0));
w = probeInfo.getWidth() + MARGIN * 2;
h = probeInfo.getHeight() + MARGIN * 2;
Dimension size = DisplayUtil.displaySize();
x = ((int) (size.width / OverlayConfig.scale) - w - 1) * pos.x / 10000;
y = ((int) (size.height / OverlayConfig.scale) - h - 1) * pos.y / 10000;
ty = (h - probeInfo.getHeight()) / 2 + 1;
}
}
@@ -22,6 +22,8 @@ import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.DataAccessorCommon;
import mcp.mobius.waila.api.impl.MetaDataProvider;
import mcp.mobius.waila.api.impl.TipList;
import mcp.mobius.waila.api.impl.elements.MetaProbeDataProvider;
import mcp.mobius.waila.api.impl.elements.ProbeInfo;
import mcp.mobius.waila.cbcore.Layout;
import mcp.mobius.waila.client.KeyEvent;
import mcp.mobius.waila.utils.Constants;
@@ -30,6 +32,10 @@ public class WailaTickHandler {
public Tooltip tooltip = null;
public MetaDataProvider handler = new MetaDataProvider();
public ProbeInfo probe = null;
public MetaProbeDataProvider elementHandler = new MetaProbeDataProvider();
private final Minecraft mc = Minecraft.getMinecraft();
private static WailaTickHandler _instance;
@@ -44,6 +50,11 @@ public class WailaTickHandler {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void tickRender(TickEvent.RenderTickEvent event) {
if (probe != null) {
TOPOverlayRenderer.renderOverlay();
return;
}
OverlayRenderer.renderOverlay();
}
@@ -64,6 +75,19 @@ public class WailaTickHandler {
RayTracing.instance().fire();
MovingObjectPosition target = RayTracing.instance().getTarget();
probe = null;
if (target != null && target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK
&& !ConfigHandler.instance()
.getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_FORCE_LEGACY_MODE, false)) {
DataAccessorCommon accessor = DataAccessorCommon.instance;
accessor.set(world, player, target);
ItemStack targetStack = RayTracing.instance().getTargetStack();
if (targetStack != null) {
probe = elementHandler.handleBlockElementData(targetStack, world, player, target, accessor);
}
}
List<String> currenttip;
List<String> currenttipHead;
List<String> currenttipBody;
@@ -118,6 +142,10 @@ public class WailaTickHandler {
currenttip.addAll(currenttipTail);
this.tooltip = new Tooltip(currenttip, targetStack);
if (!ConfigHandler.instance()
.getConfig(Configuration.CATEGORY_GENERAL, Constants.CFG_WAILA_FORCE_LEGACY_MODE, false)) {
probe = elementHandler.appendTooltipData(probe, currenttipBody, targetStack, accessor);
}
}
} else if (target != null && target.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
DataAccessorCommon accessor = DataAccessorCommon.instance;
@@ -11,6 +11,7 @@ import mcp.mobius.waila.addons.enderstorage.EnderStorageModule;
import mcp.mobius.waila.addons.etb.ETBModule;
import mcp.mobius.waila.addons.exu.ExtraUtilitiesModule;
import mcp.mobius.waila.addons.gravestone.GravestoneModule;
import mcp.mobius.waila.addons.harvestability.HUDHandlerHarvestability;
import mcp.mobius.waila.addons.harvestcraft.HarvestcraftModule;
import mcp.mobius.waila.addons.ic2.IC2Module;
import mcp.mobius.waila.addons.magicalcrops.MagicalCropsModule;
@@ -26,7 +27,9 @@ import mcp.mobius.waila.addons.twilightforest.TwilightForestModule;
import mcp.mobius.waila.addons.vanillamc.HUDHandlerFurnace;
import mcp.mobius.waila.addons.vanillamc.HUDHandlerVanilla;
import mcp.mobius.waila.api.IWailaRegistrar;
import mcp.mobius.waila.api.elements.IProbeRegistrar;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.api.impl.elements.ModuleProbeRegistrar;
import mcp.mobius.waila.handlers.DecoratorFMP;
import mcp.mobius.waila.handlers.HUDHandlerFMP;
@@ -98,6 +101,8 @@ public class ProxyServer {
/* Agriculture */
AgricultureModule.register();
HUDHandlerHarvestability.register();
if (Loader.isModLoaded("ForgeMultipart")) {
HUDHandlerFMP.register();
DecoratorFMP.register();
@@ -108,6 +113,10 @@ public class ProxyServer {
for (String s : ModuleRegistrar.instance().IMCRequests.keySet()) {
this.callbackRegistration(s, ModuleRegistrar.instance().IMCRequests.get(s));
}
for (String s : ModuleProbeRegistrar.instance().IMCRequests.keySet()) {
this.callbackProbeRegistration(s, ModuleProbeRegistrar.instance().IMCRequests.get(s));
}
}
public void callbackRegistration(String method, String modname) {
@@ -133,6 +142,29 @@ public class ProxyServer {
}
}
public void callbackProbeRegistration(String method, String modname) {
String[] splitName = method.split("\\.");
String methodName = splitName[splitName.length - 1];
String className = method.substring(0, method.length() - methodName.length() - 1);
Waila.log.info(String.format("Trying to reflect %s %s", className, methodName));
try {
Class<?> reflectClass = Class.forName(className);
Method reflectMethod = reflectClass.getDeclaredMethod(methodName, IProbeRegistrar.class);
reflectMethod.invoke(null, ModuleProbeRegistrar.instance());
Waila.log.info(String.format("Success in registering %s", modname));
} catch (ClassNotFoundException e) {
Waila.log.warn(String.format("Could not find class %s", className));
} catch (NoSuchMethodException e) {
Waila.log.warn(String.format("Could not find method %s", methodName));
} catch (Exception e) {
Waila.log.warn(String.format("Exception while trying to access the method : %s", e));
}
}
public Object getFont() {
return null;
}
@@ -27,6 +27,7 @@ public final class Constants {
public static String CFG_WAILA_NHEARTS = "waila.cfg.heartsperline";
public static String CFG_WAILA_MAXHP = "waila.cfg.maxhpbeforetext";
public static String CFG_WAILA_NEWFILTERS = "waila.cfg.newfilters";
public static String CFG_WAILA_FORCE_LEGACY_MODE = "waila.cfg.forcelegacymode";
public static String CFG_WAILA_ALPHA = "waila.cfg.alpha";
public static String CFG_WAILA_BGCOLOR = "waila.cfg.bgcolor";
@@ -5,13 +5,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashSet;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.*;
public class NBTUtil {
+1
View File
@@ -0,0 +1 @@
public net.minecraft.client.multiplayer.PlayerControllerMP field_78770_f # curBlockDamageMP
@@ -20,6 +20,7 @@ choice.toggledmaintained=Toggled/Maintained
choice.showliquids=Liquids
choice.shifttoggledblock=Sneak toggle blocks
choice.shifttoggledents=Sneak toggle entities
choice.forcelegacymode=Force legacy mode
screen.button.configureaspect=Configure aspect...
enchant.title.name=Name
@@ -148,4 +149,39 @@ option.general.showhp=Show entities health
option.general.showcrop=Show crop growth
option.thaumcraft.aspects=Show aspects
nei.options.keys.showenchant=Show enchanting values
nei.options.keys.showenchant=Show enchanting values
# waila harvestability
# tools
wailaharvestability.toolclass.pickaxe=Pickaxe
wailaharvestability.toolclass.shovel=Shovel
wailaharvestability.toolclass.axe=Axe
wailaharvestability.toolclass.chisel=Chisel
wailaharvestability.toolclass.scoop=Scoop
wailaharvestability.toolclass.crowbar=Crowbar
wailaharvestability.toolclass.sword=Sword
# tooltips
wailaharvestability.effectivetool=Effective Tool :
wailaharvestability.harvestlevel=Harvest Level :
wailaharvestability.currentlyharvestable= Currently Harvestable
wailaharvestability.harvestable= Harvestable
# options
option.harvestability.harvestlevel=Harvest level
option.harvestability.effectivetool=Effective tool
option.harvestability.currentlyharvestable=Currently harvestable
option.harvestability.oresonly=Ores only
option.harvestability.harvestlevel.sneakingonly=Sneak only: Harvest level
option.harvestability.effectivetool.sneakingonly=Sneak only: Effective tool
option.harvestability.currentlyharvestable.sneakingonly=Sneak only: Harvestable
option.harvestability.minimal=Minimal mode
option.harvestability.unharvestableonly=Unharvestable only
option.harvestability.toolrequiredonly=Tool required only
option.harvestability.shearability=Shearability
option.harvestability.shearability.sneakingonly=Sneak only: Shearability
option.harvestability.silktouchability=Silk Touchability
option.harvestability.silktouchability.sneakingonly=Sneak only: Silk Touchability
option.harvestability.harvestlevelnum=Harvest level no.
option.harvestability.harvestlevelnum.sneakingonly=Sneak only: Harvest level no.