Skip to content

Commit

Permalink
Resolved rendering issue that caused CTD
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Jul 3, 2024
1 parent 8fc407d commit 407e66f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 49 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
## ⚙️ Changes

- Brigadier Commands for `reset` & `reset_all` have been modified.
- They will reset the stats of the player regardless of the configuration.
- Thus, a new argument has been created called `retain`. It is applied to these commands, and is fully optional. It allows you to choose how much of a percentage of stats you want to keep for the provided player(s).
- Example: `/playerex reset <player_name> 50` will retain **50%** of the player's stats.
- Resolved rendering issue that caused a CTD on menu.
- Removed vanity color from the original author.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version=0.15.11
#Fabric api
fabric_version=0.92.1+1.20.1

mod_version = 3.7.2+1.20.1
mod_version = 3.7.3+1.20.1
maven_group = com.github.clevernucleus
archives_base_name = playerex

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.joml.Matrix4f;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -21,7 +22,6 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.scoreboard.AbstractTeam;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
Expand All @@ -36,41 +36,33 @@ private LivingEntityRendererMixin(EntityRendererFactory.Context ctx, M model, fl
}

// Custom method to check if the level nameplate should be rendered
private boolean playerex_shouldRenderLevel(T livingEntity) {
double d = this.dispatcher.getSquaredDistanceToCamera((Entity) livingEntity);
@Unique
private boolean playerex$shouldRenderLevel(T livingEntity) {
if (this.dispatcher.camera == null) return false;

double d = this.dispatcher.getSquaredDistanceToCamera(livingEntity);
float f = ((Entity) livingEntity).isSneaky() ? 32.0f : 64.0f;

if (d >= (double) (f * f))
return false;
MinecraftClient minecraftClient = MinecraftClient.getInstance();
ClientPlayerEntity clientPlayerEntity = minecraftClient.player;
boolean bl = !((Entity) livingEntity).isInvisibleTo(clientPlayerEntity);
boolean bl = !livingEntity.isInvisibleTo(clientPlayerEntity);

if (livingEntity != clientPlayerEntity) {
if (livingEntity != clientPlayerEntity && clientPlayerEntity != null) {
AbstractTeam abstractTeam = ((Entity) livingEntity).getScoreboardTeam();
AbstractTeam abstractTeam2 = clientPlayerEntity.getScoreboardTeam();

if (abstractTeam != null) {
AbstractTeam.VisibilityRule visibilityRule = abstractTeam.getNameTagVisibilityRule();

switch (visibilityRule) {
case ALWAYS: {
return bl;
}
case NEVER: {
return false;
}
case HIDE_FOR_OTHER_TEAMS: {
return abstractTeam2 == null ? bl
: abstractTeam.isEqual(abstractTeam2)
&& (abstractTeam.shouldShowFriendlyInvisibles() || bl);
}
case HIDE_FOR_OWN_TEAM: {
return abstractTeam2 == null ? bl : !abstractTeam.isEqual(abstractTeam2) && bl;
}
}

return true;
return switch (visibilityRule) {
case ALWAYS -> bl;
case NEVER -> false;
case HIDE_FOR_OTHER_TEAMS -> abstractTeam2 == null ? bl
: abstractTeam.isEqual(abstractTeam2)
&& (abstractTeam.shouldShowFriendlyInvisibles() || bl);
case HIDE_FOR_OWN_TEAM -> abstractTeam2 == null ? bl : !abstractTeam.isEqual(abstractTeam2) && bl;
};
}
}

Expand All @@ -79,8 +71,8 @@ private boolean playerex_shouldRenderLevel(T livingEntity) {
}

// Custom method to render the level nameplate
private void playerex_renderLevel(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers,
int light) {
@Unique
private void playerex$renderLevel(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
double d = this.dispatcher.getSquaredDistanceToCamera(entity);

if (!(d > 4096.0D)) {
Expand Down Expand Up @@ -111,24 +103,13 @@ private void playerex_renderLevel(T entity, Text text, MatrixStack matrices, Ver
}
}

// Inject code at the end of the render method
@Inject(method = "render", at = @At("TAIL"))
private void onRender(T livingEntity, float f, float g, MatrixStack matrixStack,
VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo info) {
// Check if the level nameplate should be rendered and the configuration allows
// it
if (this.playerex_shouldRenderLevel(livingEntity) && ((ConfigImpl) ExAPI.getConfig()).levelNameplate()) {
// Get the level value using DataAttributesAPI
DataAttributesAPI.ifPresent(livingEntity, ExAPI.LEVEL, (Object) null, value -> {
// Check if the entity is the player "CleverNucleus" (for special formatting)
boolean coder = (livingEntity instanceof PlayerEntity)
&& "CleverNucleus".equals(((PlayerEntity) livingEntity).getGameProfile().getName());
// Format the level as a Text object
Text tag = Text.translatable("playerex.gui.text.nameplate", String.valueOf(Math.round(value)))
.formatted(coder ? Formatting.GOLD : Formatting.WHITE);
// Render the level nameplate
this.playerex_renderLevel(livingEntity, tag, matrixStack, vertexConsumerProvider, i);
return (Object) null;
@Inject(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At("TAIL"))
private void playerex$onRender(T livingEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo info) {
if (this.playerex$shouldRenderLevel(livingEntity) && ((ConfigImpl) ExAPI.getConfig()).levelNameplate()) {
DataAttributesAPI.ifPresent(livingEntity, ExAPI.LEVEL, null, value -> {
Text tag = Text.translatable("playerex.gui.text.nameplate", String.valueOf(Math.round(value))).formatted(Formatting.WHITE);
this.playerex$renderLevel(livingEntity, tag, matrixStack, vertexConsumerProvider, i);
return null;
});
}
}
Expand Down

0 comments on commit 407e66f

Please sign in to comment.