Skip to content

Commit

Permalink
Merge branch 'bai-1.16' into bai-1.17
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/mcp/mobius/waila/overlay/WailaTickHandler.java
  • Loading branch information
deirn committed Feb 28, 2021
2 parents 922999f + 980558b commit 4763a6c
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 138 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "com.matthewprenger.cursegradle" version "1.3.0"
id 'fabric-loom' version '0.5-SNAPSHOT'
id 'fabric-loom' version '0.6-SNAPSHOT'
id "maven-publish"
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/mcp/mobius/waila/WailaClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mcp.mobius.waila;

import mcp.mobius.waila.addons.core.PluginCore;
import mcp.mobius.waila.api.impl.config.PluginConfig;
import mcp.mobius.waila.api.impl.config.WailaConfig;
import mcp.mobius.waila.gui.GuiConfigHome;
import mcp.mobius.waila.network.ClientNetworkHandler;
Expand Down Expand Up @@ -48,7 +50,7 @@ public void onInitializeClient() {
}

while (toggleLiquid.wasPressed()) {
Waila.CONFIG.get().getGeneral().setDisplayFluids(!Waila.CONFIG.get().getGeneral().shouldDisplayFluids());
PluginConfig.INSTANCE.set(PluginCore.CONFIG_SHOW_FLUID, PluginConfig.INSTANCE.get(PluginCore.CONFIG_SHOW_FLUID));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void appendBody(List<Text> tooltip, IDataAccessor accessor, IPluginConfig

@Override
public void appendTail(List<Text> tooltip, IDataAccessor accessor, IPluginConfig config) {
if (!Waila.CONFIG.get().getGeneral().shouldDisplayModName())
if (!config.get(PluginCore.CONFIG_SHOW_MOD_NAME))
return;

String modName = ModIdentification.getModInfo(accessor.getStack().getItem()).getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void appendBody(List<Text> tooltip, IEntityAccessor accessor, IPluginConf

@Override
public void appendTail(List<Text> tooltip, IEntityAccessor accessor, IPluginConfig config) {
if (Waila.CONFIG.get().getGeneral().shouldDisplayModName())
if (config.get(PluginCore.CONFIG_SHOW_MOD_NAME))
((ITaggableList<Identifier, Text>) tooltip).setTag(HUDHandlerBlocks.MOD_NAME_TAG, new LiteralText(String.format(Waila.CONFIG.get().getFormatting().getModName(), ModIdentification.getModInfo(accessor.getEntity()).getName())));
}

Expand Down
15 changes: 13 additions & 2 deletions src/main/java/mcp/mobius/waila/addons/core/PluginCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.block.Block;
import net.minecraft.block.FluidBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.decoration.AbstractDecorationEntity;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
Expand All @@ -18,8 +19,13 @@ public class PluginCore implements IWailaPlugin {

static final Identifier RENDER_ENTITY_HEALTH = new Identifier(Waila.MODID, "render_health");

static final Identifier CONFIG_SHOW_REGISTRY = new Identifier(Waila.MODID, "show_registry");
public static final Identifier CONFIG_SHOW_BLOCK = new Identifier(Waila.MODID, "show_blocks");
public static final Identifier CONFIG_SHOW_FLUID = new Identifier(Waila.MODID, "show_fluids");
public static final Identifier CONFIG_SHOW_ENTITY = new Identifier(Waila.MODID, "show_entities");
public static final Identifier CONFIG_SHOW_ITEM = new Identifier(Waila.MODID, "show_item");

static final Identifier CONFIG_SHOW_MOD_NAME = new Identifier(Waila.MODID, "show_mod_name");
static final Identifier CONFIG_SHOW_REGISTRY = new Identifier(Waila.MODID, "show_registry");
static final Identifier CONFIG_SHOW_ENTITY_HEALTH = new Identifier(Waila.MODID, "show_entity_hp");
static final Identifier CONFIG_SHOW_STATES = new Identifier(Waila.MODID, "show_states");

Expand All @@ -43,9 +49,14 @@ public void register(IRegistrar registrar) {
registrar.registerComponentProvider(HUDHandlerEntities.INSTANCE, TooltipPosition.TAIL, AbstractDecorationEntity.class);
registrar.registerComponentProvider(HUDHandlerEntities.INSTANCE, TooltipPosition.TAIL, AbstractMinecartEntity.class);
registrar.registerComponentProvider(HUDHandlerEntities.INSTANCE, TooltipPosition.TAIL, BoatEntity.class);
registrar.registerComponentProvider(HUDHandlerEntities.INSTANCE, TooltipPosition.TAIL, FallingBlockEntity.class);

registrar.addConfig(CONFIG_SHOW_REGISTRY, false);
registrar.addConfig(CONFIG_SHOW_BLOCK, true);
registrar.addConfig(CONFIG_SHOW_FLUID, false);
registrar.addConfig(CONFIG_SHOW_ENTITY, true);
registrar.addConfig(CONFIG_SHOW_ITEM, true);
registrar.addConfig(CONFIG_SHOW_MOD_NAME, true);
registrar.addConfig(CONFIG_SHOW_REGISTRY, false);
registrar.addConfig(CONFIG_SHOW_ENTITY_HEALTH, true);
registrar.addConfig(CONFIG_SHOW_STATES, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import mcp.mobius.waila.api.IEntityComponentProvider;
import mcp.mobius.waila.api.IPluginConfig;
import mcp.mobius.waila.api.ITaggableList;
import mcp.mobius.waila.utils.ModIdentification;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
Expand All @@ -23,7 +22,6 @@ public class HUDHandlerFallingBlock implements IEntityComponentProvider {

static final Identifier OBJECT_NAME_TAG = new Identifier(Waila.MODID, "object_name");
static final Identifier REGISTRY_NAME_TAG = new Identifier(Waila.MODID, "registry_name");
static final Identifier MOD_NAME_TAG = new Identifier(Waila.MODID, "mod_name");
static final Identifier CONFIG_SHOW_REGISTRY = new Identifier(Waila.MODID, "show_registry");

@Override
Expand All @@ -40,10 +38,4 @@ public void appendHead(List<Text> tooltip, IEntityAccessor accessor, IPluginConf
((ITaggableList<Identifier, Text>) tooltip).setTag(REGISTRY_NAME_TAG, new LiteralText(Registry.ENTITY_TYPE.getId(accessor.getEntity().getType()).toString()).setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
}

@Override
public void appendTail(List<Text> tooltip, IEntityAccessor accessor, IPluginConfig config) {
if (Waila.CONFIG.get().getGeneral().shouldDisplayModName())
((ITaggableList<Identifier, Text>) tooltip).setTag(MOD_NAME_TAG, new LiteralText(String.format(Waila.CONFIG.get().getFormatting().getModName(), ModIdentification.getModInfo(accessor.getEntity()).getName())));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public void register(IRegistrar registrar) {
registrar.registerBlockDataProvider(HUDHandlerVanilla.INSTANCE, JukeboxBlockEntity.class);

registrar.registerComponentProvider(HUDHandlerFallingBlock.INSTANCE, TooltipPosition.HEAD, FallingBlockEntity.class);
registrar.registerComponentProvider(HUDHandlerFallingBlock.INSTANCE, TooltipPosition.TAIL, FallingBlockEntity.class);
registrar.registerEntityStackProvider(HUDHandlerFallingBlock.INSTANCE, FallingBlockEntity.class);

registrar.registerEntityStackProvider(HUDHandlerEntityIcon.INSTANCE, AbstractMinecartEntity.class);
Expand Down
21 changes: 2 additions & 19 deletions src/main/java/mcp/mobius/waila/api/event/WailaRenderEvent.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package mcp.mobius.waila.api.event;

import java.awt.Rectangle;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Method;

import com.mojang.blaze3d.platform.GlStateManager;
import mcp.mobius.waila.api.ICommonAccessor;
import mcp.mobius.waila.overlay.OverlayRenderer;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

Expand All @@ -20,17 +18,12 @@
*/
public class WailaRenderEvent {

private static MethodHandle loadGlState_;
public static final Event<PreRender> WAILA_RENDER_PRE = EventFactory.createArrayBacked(PreRender.class,
listeners -> event -> {
for (PreRender listener : listeners) {
if (listener.onPreRender(event)) {
GlStateManager.enableRescaleNormal();
try {
loadGlState_.invoke();
} catch (Throwable e) {
// No-op
}
OverlayRenderer.loadGLState();
GlStateManager.enableDepthTest();
GlStateManager.popMatrix();
return true;
Expand All @@ -47,16 +40,6 @@ public class WailaRenderEvent {
}
);

static {
try {
Class overlayRenderer = Class.forName("mcp.mobius.waila.overlay.OverlayRenderer");
Method method = overlayRenderer.getMethod("loadGLState");
loadGlState_ = MethodHandles.lookup().unreflect(method);
} catch (Exception e) {
e.printStackTrace();
}
}

public interface PreRender {

boolean onPreRender(Pre event);
Expand Down
46 changes: 27 additions & 19 deletions src/main/java/mcp/mobius/waila/api/impl/WailaRegistrar.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package mcp.mobius.waila.api.impl;

import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import mcp.mobius.waila.api.IBlockDecorator;
import mcp.mobius.waila.api.IComponentProvider;
import mcp.mobius.waila.api.IEntityComponentProvider;
Expand All @@ -34,25 +34,29 @@ public class WailaRegistrar implements IRegistrar {
final EnumMap<TooltipPosition, Map<Class, List<IEntityComponentProvider>>> entityComponentProviders;
final Map<Class, List<IServerDataProvider<LivingEntity>>> entityDataProviders;

final Map<Object, Map<Class, Map<Integer, ?>>> providers;

final Map<Class, List<IBlockDecorator>> blockDecorators;
final Map<Identifier, ITooltipRenderer> tooltipRenderers;

WailaRegistrar() {
blockStackProviders = Maps.newLinkedHashMap();
blockStackProviders = new Object2ObjectLinkedOpenHashMap<>();
blockComponentProviders = new EnumMap<>(TooltipPosition.class);
blockDataProviders = Maps.newLinkedHashMap();
blockDataProviders = new Object2ObjectLinkedOpenHashMap<>();

entityOverrideProviders = Maps.newLinkedHashMap();
entityStackProviders = Maps.newLinkedHashMap();
entityOverrideProviders = new Object2ObjectLinkedOpenHashMap<>();
entityStackProviders = new Object2ObjectLinkedOpenHashMap<>();
entityComponentProviders = new EnumMap<>(TooltipPosition.class);
entityDataProviders = Maps.newLinkedHashMap();
entityDataProviders = new Object2ObjectLinkedOpenHashMap<>();

providers = new Object2ObjectOpenHashMap<>();

blockDecorators = Maps.newLinkedHashMap();
tooltipRenderers = Maps.newLinkedHashMap();
blockDecorators = new Object2ObjectLinkedOpenHashMap<>();
tooltipRenderers = new Object2ObjectLinkedOpenHashMap<>();

for (TooltipPosition position : TooltipPosition.values()) {
blockComponentProviders.put(position, new LinkedHashMap<>());
entityComponentProviders.put(position, new LinkedHashMap<>());
blockComponentProviders.put(position, new Object2ObjectLinkedOpenHashMap<>());
entityComponentProviders.put(position, new Object2ObjectLinkedOpenHashMap<>());
}
}

Expand Down Expand Up @@ -181,17 +185,21 @@ public ITooltipRenderer getTooltipRenderer(Identifier id) {
}

private <T> Map<Integer, List<T>> getProviders(Object obj, Map<Class, List<T>> target) {
Map<Integer, List<T>> returnList = new TreeMap<>();
Integer index = 0;
return (Map<Integer, List<T>>) providers
.computeIfAbsent(target, m -> new Object2ObjectOpenHashMap<>())
.computeIfAbsent(obj.getClass(), o -> {
Map<Integer, List<T>> returnList = new TreeMap<>();
Integer index = 0;

for (Class clazz : target.keySet()) {
if (clazz.isInstance(obj))
returnList.put(index, target.get(clazz));
for (Class clazz : target.keySet()) {
if (clazz.isAssignableFrom(o))
returnList.put(index, target.get(clazz));

index++;
}
index++;
}

return returnList;
return returnList;
});
}

/* HAS METHODS */
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/mcp/mobius/waila/api/impl/config/WailaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@ public static class ConfigGeneral {
private DisplayMode displayMode = DisplayMode.TOGGLE;
private boolean hideFromPlayerList = true;
private boolean hideFromDebug = true;
private boolean showItem = true;
private boolean enableTextToSpeech = false;
private int maxHealthForRender = 40;
private int maxHeartsPerLine = 10;
private boolean displayFluids = false;
private boolean displayModName = true;

public void setDisplayTooltip(boolean displayTooltip) {
this.displayTooltip = displayTooltip;
Expand All @@ -67,10 +64,6 @@ public void setHideFromDebug(boolean hideFromDebug) {
this.hideFromDebug = hideFromDebug;
}

public void setShowItem(boolean showItem) {
this.showItem = showItem;
}

public void setEnableTextToSpeech(boolean enableTextToSpeech) {
this.enableTextToSpeech = enableTextToSpeech;
}
Expand All @@ -83,14 +76,6 @@ public void setMaxHeartsPerLine(int maxHeartsPerLine) {
this.maxHeartsPerLine = maxHeartsPerLine;
}

public void setDisplayFluids(boolean displayFluids) {
this.displayFluids = displayFluids;
}

public void setDisplayModName(boolean displayModName) {
this.displayModName = displayModName;
}

public boolean shouldDisplayTooltip() {
return displayTooltip;
}
Expand All @@ -111,10 +96,6 @@ public boolean shouldHideFromDebug() {
return hideFromDebug;
}

public boolean shouldShowItem() {
return showItem;
}

public boolean shouldEnableTextToSpeech() {
return enableTextToSpeech;
}
Expand All @@ -127,14 +108,6 @@ public int getMaxHeartsPerLine() {
return maxHeartsPerLine;
}

public boolean shouldDisplayFluids() {
return displayFluids;
}

public boolean shouldDisplayModName() {
return displayModName;
}

}

public static class ConfigOverlay {
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/mcp/mobius/waila/gui/GuiConfigWaila.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ public OptionsListWidget getOptions() {
.withBoolean("config.waila.display_tooltip",
config().getGeneral().shouldDisplayTooltip(),
val -> config().getGeneral().setDisplayTooltip(val))
.withBoolean("config.waila.display_fluids",
config().getGeneral().shouldDisplayFluids(),
val -> config().getGeneral().setDisplayFluids(val))
.withBoolean("config.waila.display_mod_name",
config().getGeneral().shouldDisplayModName(),
val -> config().getGeneral().setDisplayModName(val))
.withBoolean("config.waila.sneaky_details",
config().getGeneral().shouldShiftForDetails(),
val -> config().getGeneral().setShiftForDetails(val))
Expand All @@ -48,12 +42,17 @@ public OptionsListWidget getOptions() {
.withBoolean("config.waila.hide_from_debug",
config().getGeneral().shouldHideFromDebug(),
val -> config().getGeneral().setHideFromDebug(val))
.withBoolean("config.waila.display_item",
config().getGeneral().shouldShowItem(),
val -> config().getGeneral().setShowItem(val))
.withBoolean("config.waila.tts",
config().getGeneral().shouldEnableTextToSpeech(),
val -> config().getGeneral().setEnableTextToSpeech(val));
val -> config().getGeneral().setEnableTextToSpeech(val))
.withInput("config.waila.max_health_for_render",
config().getGeneral().getMaxHealthForRender(),
val -> config().getGeneral().setMaxHealthForRender(val),
OptionsEntryValueInput.INTEGER)
.withInput("config.waila.max_hearts_per_line",
config().getGeneral().getMaxHeartsPerLine(),
val -> config().getGeneral().setMaxHeartsPerLine(val),
OptionsEntryValueInput.INTEGER);
}
}))
.withButton("config.waila.overlay", 100, 20, w -> client.openScreen(new GuiOptions(this, new TranslatableText("config.waila.overlay")) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/mcp/mobius/waila/overlay/DisplayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class DisplayUtil {
private static final String[] NUM_SUFFIXES = new String[]{"", "k", "m", "b", "t"};
private static final int MAX_LENGTH = 4;
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static final DecimalFormat SHORT_HAND = new DecimalFormat("##0E0");
private static final LiteralText UNNAMED = new LiteralText("Unnamed");

public static void renderStack(MatrixStack matrices, int x, int y, ItemStack stack) {
enable3DRender();
Expand Down Expand Up @@ -62,7 +64,7 @@ public static void renderStackSize(MatrixStack matrices, TextRenderer fr, ItemSt
}

private static String shortHandNumber(Number number) {
String shorthand = new DecimalFormat("##0E0").format(number);
String shorthand = SHORT_HAND.format(number);
shorthand = shorthand.replaceAll("E[0-9]", NUM_SUFFIXES[Character.getNumericValue(shorthand.charAt(shorthand.length() - 1)) / 3]);
while (shorthand.length() > MAX_LENGTH || shorthand.matches("[0-9]+\\.[a-z]"))
shorthand = shorthand.substring(0, shorthand.length() - 2) + shorthand.substring(shorthand.length() - 1);
Expand Down Expand Up @@ -135,7 +137,7 @@ public static List<Text> itemDisplayNameMultiline(ItemStack itemstack) {
namelist = new ArrayList<>();

if (namelist.isEmpty())
namelist.add(new LiteralText("Unnamed"));
namelist.add(UNNAMED);

namelist.set(0, new LiteralText(itemstack.getRarity().formatting.toString() + namelist.get(0)));
for (int i = 1; i < namelist.size(); i++)
Expand Down
Loading

0 comments on commit 4763a6c

Please sign in to comment.