Skip to content

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jul 12, 2024
1 parent 799ff43 commit fea04b0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 67 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
maven-group = "band.kessokuteatime"
archives-name = "ivespoken"
mod = "2.1.0"
mod = "2.2.0"
loader = "fabric"

minecraft = "1.21"
Expand All @@ -22,7 +22,7 @@ id-curseforge = "998412"
# display
display-name = "I've Spoken"
display-loader = "Fabric"
display-version = "1.20.x"
display-version = "1.21+"

[libraries]
minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" }
Expand Down
61 changes: 3 additions & 58 deletions src/main/java/band/kessokuteatime/ivespoken/IveSpoken.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package band.kessokuteatime.ivespoken;

import band.kessokuteatime.nightautoconfig.config.base.ConfigType;
import com.google.common.collect.ImmutableMap;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigHolder;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import band.kessokuteatime.ivespoken.config.IveSpokenConfig;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.EntityAttachmentType;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,7 +25,7 @@ public class IveSpoken implements ClientModInitializer {
private static final HashMap<UUID, StampedMessage> dialogs = new HashMap<>();

static {
AutoConfig.register(IveSpokenConfig.class, Toml4jConfigSerializer::new);
AutoConfig.register(IveSpokenConfig.class, ConfigType.DEFAULT_COMMENTED::fileWatcherSerializer);
CONFIG = AutoConfig.getConfigHolder(IveSpokenConfig.class);
}

Expand All @@ -44,10 +37,6 @@ public static ImmutableMap<UUID, StampedMessage> dialogs() {
return ImmutableMap.copyOf(dialogs);
}

public static MutableText translatable(String category, String... paths) {
return Text.translatable(category + "." + ID + "." + String.join(".", paths));
}

public static void add(UUID uuid, Text message) {
dialogs.put(uuid, new StampedMessage(System.currentTimeMillis(), message));
}
Expand All @@ -65,13 +54,6 @@ public static void refresh() {
return dialogs().get(uuid);
}

public static long timestamp(UUID uuid) {
@Nullable StampedMessage message = message(uuid);
if (message == null) return 0;

return message.timestamp();
}

public static @Nullable Text dialog(UUID uuid) {
@Nullable StampedMessage message = message(uuid);
if (message == null) return null;
Expand All @@ -92,43 +74,6 @@ public static long timestamp(UUID uuid) {
builder.append(c);
}

return Text.literal(builder.toString())
.setStyle(content.getStyle().withColor(Formatting.GRAY));
}

public static void renderDialog(AbstractClientPlayerEntity player, MatrixStack matrixStack, VertexConsumerProvider vertexConsumers, int light, float tickDelta) {
@Nullable Text dialog = dialog(player.getUuid());
if (dialog == null) return;

boolean sneaky = !player.isSneaky();
Vec3d pos = player.getAttachments().getPointNullable(EntityAttachmentType.NAME_TAG, 0, player.getYaw(tickDelta));
if (pos != null) {
int y = (player.getName().getString().equals("deadmau5") ? -10 : 0) - 10;

matrixStack.push();
matrixStack.translate(0, pos.getY() + 0.5, 0);
matrixStack.multiply(MinecraftClient.getInstance().getEntityRenderDispatcher().getRotation());
matrixStack.scale(-0.025F, -0.025F, 0.025F);
Matrix4f matrix4f = matrixStack.peek().getPositionMatrix();

int backgroundColor = (int) (MinecraftClient.getInstance().options.getTextBackgroundOpacity(0.25F) * 255.0F) << 24;
float x = (float) -MinecraftClient.getInstance().textRenderer.getWidth(dialog) / 2;

MinecraftClient.getInstance().textRenderer.draw(
dialog, x, y, 0x20FFFFFF, false, matrix4f, vertexConsumers,
sneaky ? TextRenderer.TextLayerType.SEE_THROUGH : TextRenderer.TextLayerType.NORMAL,
backgroundColor, light
);

if (sneaky) {
MinecraftClient.getInstance().textRenderer.draw(
dialog, x, y, 0xFFFFFFFF, false, matrix4f, vertexConsumers,
TextRenderer.TextLayerType.NORMAL,
0, light
);
}

matrixStack.pop();
}
return Text.literal(builder.toString()).setStyle(content.getStyle().withColor(Formatting.GRAY));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
package band.kessokuteatime.ivespoken.config;

import com.electronwill.nightconfig.core.serde.annotations.SerdeComment;
import com.electronwill.nightconfig.core.serde.annotations.SerdeDefault;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;

import java.util.function.Supplier;

@Config(name = "ivespoken")
public class IveSpokenConfig implements ConfigData {
public boolean enabled = true;
@ConfigEntry.Gui.Excluded
private transient final Supplier<Boolean> enabledProvider = () -> true;

@SerdeDefault(provider = "enabledSupplier")
public boolean enabled = enabledProvider.get();

@ConfigEntry.Gui.Excluded
private transient final Supplier<Long> lastingTimerProvider = () -> 1000L * 5;

@SerdeDefault(provider = "enabledSupplier")
@SerdeComment(" The time in milliseconds that the message will be displayed on the screen.")
@SerdeComment(" Max value: 60000 milliseconds (1 minute)")
@ConfigEntry.BoundedDiscrete(max = 1000 * 60)
public long lastingTime = 1000 * 5;
public long lastingTime = lastingTimerProvider.get();

@ConfigEntry.Gui.Excluded
private transient final Supplier<Integer> maxWidthProvider = () -> 180;

@ConfigEntry.BoundedDiscrete(max = 1000)
public int maxWidth = 180;
@SerdeComment(" The maximum width of the message on the screen in pixel.")
@SerdeComment(" Min value: 100 pixels")
@SerdeComment(" Max value: 1000 pixels")
@ConfigEntry.BoundedDiscrete(min = 100,max = 1000)
public int maxWidth = maxWidthProvider.get();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package band.kessokuteatime.ivespoken.mixin;

import band.kessokuteatime.ivespoken.IveSpoken;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.network.message.MessageSignatureData;
Expand All @@ -17,7 +18,10 @@ public class ChatTracker {
at = @At("HEAD")
)
private void addMessage(Text message, MessageSignatureData signature, MessageIndicator indicator, CallbackInfo ci) {
IveSpoken.LOGGER.info("Message received: {}", message);
if (FabricLoader.getInstance().isDevelopmentEnvironment()) {
IveSpoken.LOGGER.info("Message received: {}", message);
}

TextContent textContent = message.getContent();
if (textContent instanceof TranslatableTextContent translatableTextContent) {
Object[] args = translatableTextContent.getArgs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(PlayerEntityRenderer.class)
Expand All @@ -24,15 +26,21 @@ protected DialogRenderer(EntityRendererFactory.Context ctx) {
method = "renderLabelIfPresent*",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/math/MatrixStack;pop()V"
target = "Lnet/minecraft/client/util/math/MatrixStack;pop()V",
shift = At.Shift.BEFORE
)
)
private void renderDialog(AbstractClientPlayerEntity player, Text text, MatrixStack matrixStack, VertexConsumerProvider vertexConsumers, int light, float tickDelta, CallbackInfo ci) {
if (!IveSpoken.CONFIG.get().enabled) return;

@Nullable Text dialog = IveSpoken.dialog(player.getUuid());
if (dialog == null) return;

double distance = this.dispatcher.getSquaredDistanceToCamera(player);
if (distance > 4096) return;

IveSpoken.renderDialog(player, matrixStack, vertexConsumers, light, tickDelta);
matrixStack.translate(0.0F, 9.0F * 1.15F * 0.025F, 0.0F);

super.renderLabelIfPresent(player, dialog, matrixStack, vertexConsumers, light, tickDelta);
}
}

0 comments on commit fea04b0

Please sign in to comment.