Compare commits

..
12 changed files with 157 additions and 218 deletions

No files matched your search

@@ -17,7 +17,6 @@ import cpw.mods.fml.common.registry.GameData;
import mcp.mobius.waila.api.IWailaCommonAccessor;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaEntityAccessor;
import mcp.mobius.waila.handlers.HUDHandlerInventory;
import mcp.mobius.waila.utils.NBTUtil;
public class DataAccessorCommon implements IWailaCommonAccessor, IWailaDataAccessor, IWailaEntityAccessor {
@@ -124,23 +123,9 @@ public class DataAccessorCommon implements IWailaCommonAccessor, IWailaDataAcces
@Override
public NBTTagCompound getNBTData() {
if ((this.tileEntity != null) && this.isTagCorrectTileEntity(this.remoteNbt)) {
if (!remoteNbt.getBoolean(HUDHandlerInventory.TAG_SUMMARY_ONLY)) return remoteNbt;
NBTTagCompound tag = new NBTTagCompound();
try {
this.tileEntity.writeToNBT(tag);
} catch (Exception ignored) {}
return HUDHandlerInventory.mergeSummary(remoteNbt, tag);
}
if ((this.tileEntity != null) && this.isTagCorrectTileEntity(this.remoteNbt)) return remoteNbt;
if ((this.entity != null) && this.isTagCorrectEntity(this.remoteNbt)) {
if (!remoteNbt.getBoolean(HUDHandlerInventory.TAG_SUMMARY_ONLY)) return remoteNbt;
NBTTagCompound tag = new NBTTagCompound();
try {
this.entity.writeToNBT(tag);
} catch (Exception ignored) {}
return HUDHandlerInventory.mergeSummary(remoteNbt, tag);
}
if ((this.entity != null) && this.isTagCorrectEntity(this.remoteNbt)) return remoteNbt;
if (this.tileEntity != null) {
NBTTagCompound tag = new NBTTagCompound();
@@ -21,7 +21,6 @@ import mcp.mobius.waila.api.IWailaEntityProvider;
import mcp.mobius.waila.cbcore.LangUtil;
import mcp.mobius.waila.cbcore.Layout;
import mcp.mobius.waila.client.KeyEvent;
import mcp.mobius.waila.handlers.HUDHandlerInventory;
import mcp.mobius.waila.network.Message0x01TERequest;
import mcp.mobius.waila.network.Message0x03EntRequest;
import mcp.mobius.waila.network.WailaPacketHandler;
@@ -81,8 +80,7 @@ public class MetaDataProvider {
keys.addAll(ModuleRegistrar.instance().getSyncedNBTKeys(accessor.getTileEntity()));
if (!keys.isEmpty() || ModuleRegistrar.instance().hasNBTProviders(block)
|| ModuleRegistrar.instance().hasNBTProviders(accessor.getTileEntity())
|| HUDHandlerInventory.shouldRequest(accessor.getTileEntity()))
|| ModuleRegistrar.instance().hasNBTProviders(accessor.getTileEntity()))
WailaPacketHandler.INSTANCE.sendToServer(new Message0x01TERequest(accessor.getTileEntity(), keys));
} else if (accessor.getTileEntity() != null && !Waila.instance.serverPresent
@@ -195,8 +193,7 @@ public class MetaDataProvider {
if (ModuleRegistrar.instance().hasSyncedNBTKeys(accessor.getEntity()))
keys.addAll(ModuleRegistrar.instance().getSyncedNBTKeys(accessor.getEntity()));
if (!keys.isEmpty() || ModuleRegistrar.instance().hasNBTEntityProviders(accessor.getEntity())
|| HUDHandlerInventory.shouldRequest(accessor.getEntity()))
if (!keys.isEmpty() || ModuleRegistrar.instance().hasNBTEntityProviders(accessor.getEntity()))
WailaPacketHandler.INSTANCE.sendToServer(new Message0x03EntRequest(accessor.getEntity(), keys));
} else if (accessor.getEntity() != null && !Waila.instance.serverPresent && accessor.isTimeElapsed(250)) {
@@ -16,6 +16,7 @@ import mcp.mobius.waila.handlers.HUDHandlerBlocks;
import mcp.mobius.waila.handlers.HUDHandlerEntities;
import mcp.mobius.waila.handlers.VanillaTooltipHandler;
import mcp.mobius.waila.handlers.nei.NEIHandler;
import mcp.mobius.waila.overlay.BreakProgressRenderer;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderAspectString;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderBar;
import mcp.mobius.waila.overlay.tooltiprenderers.TTRenderFluidBar;
@@ -53,6 +54,8 @@ public class ProxyClient extends ProxyServer {
ModuleRegistrar.instance().addConfig("General", "general.showents");
ModuleRegistrar.instance().addConfig("General", "general.showhp");
ModuleRegistrar.instance().addConfig("General", "general.showcrop");
ModuleRegistrar.instance().addConfig("General", BreakProgressRenderer.CFG_ENABLED, true);
ModuleRegistrar.instance().addConfig("General", BreakProgressRenderer.CFG_TOP, false);
ModuleRegistrar.instance().registerTooltipRenderer("waila.health", new TTRenderHealth());
ModuleRegistrar.instance().registerTooltipRenderer("waila.stack", new TTRenderStack());
@@ -1,175 +0,0 @@
package mcp.mobius.waila.handlers;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.world.World;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.IWailaEntityAccessor;
import mcp.mobius.waila.api.IWailaEntityProvider;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.cbcore.LangUtil;
import mcp.mobius.waila.utils.WailaExceptionHandler;
/**
* Shows "X items in Y of Z slots" for every block and entity that is an {@link IInventory}.
* <p>
* The server always adds the summary to the NBT answer of a {@link IInventory} target (see
* {@link #writeSummary(Object, World, int, int, int, NBTTagCompound)}). This is not done with an NBT provider, because
* an NBT provider would stop the synced NBT keys of other mods for all inventories.
* <p>
* If the client only asked because of the summary, the answer has only the summary and {@link #TAG_SUMMARY_ONLY}. The
* client then adds the summary to its own NBT of the target, so that other mods still get the same NBT as before.
*/
public class HUDHandlerInventory implements IWailaDataProvider, IWailaEntityProvider {
public static final String CFG_SHOW = "general.showinventory";
private static final String TAG_ITEMS = "WailaInvItems";
private static final String TAG_USED = "WailaInvUsed";
private static final String TAG_SLOTS = "WailaInvSlots";
public static final String TAG_SUMMARY_ONLY = "WailaInvOnly";
/**
* @return true if the client must ask the server for the summary of this target.
*/
public static boolean shouldRequest(Object target) {
// Players implement IInventory, so this also summarises player inventories. Test instanceof EntityPlayer to
// skip.
return target instanceof IInventory && ConfigHandler.instance().getConfig(CFG_SHOW, true);
}
/**
* Server side: adds the item count, the used slots and the total slots of the target to the tag.
*/
public static void writeSummary(Object target, NBTTagCompound tag) {
if (!(target instanceof IInventory)) return;
try {
IInventory inv = (IInventory) target;
// Count both halves of a double chest. The chest updates its neighbours every tick.
if (target instanceof TileEntityChest chest) {
TileEntityChest other = chest.adjacentChestXNeg != null ? chest.adjacentChestXNeg
: chest.adjacentChestXPos != null ? chest.adjacentChestXPos
: chest.adjacentChestZNeg != null ? chest.adjacentChestZNeg : chest.adjacentChestZPos;
if (other != null) inv = new InventoryLargeChest("", chest, other);
}
long items = 0;
int used = 0;
int slots = inv.getSizeInventory();
for (int i = 0; i < slots; i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack == null || stack.getItem() == null || stack.stackSize <= 0) continue;
items += stack.stackSize;
used++;
}
tag.setLong(TAG_ITEMS, items);
tag.setInteger(TAG_USED, used);
tag.setInteger(TAG_SLOTS, slots);
} catch (Exception | LinkageError e) {
// Do not lose the data of the other providers because of one bad inventory
WailaExceptionHandler.handleErr(e, "HUDHandlerInventory | " + target.getClass().getName(), null);
}
}
/**
* Client side: adds the values of a summary only answer to the local NBT of the target.
*/
public static NBTTagCompound mergeSummary(NBTTagCompound remote, NBTTagCompound local) {
for (String key : new String[] { TAG_ITEMS, TAG_USED, TAG_SLOTS }) {
NBTBase tag = remote.getTag(key);
if (tag != null) local.setTag(key, tag.copy());
}
return local;
}
private static void addLine(NBTTagCompound tag, List<String> currenttip, IWailaConfigHandler config) {
if (tag == null || !config.getConfig(CFG_SHOW, true) || !tag.hasKey(TAG_SLOTS)) return;
int slots = tag.getInteger(TAG_SLOTS);
if (slots <= 0) return;
long items = tag.getLong(TAG_ITEMS);
int used = tag.getInteger(TAG_USED);
String key = items == 1 ? "hud.msg.inventory.single" : "hud.msg.inventory";
currenttip.add(String.format(LangUtil.translateG(key), items, used, slots));
}
@Override
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
return currenttip;
}
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
addLine(accessor.getNBTData(), currenttip, config);
return currenttip;
}
@Override
public List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
return currenttip;
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x,
int y, int z) {
return tag;
}
@Override
public Entity getWailaOverride(IWailaEntityAccessor accessor, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(Entity entity, List<String> currenttip, IWailaEntityAccessor accessor,
IWailaConfigHandler config) {
return currenttip;
}
@Override
public List<String> getWailaBody(Entity entity, List<String> currenttip, IWailaEntityAccessor accessor,
IWailaConfigHandler config) {
addLine(accessor.getNBTData(), currenttip, config);
return currenttip;
}
@Override
public List<String> getWailaTail(Entity entity, List<String> currenttip, IWailaEntityAccessor accessor,
IWailaConfigHandler config) {
return currenttip;
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, Entity ent, NBTTagCompound tag, World world) {
return tag;
}
public static void register() {
HUDHandlerInventory provider = new HUDHandlerInventory();
ModuleRegistrar.instance().addConfig("General", CFG_SHOW, true);
ModuleRegistrar.instance().registerBodyProvider((IWailaDataProvider) provider, IInventory.class);
ModuleRegistrar.instance().registerBodyProvider((IWailaEntityProvider) provider, IInventory.class);
}
}
@@ -20,7 +20,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.handlers.HUDHandlerInventory;
import mcp.mobius.waila.utils.AccessHelper;
import mcp.mobius.waila.utils.NBTUtil;
import mcp.mobius.waila.utils.WailaExceptionHandler;
@@ -126,16 +125,11 @@ public class Message0x01TERequest extends SimpleChannelInboundHandler<Message0x0
}
}
} else if (msg.keys.isEmpty()) {
// The client asked only for the inventory summary
tag.setBoolean(HUDHandlerInventory.TAG_SUMMARY_ONLY, true);
} else {
entity.writeToNBT(tag);
tag = NBTUtil.createTag(tag, msg.keys);
}
HUDHandlerInventory.writeSummary(entity, tag);
tag.setInteger("WailaX", msg.posX);
tag.setInteger("WailaY", msg.posY);
tag.setInteger("WailaZ", msg.posZ);
@@ -16,7 +16,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import mcp.mobius.waila.api.IWailaEntityProvider;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.handlers.HUDHandlerInventory;
import mcp.mobius.waila.utils.AccessHelper;
import mcp.mobius.waila.utils.NBTUtil;
import mcp.mobius.waila.utils.WailaExceptionHandler;
@@ -84,16 +83,11 @@ public class Message0x03EntRequest extends SimpleChannelInboundHandler<Message0x
}
}
} else if (msg.keys.isEmpty()) {
// The client asked only for the inventory summary
tag.setBoolean(HUDHandlerInventory.TAG_SUMMARY_ONLY, true);
} else {
entity.writeToNBT(tag);
tag = NBTUtil.createTag(tag, msg.keys);
}
HUDHandlerInventory.writeSummary(entity, tag);
tag.setInteger("WailaEntityID", entity.getEntityId());
WailaPacketHandler.INSTANCE.sendTo(new Message0x04EntNBTData(tag), WailaPacketHandler.getPlayer(ctx));
@@ -0,0 +1,131 @@
package mcp.mobius.waila.overlay;
import java.lang.reflect.Field;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import cpw.mods.fml.relauncher.ReflectionHelper;
import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.impl.ConfigHandler;
import mcp.mobius.waila.utils.ColorUtils;
/**
* Draws the block break progress as a thin line on the edge of the tooltip box (Jade style). Based on the break
* progress of WDMla (https://github.com/GTNewHorizons/WDMla).
*/
public final class BreakProgressRenderer {
public static final String CFG_ENABLED = "general.breakprogress";
public static final String CFG_TOP = "general.breakprogresstop";
/** Alpha change per game tick */
private static final float FADE_PER_TICK = 0.1f;
/** Alpha while mining. The line is fully opaque only in the last tick before the block breaks. */
private static final float MAX_ALPHA = 0.6f;
private static float progress;
private static float alpha;
private static boolean canHarvest = true;
private static long lastFrame;
private static World lastWorld;
private static int lastX, lastY, lastW, lastH;
private static Field curBlockDamageField;
private static boolean fieldFailed;
private BreakProgressRenderer() {}
private static boolean isEnabled() {
return ConfigHandler.instance().getConfig(CFG_ENABLED, true);
}
/**
* Updates the progress state. Call this one time per frame before you draw.
*/
public static void update(float partialTicks) {
final Minecraft mc = Minecraft.getMinecraft();
long now = Minecraft.getSystemTime();
// A paused or lagging client must not fade out in one step
float deltaTicks = Math.min((now - lastFrame) / 50f, 1f);
lastFrame = now;
if (mc.theWorld != lastWorld) {
lastWorld = mc.theWorld;
progress = alpha = 0;
}
if (!isEnabled() || mc.playerController == null || mc.theWorld == null || mc.thePlayer == null) {
progress = alpha = 0;
return;
}
float damage = getBlockDamage(mc.playerController);
MovingObjectPosition target = RayTracing.instance().getTarget();
if (damage <= 0 || target == null || target.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
// Not mining (anymore), fade out the last progress
alpha = Math.max(alpha - deltaTicks * FADE_PER_TICK, 0f);
return;
}
int x = target.blockX, y = target.blockY, z = target.blockZ;
Block block = mc.theWorld.getBlock(x, y, z);
canHarvest = ForgeHooks.canHarvestBlock(block, mc.thePlayer, mc.theWorld.getBlockMetadata(x, y, z));
alpha = Math.min(alpha + deltaTicks * FADE_PER_TICK, MAX_ALPHA);
float perTick = block.getPlayerRelativeBlockHardness(mc.thePlayer, mc.theWorld, x, y, z);
if (damage + perTick >= 1f) {
// The block breaks in the next tick
alpha = progress = 1f;
} else {
progress = MathHelper.clamp_float(damage + partialTicks * perTick, 0f, 1f);
}
}
private static float getBlockDamage(PlayerControllerMP controller) {
if (fieldFailed) return 0f;
try {
if (curBlockDamageField == null) {
curBlockDamageField = ReflectionHelper
.findField(PlayerControllerMP.class, "curBlockDamageMP", "field_78770_f");
}
return curBlockDamageField.getFloat(controller);
} catch (Exception e) {
fieldFailed = true;
Waila.log.error("Cannot read the block damage, break progress is disabled", e);
return 0f;
}
}
/**
* Draws the line on the outer row of the tooltip box. The arguments are the box geometry from {@link Tooltip}.
*/
public static void draw(int x, int y, int w, int h) {
lastX = x;
lastY = y;
lastW = w;
lastH = h;
if (!isEnabled() || alpha <= 0) return;
int width = (int) ((w - 1) * progress);
if (width <= 0) return;
// Transparent as the box background
float boxAlpha = (OverlayConfig.alpha >>> 24) / 255f;
int base = canHarvest ? ColorUtils.breakProgress.getColor() : ColorUtils.breakProgressFailure.getColor();
int color = ((int) (((base >>> 24) & 0xFF) * alpha * boxAlpha) << 24) | (base & 0xFFFFFF);
boolean top = ConfigHandler.instance().getConfig(CFG_TOP, false);
DisplayUtil.drawGradientRect(x + 1, top ? y : y + h, width, 1, color, color);
}
/**
* Draws only the fading line, for when the tooltip itself is already gone.
*/
public static void drawLast() {
draw(lastX, lastY, lastW, lastH);
}
}
@@ -23,8 +23,17 @@ public class OverlayRenderer {
&& ConfigHandler.instance().showTooltip());
}
public static void renderOverlay(Tooltip tooltip) {
if (!isOverlayVisible() || RayTracing.instance().getTarget() == null) return;
public static void renderOverlay(Tooltip tooltip, float partialTicks) {
if (!isOverlayVisible()) return;
BreakProgressRenderer.update(partialTicks);
if (RayTracing.instance().getTarget() == null
|| RayTracing.instance().getTarget().typeOfHit == MovingObjectPosition.MovingObjectType.MISS) {
// Keep drawing the progress bar while it fades out after the block was broken
BreakProgressRenderer.drawLast();
return;
}
if (RayTracing.instance().getTarget().typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK
&& RayTracing.instance().getTargetStack() != null) {
@@ -58,6 +67,8 @@ public class OverlayRenderer {
OverlayConfig.gradient1,
OverlayConfig.gradient2);
BreakProgressRenderer.draw(tooltip.x, tooltip.y, tooltip.w, tooltip.h);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
tooltip.draw();
@@ -29,7 +29,7 @@ public class WailaTickHandler {
@SubscribeEvent
public void tickRender(TickEvent.RenderTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
OverlayRenderer.renderOverlay(tooltip);
OverlayRenderer.renderOverlay(tooltip, event.renderTickTime);
}
}
@@ -29,7 +29,6 @@ import mcp.mobius.waila.api.IWailaRegistrar;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import mcp.mobius.waila.handlers.DecoratorFMP;
import mcp.mobius.waila.handlers.HUDHandlerFMP;
import mcp.mobius.waila.handlers.HUDHandlerInventory;
import mcp.mobius.waila.utils.LoadedMods;
public class ProxyServer {
@@ -42,7 +41,6 @@ public class ProxyServer {
HUDHandlerVanilla.register();
HUDHandlerFurnace.register();
HUDHandlerInventory.register();
/* BUILDCRAFT */
BCModule.register();
@@ -11,7 +11,9 @@ public class ColorUtils {
fuelFurnaceBarTop = color.argb("fuelFurnaceBarTop", "0xFFFF8800"),
fuelFurnaceBarBottom = color.argb("fuelFurnaceBarBottom", "0xFFFFCC00"),
progressBarTop = color.argb("progressBarTop", "0xFFFF0000"),
progressBarBottom = color.argb("progressBarBottom", "0xFF8B0000");
progressBarBottom = color.argb("progressBarBottom", "0xFF8B0000"),
breakProgress = color.argb("breakProgress", "0xFFFFFFFF"),
breakProgressFailure = color.argb("breakProgressFailure", "0xFFAA0000");
// spotless:on
}
@@ -43,8 +43,6 @@ client.msg.nousage=No usage found.
hud.msg.holdkeymoreinfo=Hold %s for more info
hud.msg.empty=Empty
hud.msg.inventory=%d items in %d of %d slots
hud.msg.inventory.single=%d item in %d of %d slots
hud.msg.output=Output
hud.msg.input=Input
hud.msg.out=Out
@@ -155,7 +153,8 @@ option.stevescarts.shifttoggle=Shift toggle
option.general.showents=Show entities
option.general.showhp=Show entities health
option.general.showcrop=Show crop growth
option.general.showinventory=Show inventory summary
option.general.breakprogress=Show break progress
option.general.breakprogresstop=Break progress on top
option.thaumcraft.aspects=Show aspects
nei.options.keys.showenchant=Show enchanting values