remove VillagerTradeOverlayRenderer and related configuration options
This commit is contained in:
@@ -5,7 +5,6 @@ import com.github.sebseb7.autotrade.event.InputHandler;
|
||||
import com.github.sebseb7.autotrade.event.KeybindCallbacks;
|
||||
import com.github.sebseb7.autotrade.gui.MerchantScreenButtonInjector;
|
||||
import com.github.sebseb7.autotrade.render.TraderHighlightRenderer;
|
||||
import com.github.sebseb7.autotrade.render.VillagerTradeOverlayRenderer;
|
||||
import fi.dy.masa.malilib.config.ConfigManager;
|
||||
import fi.dy.masa.malilib.config.options.ConfigString;
|
||||
import fi.dy.masa.malilib.event.InputEventHandler;
|
||||
@@ -31,7 +30,6 @@ public class InitHandler implements IInitializationHandler {
|
||||
ConfigManager.getInstance().registerConfigHandler(Reference.MOD_ID, new Configs());
|
||||
|
||||
TraderHighlightRenderer.register();
|
||||
VillagerTradeOverlayRenderer.register();
|
||||
MerchantScreenButtonInjector.register();
|
||||
|
||||
InputHandler handler = new InputHandler();
|
||||
|
||||
@@ -60,8 +60,7 @@ public class Configs implements IConfigHandler {
|
||||
"true: Start the delay after the villager was unloaded; false: Start the delay after the trade has been initiated");
|
||||
public static final ConfigInteger CONTAINER_CLOSE_DELAY = new ConfigInteger("containerCloseDelay", 0, 0,
|
||||
30000000, "delay in ticks; to get signal from trapped chest");
|
||||
public static final ConfigBoolean SHOW_TRADES = new ConfigBoolean("showTrades", true,
|
||||
"Display villager/wandering-trader trades above their heads (requires trading with them once to cache the offers)");
|
||||
|
||||
public static final ConfigString SELECTED_ENCHANTMENTS = new ConfigString("selectedEnchantments", "",
|
||||
"Comma-separated list of selected enchantment IDs (set via the \"Select Enchantments\" button on a librarian's trade screen)");
|
||||
|
||||
@@ -69,7 +68,7 @@ public class Configs implements IConfigHandler {
|
||||
ENABLE_SELL, SELL_ITEM, SELL_LIMIT, ENABLE_BUY, BUY_ITEM, BUY_LIMIT, MAX_INPUT_ITEMS,
|
||||
INPUT_CONTAINER_X, INPUT_CONTAINER_Y, INPUT_CONTAINER_Z, OUTPUT_CONTAINER_X, OUTPUT_CONTAINER_Y,
|
||||
OUTPUT_CONTAINER_Z, VOID_TRADING_DELAY, VOID_TRADING_DELAY_AFTER_TELEPORT, CONTAINER_CLOSE_DELAY,
|
||||
SHOW_TRADES, SELECTED_ENCHANTMENTS);
|
||||
SELECTED_ENCHANTMENTS);
|
||||
}
|
||||
|
||||
public static void loadFromFile() {
|
||||
|
||||
@@ -11,8 +11,7 @@ import net.minecraft.world.item.trading.MerchantOffers;
|
||||
*
|
||||
* <p>
|
||||
* Populated by {@code AutoTradeClientTick} when the mod opens a merchant
|
||||
* screen; consumed by {@link VillagerTradeOverlayRenderer} to draw trade labels
|
||||
* above each villager's head.
|
||||
* screen.
|
||||
*/
|
||||
public final class VillagerTradeCache {
|
||||
private static final Map<UUID, MerchantOffers> CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
package com.github.sebseb7.autotrade.render;
|
||||
|
||||
import com.github.sebseb7.autotrade.config.Configs;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
//? if mc26 {
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderContext;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.level.LevelRenderEvents;
|
||||
//?}
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
//? if mc26 {
|
||||
import net.minecraft.world.entity.npc.villager.Villager;
|
||||
import net.minecraft.world.entity.npc.wanderingtrader.WanderingTrader;
|
||||
//?}
|
||||
import net.minecraft.world.item.trading.MerchantOffer;
|
||||
import net.minecraft.world.item.trading.MerchantOffers;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Renders a compact summary of each villager's known trades above their head.
|
||||
*
|
||||
* <p>
|
||||
* Trade data comes from {@link VillagerTradeCache}, which is populated when the
|
||||
* mod opens a merchant screen. Villagers whose trades haven't been seen yet
|
||||
* show nothing.
|
||||
*/
|
||||
public final class VillagerTradeOverlayRenderer {
|
||||
|
||||
/** World-space scale of the text (vanilla name-tags use ~0.025). */
|
||||
private static final float TEXT_SCALE = 0.02F;
|
||||
|
||||
/** Text background colour (semi-transparent dark). */
|
||||
private static final int BG_COLOR = 0x80000000;
|
||||
|
||||
/** Normal trade text colour (white). */
|
||||
private static final int TEXT_COLOR = 0xFFFFFFFF;
|
||||
|
||||
/** Depleted trade text colour (grey/red). */
|
||||
private static final int DEPLETED_COLOR = 0xFFFF6666;
|
||||
|
||||
private VillagerTradeOverlayRenderer() {
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
//? if mc26 {
|
||||
LevelRenderEvents.COLLECT_SUBMITS.register(VillagerTradeOverlayRenderer::renderLevel);
|
||||
//?}
|
||||
}
|
||||
|
||||
//? if mc26 {
|
||||
private static void renderLevel(LevelRenderContext context) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.level == null || mc.player == null) {
|
||||
return;
|
||||
}
|
||||
if (!Configs.Generic.SHOW_TRADES.getBooleanValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Font font = mc.font;
|
||||
Vec3 camera = mc.gameRenderer.getMainCamera().position();
|
||||
float tickDelta = mc.getDeltaTracker().getGameTimeDeltaPartialTick(true);
|
||||
|
||||
for (Entity entity : mc.level.entitiesForRendering()) {
|
||||
if (!(entity instanceof Villager) && !(entity instanceof WanderingTrader)) {
|
||||
continue;
|
||||
}
|
||||
if (entity.distanceToSqr(mc.player) > 64.0 * 64.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MerchantOffers offers = VillagerTradeCache.get(entity.getUUID());
|
||||
if (offers == null || offers.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<TradeLineEntry> lines = buildTradeLines(offers);
|
||||
if (lines.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double x = Mth.lerp(tickDelta, entity.xOld, entity.getX()) - camera.x;
|
||||
double y = Mth.lerp(tickDelta, entity.yOld, entity.getY()) - camera.y;
|
||||
double z = Mth.lerp(tickDelta, entity.zOld, entity.getZ()) - camera.z;
|
||||
|
||||
float baseY = entity.getBbHeight() + 0.6F;
|
||||
|
||||
PoseStack poseStack = new PoseStack();
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(x, y + baseY, z);
|
||||
|
||||
poseStack.mulPose(mc.gameRenderer.getMainCamera().rotation());
|
||||
poseStack.scale(-TEXT_SCALE, -TEXT_SCALE, TEXT_SCALE);
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
TradeLineEntry entry = lines.get(i);
|
||||
float lineOffsetY = -(lines.size() - 1 - i) * (font.lineHeight + 2);
|
||||
|
||||
Matrix4f matrix = poseStack.last().pose();
|
||||
matrix = new Matrix4f(matrix);
|
||||
matrix.translate(0, lineOffsetY, 0);
|
||||
|
||||
int textWidth = font.width(entry.text);
|
||||
float textX = -textWidth / 2.0F;
|
||||
|
||||
context.submitNodeCollector().submitText(poseStack, textX, 0,
|
||||
net.minecraft.network.chat.Component.literal(entry.text).getVisualOrderText(), false,
|
||||
Font.DisplayMode.NORMAL, entry.color, 0xF000F0, BG_COLOR, 0);
|
||||
}
|
||||
|
||||
poseStack.popPose();
|
||||
}
|
||||
}
|
||||
|
||||
//?}
|
||||
|
||||
private static List<TradeLineEntry> buildTradeLines(MerchantOffers offers) {
|
||||
List<TradeLineEntry> lines = new ArrayList<>();
|
||||
for (int i = 0; i < offers.size(); i++) {
|
||||
MerchantOffer offer = offers.get(i);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (!offer.getCostA().isEmpty()) {
|
||||
sb.append(offer.getCostA().getCount()).append("× ").append(offer.getCostA().getHoverName().getString());
|
||||
}
|
||||
|
||||
if (!offer.getCostB().isEmpty()) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(" + ");
|
||||
}
|
||||
sb.append(offer.getCostB().getCount()).append("× ").append(offer.getCostB().getHoverName().getString());
|
||||
}
|
||||
|
||||
sb.append(" → ");
|
||||
|
||||
sb.append(offer.getResult().getCount()).append("× ").append(offer.getResult().getHoverName().getString());
|
||||
|
||||
int remaining = offer.getMaxUses() - offer.getUses();
|
||||
sb.append(" (").append(remaining).append("/").append(offer.getMaxUses()).append(")");
|
||||
|
||||
boolean depleted = remaining <= 0;
|
||||
lines.add(new TradeLineEntry(sb.toString(), depleted ? DEPLETED_COLOR : TEXT_COLOR));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private record TradeLineEntry(String text, int color) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user