Skip to content

Commit

Permalink
fix compatability with 1.16.5+ + fix multiversion text on some versions
Browse files Browse the repository at this point in the history
fixes #9
  • Loading branch information
Mia committed Feb 5, 2025
1 parent 8772375 commit 9ddf1a9
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 38 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<img src="/assets/logo.png" width="160px" align="right"/>

![Modrinth Version](https://img.shields.io/modrinth/v/rEeBGDR0)
<a href="https://modrinth.com/mod/player-visibility"><img src="https://img.shields.io/modrinth/dt/rEeBGDR0?logo=modrinth" alt="Modrinth Downloads"/></a>
<a href="https://modrinth.com/mod/player-visibility"><img src="https://img.shields.io/modrinth/dt/rEeBGDR0?logo=modrinth&color=07a85c" alt="Modrinth Downloads"/></a>
<a href="https://www.curseforge.com/minecraft/mc-mods/player-visibility"><img src="https://img.shields.io/curseforge/dt/890962?logo=curseforge&color=f16436"/></a>

Hide players easily! PlayerVisibility is a fabric mod for Minecraft to hide other players and entities at a press of a key!

Expand Down
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ allprojects {
subprojects {
version = project.mod_version
group = project.maven_group

tasks.withType(JavaCompile).configureEach {
it.options.release = 12
}
}
6 changes: 4 additions & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ publishing {
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 8
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;

public class Text {
private static final MethodHandles.Lookup lookup = MethodHandles.lookup();
Expand All @@ -19,9 +20,9 @@ public static Object translatable(String key, Object... args) {
} catch (Throwable e) {
try {
Class<?> translatableTextClass = Class.forName("net.minecraft.class_2588");
MethodType methodType = MethodType.methodType(void.class, String.class, Object[].class);
MethodHandle constructor = lookup.findConstructor(translatableTextClass, methodType);
return constructor.invoke(key, args);
Constructor<?> translatableTextCtor = translatableTextClass.getConstructor(String.class, Object[].class);

return translatableTextCtor.newInstance(key, args);
} catch (Throwable e2) {
LOGGER.error("Couldn't create translatable text for {}", key, e2);
}
Expand All @@ -38,9 +39,17 @@ public static Object translatable(String key) {
} catch (Throwable e) {
try {
Class<?> translatableTextClass = Class.forName("net.minecraft.class_2588");
MethodType methodType = MethodType.methodType(void.class, String.class);
MethodHandle constructor = lookup.findConstructor(translatableTextClass, methodType);
return constructor.invoke(key);

try {
MethodType ctorType = MethodType.methodType(void.class, String.class);
MethodHandle ctorMethod = lookup.findConstructor(translatableTextClass, ctorType);
return ctorMethod.invoke(key);
} catch (Throwable ignored) {
}

MethodType ctorType = MethodType.methodType(void.class, String.class, Object[].class);
MethodHandle ctorMethod = lookup.findConstructor(translatableTextClass, ctorType);
return ctorMethod.invoke(key, new Object[0]);
} catch (Throwable e2) {
LOGGER.error("Couldn't create translatable text for {}", key, e2);
}
Expand All @@ -62,14 +71,15 @@ public static Object of(String text) {
MethodHandle ofMethod = lookup.findStatic(textClass, "method_30163", methodType);
return ofMethod.invoke(text);
} catch (Throwable e2) {
// try {
// Class<?> textClass = Class.forName("net.minecraft.class_2585");
// MethodType methodType = MethodType.methodType(void.class, new Class[]{String.class});
// MethodHandle constructor = lookup.findConstructor(textClass, methodType);
// return constructor.invoke(text);
// } catch (Throwable e3) {
LOGGER.error("Couldn't create literal text for {}", text, e2);
// }
try {
Class<?> literalTextClass = Class.forName("net.minecraft.class_2585");
MethodType ctorType = MethodType.methodType(void.class, String.class);
MethodHandle ctorMethod = lookup.findConstructor(literalTextClass, ctorType);

return ctorMethod.invoke(text);
} catch (Throwable e3) {
LOGGER.error("Couldn't create literal text for {}", text, e3);
}
}
}
throw new IllegalStateException(String.format("Text.of class couldn't be found for %s", VersionMixinPlugin.getMinecraftVersion()));
Expand Down
8 changes: 1 addition & 7 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,8 @@ processResources {
}
}

tasks.withType(JavaCompile).configureEach {
it.options.release = 12
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(12)
languageVersion = JavaLanguageVersion.of(8)
}
sourceCompatibility = JavaVersion.VERSION_12
targetCompatibility = JavaVersion.VERSION_12
}
2 changes: 1 addition & 1 deletion fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rg.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
# check these on https://fabricmc.net/develop
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.10
loader_version=0.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.MutableText;

import org.lwjgl.glfw.GLFW;

Expand Down Expand Up @@ -108,7 +107,7 @@ public static boolean shouldHideEntityRenderState(Object entity) {
nameField.setAccessible(true); // not sure if it's necessary also I'm not sure if I'm stupid but this SHOULD be okay????

Object textName = nameField.get(entity);
if (textName instanceof MutableText) {
if (textName instanceof net.minecraft.text.Text) {
playerUsername = ((net.minecraft.text.Text) textName).getString();
}

Expand Down Expand Up @@ -169,10 +168,20 @@ public static <E extends Entity> boolean shouldHideEntity(E entity) {
}

public static void sendMessage(Object text) {
if (text instanceof MutableText) {
try {
if (Class.forName("net.minecraft.class_5250").isAssignableFrom(text.getClass())) { // MutableText
sendMessage(((net.minecraft.text.Text) text).getString());
return;
}
} catch (Throwable ignored) {
}
if (text instanceof net.minecraft.text.Text) {
sendMessage(((net.minecraft.text.Text) text).getString());
} else if (text instanceof String) {
return;
}
if (text instanceof String) {
sendMessage(text);
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;

import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

Expand All @@ -26,7 +27,9 @@ public abstract class EntityMixinv115m1211 {
private <E extends Entity> void wrapRender(E entity, double x, double y, double z, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, Operation<Void> original) {
transparency.put(entity, -1);

if (ModConfig.hidePlayers && PlayerVisibility.shouldHideEntity(entity)) {
boolean shouldHide = (entity instanceof PlayerEntity && ModConfig.hidePlayers) || (!(entity instanceof PlayerEntity) && ModConfig.hideEntities);

if (shouldHide && PlayerVisibility.shouldHideEntity(entity)) {
if (ModConfig.comfortZone) {
double sqDst = this.getSquaredDistanceToCamera(entity);
double distance = Math.sqrt(sqDst);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;

import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

Expand All @@ -26,7 +27,9 @@ public abstract class EntityMixinv1212 {
private <E extends Entity> void wrapRender(E entity, double x, double y, double z, float yaw, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, Operation<Void> original) {
transparency.put(entity, -1);

if (ModConfig.hidePlayers && PlayerVisibility.shouldHideEntity(entity)) {
boolean shouldHide = (entity instanceof PlayerEntity && ModConfig.hidePlayers) || (!(entity instanceof PlayerEntity) && ModConfig.hideEntities);

if (shouldHide && PlayerVisibility.shouldHideEntity(entity)) {
if (ModConfig.comfortZone) {
double sqDst = this.getSquaredDistanceToCamera(entity);
double distance = Math.sqrt(sqDst);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ public TransparentVertexConsumer(VertexConsumer parent, E entity) {
try {
vertexFFF = parent.getClass().getMethod("method_22912", float.class, float.class, float.class);
} catch (Throwable ignored) {
PlayerVisibilityClient.LOGGER.error("No vertexFFF", ignored);
}
try {
overlayII = parent.getClass().getMethod("method_60796", int.class, int.class);
} catch (Throwable ignored) {
PlayerVisibilityClient.LOGGER.error("No overlayII", ignored);
}
}

Expand Down
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"depends": {
"fabricloader": ">=0.16.0",
"fabric": "*",
"minecraft": ">=1.15",
"minecraft": ">=1.16.5",
"java": ">=7"
},
"suggests": {
Expand Down

0 comments on commit 9ddf1a9

Please sign in to comment.