Skip to content

Commit

Permalink
fix nametag checks & move to mdg for neo & vanilla
Browse files Browse the repository at this point in the history
  • Loading branch information
Uraneptus committed Jan 3, 2025
1 parent 40ed94f commit 8b90338
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 55 deletions.
46 changes: 32 additions & 14 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
plugins {
id 'java-library'
id 'idea'
id 'net.neoforged.gradle.userdev' version '7.0.165'
id 'net.neoforged.moddev' version '2.0.72'
id 'eclipse'
}

version = "${project.mc_version}-${project.build_number}-NEOFORGE"

def accesstransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
if (accesstransformer.exists()) {
minecraft.accessTransformers.file accesstransformer
}
neoForge {
version = project.neoforge_version
validateAccessTransformers = true
accessTransformers = project.files('src/main/resources/META-INF/accesstransformer.cfg')

runs {
configureEach {
workingDirectory project.file('../run')
systemProperty 'forge.logging.console.level', 'debug'
modSource project.sourceSets.main
parchment {
mappingsVersion = project.mapping_version
minecraftVersion = project.mc_version
}

client {
runs {
configureEach {
gameDirectory = project.file('../run')
systemProperty 'forge.logging.markers', 'REGISTRIES'
logLevel = org.slf4j.event.Level.DEBUG
}
client {
client()
}
data {
clientData()
}
server {
server()
programArgument '--nogui'
}
}

server {
programArgument '--nogui'
mods {
// define mod <-> source bindings
// these are used to tell the game which sources are for which mod
// mostly optional in a single mod project
// but multi mod projects should define one per mod
"${mod_id}" {
sourceSet(project.sourceSets.main)
}
}
}

Expand All @@ -34,7 +53,6 @@ repositories {
}

dependencies {
implementation "net.neoforged:neoforge:${neoforge_version}"
implementation project(":Xplat")
}

Expand Down
31 changes: 23 additions & 8 deletions Xplat/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
plugins {
id('java')
// Unfortunately, VG has not published a new non-SNAPSHOT version since 2021.
// This may break if this snapshot gets garbage-collected. In that case, visit
// https://repo.spongepowered.org/service/rest/repository/browse/maven-public/org/spongepowered/vanillagradle/
// (or wherever their maven is now) and pick another snapshot version.
id('org.spongepowered.gradle.vanilla') version '0.2.1-20230603.203956-54'
id 'net.neoforged.moddev' version '2.0.72'
}

archivesBaseName = "${project.mod_name}-xplat"
version = "${project.mc_version}-${project.build_number}"

minecraft {
version(project.mc_version)
accessWideners 'src/main/resources/neat_xplat.accesswidener'
neoForge {
neoFormVersion = "1.21.4-20241203.161809"

validateAccessTransformers = true
accessTransformers = project.files('src/main/resources/META-INF/accesstransformer_xplat.cfg')

parchment {
mappingsVersion = project.mapping_version
minecraftVersion = project.mc_version
}

runs {
client {
client()
}
server {
server()
}
data {
clientData()
}
}
}

dependencies {
Expand Down
10 changes: 10 additions & 0 deletions Xplat/src/main/java/vazkii/neat/NeatRenderState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package vazkii.neat;

public interface NeatRenderState {
boolean neat$isBoss();
void neat$setBoss(boolean value);
boolean neat$isFriendly();
void neat$setFriendly(boolean value);
boolean neat$isIdBlacklisted();
void neat$setIdBlacklisted(boolean value);
}
2 changes: 1 addition & 1 deletion Xplat/src/main/java/vazkii/neat/NeatRenderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import net.minecraft.client.renderer.RenderStateShard;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;

import net.minecraft.util.TriState;

import vazkii.neat.mixin.AccessorRenderType;

import static com.mojang.blaze3d.vertex.DefaultVertexFormat.*;
Expand Down
47 changes: 22 additions & 25 deletions Xplat/src/main/java/vazkii/neat/mixin/EntityRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,48 @@
import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.state.EntityRenderState;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
import net.minecraft.client.renderer.entity.state.PlayerRenderState;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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;

import vazkii.neat.HealthBarRenderer;
import vazkii.neat.NeatConfig;
import vazkii.neat.NeatRenderState;

@Mixin(EntityRenderer.class)
public class EntityRendererMixin {

@Shadow @Final protected EntityRenderDispatcher entityRenderDispatcher;

@Inject(method = "render(Lnet/minecraft/client/renderer/entity/state/EntityRenderState;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/EntityRenderer;renderNameTag(Lnet/minecraft/client/renderer/entity/state/EntityRenderState;Lnet/minecraft/network/chat/Component;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V"), cancellable = true)
private void neat_disableNameTag(EntityRenderState renderState, PoseStack $$1, MultiBufferSource $$2, int $$3, CallbackInfo ci) {
if (NeatConfig.instance.disableNameTag() /*&& (!NeatConfig.instance.disableNameTagIfHealthbar() TODO || neat$allowNameTagDisable(renderState)))*/ ) {
if (NeatConfig.instance.disableNameTag() && (!NeatConfig.instance.disableNameTagIfHealthbar() || neat$allowNameTagDisable(renderState))) {
ci.cancel();
}
}

@Unique
public boolean neat$allowNameTagDisable(Entity entity) {
if (!(entity instanceof LivingEntity))
return false;
if (entity instanceof Player && !NeatConfig.instance.showOnPlayers())
return false;
if (HealthBarRenderer.isBoss(entity) && !NeatConfig.instance.showOnBosses())
return false;
if (entity.getType().getCategory().isFriendly() && !NeatConfig.instance.showOnPassive())
return false;
if ((!entity.getType().getCategory().isFriendly() && !HealthBarRenderer.isBoss(entity)) && !NeatConfig.instance.showOnHostile())
return false;

var id = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType());
return !NeatConfig.instance.blacklist().contains(id.toString()) && NeatConfig.draw;
public boolean neat$allowNameTagDisable(EntityRenderState renderState) {
if (renderState instanceof LivingEntityRenderState livingRenderState) {
if (renderState instanceof PlayerRenderState && !NeatConfig.instance.showOnPlayers()) {
return false;
}
if (((NeatRenderState) livingRenderState).neat$isBoss() && !NeatConfig.instance.showOnBosses()) {
return false;
}
if (((NeatRenderState) livingRenderState).neat$isFriendly() && !NeatConfig.instance.showOnPassive()) {
return false;
}
if ((!((NeatRenderState) livingRenderState).neat$isFriendly() && !((NeatRenderState) livingRenderState).neat$isBoss()) && !NeatConfig.instance.showOnHostile()) {
return false;
}
return !((NeatRenderState) livingRenderState).neat$isIdBlacklisted() && NeatConfig.draw;

}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package vazkii.neat.mixin;

import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

import vazkii.neat.NeatRenderState;

@Mixin(LivingEntityRenderState.class)
public class LivingEntityRenderStateMixin implements NeatRenderState {
@Unique
public boolean neat$isBoss;
@Unique
public boolean neat$isFriendly;
@Unique
public boolean neat$isIdBlacklisted;

@Override
public boolean neat$isBoss() {
return neat$isBoss;
}

@Override
public void neat$setBoss(boolean value) {
this.neat$isBoss = value;
}

@Override
public boolean neat$isFriendly() {
return neat$isFriendly;
}

@Override
public void neat$setFriendly(boolean value) {
this.neat$isFriendly = value;
}

@Override
public boolean neat$isIdBlacklisted() {
return neat$isIdBlacklisted;
}

@Override
public void neat$setIdBlacklisted(boolean value) {
this.neat$isIdBlacklisted = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package vazkii.neat.mixin;

import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.LivingEntity;

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.callback.CallbackInfo;

import vazkii.neat.HealthBarRenderer;
import vazkii.neat.NeatConfig;
import vazkii.neat.NeatRenderState;

@Mixin(LivingEntityRenderer.class)
public class LivingEntityRendererMixin {

@Inject(
method = "extractRenderState(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/client/renderer/entity/state/LivingEntityRenderState;F)V",
at = @At("TAIL")
)
public void neat$extractRenderState(LivingEntity entity, LivingEntityRenderState entityRenderState, float partialTick, CallbackInfo ci) {
((NeatRenderState) entityRenderState).neat$setBoss(HealthBarRenderer.isBoss(entity));
((NeatRenderState) entityRenderState).neat$setFriendly(entity.getType().getCategory().isFriendly());
((NeatRenderState) entityRenderState).neat$setIdBlacklisted(NeatConfig.instance.blacklist().contains(BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).toString()));
}
}
2 changes: 2 additions & 0 deletions Xplat/src/main/resources/META-INF/accesstransformer_xplat.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public net.minecraft.client.renderer.RenderType$CompositeRenderType
public net.minecraft.client.renderer.RenderType$CompositeState
2 changes: 2 additions & 0 deletions Xplat/src/main/resources/neat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"AccessorRenderType",
"EntityRendererMixin",
"LevelRendererMixin",
"LivingEntityRendererMixin",
"LivingEntityRenderStateMixin",
"MinecraftMixin"
],
"injectors": {
Expand Down
5 changes: 0 additions & 5 deletions Xplat/src/main/resources/neat_xplat.accesswidener

This file was deleted.

3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ org.gradle.jvmargs=-Xmx2G \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

group=vazkii.neat
neoforge_version=21.4.2-beta
neoforge_version=21.4.48-beta
fabric_loader_version=0.16.9
fabric_api_version=0.110.5+1.21.4
mod_id=neat
build_number=42
mod_name=Neat
mc_version=1.21.4
mapping_version=2024.12.29
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
}

rootProject.name = 'Neat'
Expand Down

0 comments on commit 8b90338

Please sign in to comment.