Skip to content

Commit

Permalink
Update to 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
PotatoPresident committed Nov 20, 2024
1 parent d4b536e commit 37cbd29
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 63 deletions.
23 changes: 3 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
plugins {
id 'fabric-loom' version '1.6.+'
id 'fabric-loom' version '1.8.+'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version + "-" + project.minecraft_version + "+"
group = project.maven_group

Expand All @@ -22,21 +18,8 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API
Set<String> apiModules = [
"fabric-api-base",
"fabric-key-binding-api-v1",
"fabric-lifecycle-events-v1",
"fabric-resource-loader-v0", // MidnightLib
"fabric-screen-api-v1"
]

apiModules.forEach {
modImplementation include(fabricApi.module(it, project.fabric_version))
}

modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
modImplementation include("maven.modrinth:midnightlib:${project.midnightlib_version}")
include "maven.modrinth:midnightlib:${project.midnightlib_version}"

modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}", {
exclude module: "fabric-api"
Expand All @@ -53,7 +36,7 @@ processResources {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}

Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/develop/
minecraft_version=1.21
yarn_mappings=1.21+build.2
loader_version=0.15.11
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.9
# Mod Properties
mod_version=1.8.7
mod_version=1.8.8
maven_group=us.potatoboy
archives_base_name=PetOwner
# Dependencies
# check this on https://fabricmc.net/develop/
fabric_version=0.100.3+1.21
modmenu_version=11.0.0-rc.4
midnightlib_version=1.5.7-fabric
fabric_version=0.109.0+1.21.3
modmenu_version=12.0.0-beta.1
midnightlib_version=1.6.4-fabric
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
24 changes: 14 additions & 10 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/us/potatoboy/petowner/client/PetRenderState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package us.potatoboy.petowner.client;

import java.util.List;
import java.util.UUID;

public interface PetRenderState {
List<UUID> petOwner$getOwnerIds();
boolean petOwner$getHasPassenger();
boolean petOwner$getIsTargeted();

void petOwner$setOwnerIds(List<UUID> ownerIds);
void petOwner$setHasPassenger(boolean hasPassenger);
void petOwner$setIsTargeted(boolean isTargeted);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class PetOwnerConfig extends MidnightConfig {
@Entry public static KeybindMode keybindMode = KeybindMode.TOGGLE;
@Entry public static boolean alwaysShow = false;
@Entry public static boolean showKeybindMessage = false;
@Entry public static boolean showKeybindMessage = true;

public enum KeybindMode {
TOGGLE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package us.potatoboy.petowner.mixin;

import net.minecraft.client.render.entity.state.EntityRenderState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import us.potatoboy.petowner.client.PetRenderState;

import java.util.List;
import java.util.UUID;

@Mixin(EntityRenderState.class)
public abstract class EntityRenderStateMixin implements PetRenderState {
@Unique
public List<UUID> ownerIds;
@Unique
public boolean hasPassenger;
@Unique
public boolean isTargeted;

@Override
public List<UUID> petOwner$getOwnerIds() {
return ownerIds;
}

@Override
public boolean petOwner$getHasPassenger() {
return hasPassenger;
}

@Override
public boolean petOwner$getIsTargeted() {
return isTargeted;
}

@Override
public void petOwner$setOwnerIds(List<UUID> ownerIds) {
this.ownerIds = ownerIds;
}

@Override
public void petOwner$setHasPassenger(boolean hasPassenger) {
this.hasPassenger = hasPassenger;
}

@Override
public void petOwner$setIsTargeted(boolean isTargeted) {
this.isTargeted = isTargeted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.state.EntityRenderState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAttachmentType;
Expand All @@ -20,33 +21,36 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import us.potatoboy.petowner.client.PetOwnerClient;
import us.potatoboy.petowner.client.config.PetOwnerConfig;
import org.joml.Matrix4f;
import us.potatoboy.petowner.client.PetRenderState;
import us.potatoboy.petowner.client.config.PetOwnerConfig;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Mixin(EntityRenderer.class)
public abstract class OwnerNameTagRendering {
public abstract class OwnerNameTagRendering<T extends Entity, S extends EntityRenderState> {
@Final
@Shadow
protected EntityRenderDispatcher dispatcher;

@Shadow public abstract TextRenderer getTextRenderer();

@Inject(method = "render", at = @At("HEAD"))
private void render(Entity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
private void render(S state, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
PetRenderState petRenderState = (PetRenderState) state;

//If HUD is hidden
if (MinecraftClient.getInstance().options.hudHidden) return;
//If the player is riding the entity
if (entity.hasPassenger(MinecraftClient.getInstance().player)) return;
if (petRenderState.petOwner$getHasPassenger()) return;
//If the key is bound and owner is disabled
if (!PetOwnerClient.keyBinding.isUnbound() && !PetOwnerClient.enabled) return;
//If the entity is not targeted
if (dispatcher.targetedEntity != entity && !PetOwnerConfig.alwaysShow) return;
if (!petRenderState.petOwner$getIsTargeted() && !PetOwnerConfig.alwaysShow) return;

List<UUID> ownerIds = PetOwnerClient.getOwnerIds(entity);
List<UUID> ownerIds = petRenderState.petOwner$getOwnerIds();
if (ownerIds.isEmpty()) return;

for (int i = 0; i < ownerIds.size(); i++) {
Expand All @@ -61,9 +65,9 @@ private void render(Entity entity, float yaw, float tickDelta, MatrixStack matri
PetOwnerClient.LOGGER.error("If you're trying to figure out why the mod doesn't work, it's cause you're in a dev env");
}

double d = this.dispatcher.getSquaredDistanceToCamera(entity);
double d = state.squaredDistanceToCamera;
if (d <= 4096.0D) {
Vec3d vec3d = entity.getAttachments().getPointNullable(EntityAttachmentType.NAME_TAG, 0, entity.getYaw(tickDelta));
Vec3d vec3d = state.nameLabelPos;
if (vec3d != null) {
int y = 10 + (10 * i);
matrices.push();
Expand All @@ -85,4 +89,18 @@ private void render(Entity entity, float yaw, float tickDelta, MatrixStack matri
}
}
}

@Inject(method = "updateRenderState", at = @At("HEAD"))
private void updateRenderState(T entity, S state, float tickDelta, CallbackInfo ci) {
if (state instanceof PetRenderState petRenderState) {
petRenderState.petOwner$setOwnerIds(PetOwnerClient.getOwnerIds(entity));
petRenderState.petOwner$setHasPassenger(entity.hasPassenger(MinecraftClient.getInstance().player));
petRenderState.petOwner$setIsTargeted(entity == MinecraftClient.getInstance().targetedEntity);

if (!PetOwnerClient.getOwnerIds(entity).isEmpty()) {
state.nameLabelPos = entity.getAttachments().getPointNullable(EntityAttachmentType.NAME_TAG, 0, entity.getLerpedYaw(tickDelta));
}
}
}

}
8 changes: 2 additions & 6 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@
},
"depends": {
"midnightlib": ">=1.5.0",
"fabric-api-base": "*",
"fabric-key-binding-api-v1": "*",
"fabric-lifecycle-events-v1": "*",
"fabric-resource-loader-v0": "*",
"fabric-screen-api-v1": "*",
"minecraft":">=1.21"
"fabric-api": "*",
"minecraft":">=1.21.3"
},
"mixins": [
"petowner.mixins.json"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/petowner.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "us.potatoboy.petowner.mixin",
"compatibilityLevel": "JAVA_8",
"client": [
"EntityRenderStateMixin",
"FoxTrustedAccessor",
"OwnerNameTagRendering"
],
Expand Down

0 comments on commit 37cbd29

Please sign in to comment.