diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 92a4678..a8a0d06 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: - name: capture build artifacts if: ${{ runner.os == 'Linux' }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Artifacts path: build/libs/ \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9ebb560..5979fcc 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,16 +14,14 @@ on: type: string permissions: - # packages: write + packages: write contents: write jobs: publish: strategy: matrix: - # Use these Java versions java: [21] - # and run on both Linux and Windows os: [ubuntu-22.04] runs-on: ${{ matrix.os }} @@ -51,14 +49,11 @@ jobs: if: ${{ runner.os != 'Windows' }} run: chmod +x ./gradlew - # get new tag in the form vX.Y.Z, saved to new_tag=vX.Y.Z - name: Pull Mod Version id: pull-new-version run: | grep 'module_version=' gradle.properties | sed 's/module_version=/new_tag=v/g' >> $GITHUB_OUTPUT - # previous tag parsing - # we use an env variable here because it's easier than joining two step outputs I think - name: Set previous tag from override if: ${{ inputs.lastTagOverride != null }} run: | @@ -80,8 +75,6 @@ jobs: echo "PREVIOUS_TAG=NONE" >> "$GITHUB_ENV" fi - # new tag parsing and concat - # vX.Y.Z -> vX.Y.Z+1.20.4 - id: new-tag-generator name: Format new tag from input and branch run: | @@ -122,18 +115,16 @@ jobs: - name: build & run tests run: ./gradlew check build - - name: Publish to JackFred Maven and GitHub Release + - name: Publish to GitHub Packages and GitHub Release run: ./gradlew publish githubRelease -PchangelogHeaderAddon="${{ inputs.changelogHeader }}" env: RELEASE: true GITHUB_ACTOR: ${{ secrets.GITHUB_ACTOR }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - JACKFRED_MAVEN_USER: ${{ secrets.JACKFRED_MAVEN_USER }} - JACKFRED_MAVEN_PASS: ${{ secrets.JACKFRED_MAVEN_PASS }} - name: Capture build artifacts if: ${{ runner.os == 'Linux' }} - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Artifacts path: | diff --git a/build.gradle.kts b/build.gradle.kts index 0583d92..92e7ffa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,9 +8,9 @@ import red.jackf.GenerateChangelogTask import red.jackf.UpdateDependenciesTask plugins { - id("fabric-loom") version "1.9-SNAPSHOT" apply false + id("fabric-loom") version "1.11-SNAPSHOT" apply false id("com.github.breadmoirai.github-release") version "2.4.1" apply false - id("org.ajoberstar.grgit") version "5.0.+" + id("org.ajoberstar.grgit") version "5.2.1" id("maven-publish") } @@ -144,19 +144,24 @@ allprojects { // PACKAGING // /////////////// - tasks.withType().configureEach { - inputs.property("module_version", version) - inputs.property("module_name", +properties["module_name"]) - inputs.property("module_description", +properties["module_description"]) + val moduleName = project.properties["module_name"]?.toString() ?: "jackfredlib" + val moduleDescription = project.properties["module_description"]?.toString() ?: "Library for WhereIsIt" + val rootModuleName = rootProject.properties["module_name"]?.toString() ?: "WhereIsIt" + val rootModuleDescription = rootProject.properties["module_description"]?.toString() ?: "WhereIsIt project" - inputs.property("root_module_name", +rootProject.properties["module_name"]) - inputs.property("root_module_description", +rootProject.properties["module_description"]) + tasks.withType().configureEach { + inputs.property("module_version", project.version) + inputs.property("module_name", moduleName) + inputs.property("module_description", moduleDescription) + inputs.property("root_module_name", rootModuleName) + inputs.property("root_module_description", rootModuleDescription) filesMatching("fabric.mod.json") { expand(inputs.properties) } } + tasks.named("jar") { from(rootProject.file("LICENSE")) { rename { "${it}_${this@allprojects.name}" } @@ -253,11 +258,11 @@ fun setupRepositories(repos: RepositoryHandler) { if (canPublish) { repos.maven { - name = "JackFred-Maven" - url = uri("https://maven.jackf.red/releases") + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ponuing/JackFredLib") credentials { - username = System.getenv("JACKFRED_MAVEN_USER") - password = System.getenv("JACKFRED_MAVEN_PASS") + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") } } } @@ -291,19 +296,18 @@ allprojects { } developers { developer { - url = "https://jackf.red" - name = "JackFred2" + url = "https://github.com/ponuing" + name = "ponuing" } } scm { - connection = "scm:git:git://github.com/JackFred2/JackFredLib.git" - developerConnection = "scm:git:git://github.com/JackFred2/JackFredLib.git" + connection = "scm:git:git://github.com/ponuing/JackFredLib.git" + developerConnection = "scm:git:git://github.com/ponuing/JackFredLib.git" url = +propertiesHandle["github_url"] } } } } - setupRepositories(repositories) } } diff --git a/gradle.properties b/gradle.properties index 5f39dc8..12150cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.4-rc3 -parchment_version=1.21:2024.07.28 -loader_version=0.16.9 +minecraft_version=1.21.9 +parchment_version=1.21.9:2025.10.05 +loader_version=0.17.3 # https://github.com/FabricMC/fabric-loom/issues/869 # seems to randomly work? not reliable enough @@ -18,19 +18,19 @@ archives_base_name=jackfredlib # Dependencies # JF_AUTO_UPDATE_BLOCK -fabric-api_version=0.110.3+1.21.4 -modmenu_version=12.0.0-beta.1 +fabric-api_version=0.134.0+1.21.9 +modmenu_version=16.0.0-rc.1 # JF_END_AUTO_UPDATE_BLOCK # mixin_extras_version=0.2.1 jankson_version=1.2.3 -commons_io_version=2.17.0 +commons_io_version=2.20.0 # Publishing # lastTag=v0.5.12+1.20.2 # newTag=v0.5.13+1.20.2 changelog_filter=[feat],[fix],[change],[docs] -github_url=https://github.com/JackFred2/JackFredLib -github_owner=JackFred2 +github_url=https://github.com/ponuing/JackFredLib +github_owner=ponuing github_repo=JackFredLib mod_name=JackFredLib diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 94ce4ff..9348b7c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sun Aug 18 16:37:48 BST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jackfredlib-colour/src/client/java/red/jackf/jackfredlib/client/api/colour/GradientUtils.java b/jackfredlib-colour/src/client/java/red/jackf/jackfredlib/client/api/colour/GradientUtils.java index 79b9798..5ec3850 100644 --- a/jackfredlib-colour/src/client/java/red/jackf/jackfredlib/client/api/colour/GradientUtils.java +++ b/jackfredlib-colour/src/client/java/red/jackf/jackfredlib/client/api/colour/GradientUtils.java @@ -2,9 +2,8 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.RenderType; import net.minecraft.util.Mth; -import org.joml.Matrix4f; +import org.joml.Matrix3x2f; import red.jackf.jackfredlib.api.colour.Colour; import red.jackf.jackfredlib.api.colour.Gradient; @@ -37,18 +36,16 @@ public static void drawHorizontalGradient(GuiGraphics graphics, int x, int y, in } final Gradient usedGradient = generateRepeatedGradient(gradient, gradientStart, gradientEnd); - graphics.drawSpecial(buffer -> { - var pose = graphics.pose().last().pose(); - - float lastKey = usedGradient.getPoints().firstKey(); - for (float secondKey : usedGradient.getPoints().navigableKeySet()) { - if (secondKey == lastKey) continue; // don't do last - float x1 = x + (width * lastKey); - float x2 = x + (width * secondKey); - drawHorizontalGradient(buffer.getBuffer(RenderType.gui()), pose, x1, y, x2, y + height, usedGradient.sample(lastKey), usedGradient.sample(secondKey)); - lastKey = secondKey; - } - }); + float lastKey = usedGradient.getPoints().firstKey(); + for (float secondKey : usedGradient.getPoints().navigableKeySet()) { + if (secondKey == lastKey) continue; // don't do last + float x1 = x + (width * lastKey); + float x2 = x + (width * secondKey); + int fromArgb = usedGradient.sample(lastKey).toARGB(); + int toArgb = usedGradient.sample(secondKey).toARGB(); + graphics.fillGradient((int)Math.floor(x1), y, (int)Math.ceil(x2), y + height, fromArgb, toArgb); + lastKey = secondKey; + } } /** @@ -74,18 +71,16 @@ public static void drawVerticalGradient(GuiGraphics graphics, int x, int y, int } final Gradient usedGradient = generateRepeatedGradient(gradient, gradientStart, gradientEnd); - graphics.drawSpecial(buffer -> { - var pose = graphics.pose().last().pose(); - - float lastKey = usedGradient.getPoints().firstKey(); - for (float secondKey : usedGradient.getPoints().navigableKeySet()) { - if (secondKey == lastKey) continue; // don't do last - float y1 = y + (height * lastKey); - float y2 = y + (height * secondKey); - drawVerticalGradient(buffer.getBuffer(RenderType.gui()), pose, x, y1, x + width, y2, usedGradient.sample(lastKey), usedGradient.sample(secondKey)); - lastKey = secondKey; - } - }); + float lastKey = usedGradient.getPoints().firstKey(); + for (float secondKey : usedGradient.getPoints().navigableKeySet()) { + if (secondKey == lastKey) continue; // don't do last + float y1 = y + (height * lastKey); + float y2 = y + (height * secondKey); + int fromArgb = usedGradient.sample(lastKey).toARGB(); + int toArgb = usedGradient.sample(secondKey).toARGB(); + graphics.fillGradient(x, (int)Math.floor(y1), x + width, (int)Math.ceil(y2), fromArgb, toArgb); + lastKey = secondKey; + } } private static Gradient generateRepeatedGradient(Gradient gradient, float gradientStart, float gradientEnd) { @@ -105,9 +100,9 @@ private static Gradient generateRepeatedGradient(Gradient gradient, float gradie return gradient; } - private static void drawVerticalGradient(VertexConsumer buffer, Matrix4f pose, - float x1, float y1, float x2, float y2, - Colour from, Colour to) { + private static void drawVerticalGradient(VertexConsumer buffer, Matrix3x2f pose, + float x1, float y1, float x2, float y2, + Colour from, Colour to) { int r1 = from.r(); int g1 = from.g(); int b1 = from.b(); @@ -117,13 +112,13 @@ private static void drawVerticalGradient(VertexConsumer buffer, Matrix4f pose, int b2 = to.b(); int a2 = to.a(); - buffer.addVertex(pose, x1, y1, 0).setColor(r1, g1, b1, a1); - buffer.addVertex(pose, x1, y2, 0).setColor(r2, g2, b2, a2); - buffer.addVertex(pose, x2, y2, 0).setColor(r2, g2, b2, a2); - buffer.addVertex(pose, x2, y1, 0).setColor(r1, g1, b1, a1); + buffer.addVertex(x1, y1, 0).setColor(r1, g1, b1, a1); + buffer.addVertex(x1, y2, 0).setColor(r2, g2, b2, a2); + buffer.addVertex(x2, y2, 0).setColor(r2, g2, b2, a2); + buffer.addVertex(x2, y1, 0).setColor(r1, g1, b1, a1); } - private static void drawHorizontalGradient(VertexConsumer buffer, Matrix4f pose, + private static void drawHorizontalGradient(VertexConsumer buffer, Matrix3x2f pose, float x1, float y1, float x2, float y2, Colour from, Colour to) { int r1 = from.r(); @@ -135,9 +130,9 @@ private static void drawHorizontalGradient(VertexConsumer buffer, Matrix4f pose, int b2 = to.b(); int a2 = to.a(); - buffer.addVertex(pose, x1, y1, 0).setColor(r1, g1, b1, a1); - buffer.addVertex(pose, x1, y2, 0).setColor(r1, g1, b1, a1); - buffer.addVertex(pose, x2, y2, 0).setColor(r2, g2, b2, a2); - buffer.addVertex(pose, x2, y1, 0).setColor(r2, g2, b2, a2); + buffer.addVertex(x1, y1, 0).setColor(r1, g1, b1, a1); + buffer.addVertex(x1, y2, 0).setColor(r1, g1, b1, a1); + buffer.addVertex(x2, y2, 0).setColor(r2, g2, b2, a2); + buffer.addVertex(x2, y1, 0).setColor(r2, g2, b2, a2); } -} +} \ No newline at end of file diff --git a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/EntityUtils.java b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/EntityUtils.java index 31163fd..1e7a784 100644 --- a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/EntityUtils.java +++ b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/EntityUtils.java @@ -112,7 +112,7 @@ public static void setDisplayItem(Display.ItemDisplay display, ItemStack stack) /** *

Change a display entity's view range multiplier. This is scaled with a client's Entity View Distance modifier.

- *

The default rangefor a display entity with a modifier of {@code 1.0} and a client Entity View Distance of {@code 100%}, + *

The default range for a display entity with a modifier of {@code 1.0} and a client Entity View Distance of {@code 100%}, * is 64 blocks.

* * @param display Display to update @@ -161,7 +161,7 @@ public static void setDisplayBrightnessOverride(Display display, Brightness brig * * @param display Display to update the brightness for. * @param block Block light level to use for the display (e.g. from glowstone, torches) - * @param sky Sky light level to use for the display (e.g. from the sun, darkened by storms) + * @param sky Skylight level to use for the display (e.g. from the sun, darkened by storms) */ public static void setDisplayBrightnessOverride(Display display, int block, int sky) { ((DisplayAccessor) display).jflib$setBrightnessOverride(new Brightness(block, sky)); @@ -372,20 +372,51 @@ public static void face(Entity source, Entity target) { */ public static void face(Entity source, Vec3 target) { var vector = target.subtract(source.position()); - var yRot = (float) (Mth.atan2(vector.z, vector.x) * 180.0F / (float) Math.PI) + 90.0F; + var yRot = (float) (Mth.atan2(vector.z(), vector.x()) * 180.0F / (float) Math.PI) + 90.0F; //noinspection SuspiciousNameCombination - var xRot = (float) (Mth.atan2(vector.horizontalDistance(), vector.y) * 180.0F / (float) Math.PI) - 90.0F; + var xRot = (float) (Mth.atan2(vector.horizontalDistance(), vector.y()) * 180.0F / (float) Math.PI) - 90.0F; //if (source instanceof Display) { // if this wasn't offset the displays would be backwards yRot += 180.0F % 360.0F; //} - source.moveTo(source.getX(), - source.getY(), - source.getZ(), - Mth.positiveModulo(yRot, 360f), - Mth.positiveModulo(xRot, 360f)); + + float yaw = Mth.positiveModulo(yRot, 360f); + float pitch = Mth.positiveModulo(xRot, 360f); + + double x = source.getX(); + double y = source.getY(); + double z = source.getZ(); + + // Try to call absMoveTo(x,y,z,yaw,pitch) reflectively (present in many mappings). + // If it's not available, fall back to setting position and rotations separately. + try { + source.getClass() + .getMethod("absMoveTo", double.class, double.class, double.class, float.class, float.class) + .invoke(source, x, y, z, yaw, pitch); + } catch (ReflectiveOperationException | LinkageError ignored) { + // fallback: set position then rotation setters (common names) + try { + source.setPos(x, y, z); + } catch (LinkageError ignored2) { + } + try { + source.setYRot(yaw); + } catch (LinkageError ignored2) { + } + try { + source.setXRot(pitch); + } catch (LinkageError ignored2) { + } + } + if (source instanceof LivingEntity living) { - living.setYBodyRot(yRot); - living.setYHeadRot(yRot); + try { + living.setYBodyRot(yaw); + } catch (LinkageError ignored) { + } + try { + living.setYHeadRot(yaw); + } catch (LinkageError ignored) { + } } } -} +} \ No newline at end of file diff --git a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/builders/BuilderBase.java b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/builders/BuilderBase.java index 82ee802..26667e6 100644 --- a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/builders/BuilderBase.java +++ b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/api/lying/entity/builders/BuilderBase.java @@ -30,6 +30,7 @@ public abstract class BuilderBase> * * @see EntityType * @param type Entity type to be used. + * @throws IllegalArgumentException if the entity could not be created, likely caused by being part of a disabled feature. * @param level Level to create the entity in */ protected BuilderBase(EntityType type, ServerLevel level) { @@ -52,7 +53,16 @@ public E build() { * @return This builder */ public B position(Vec3 position) { - this.entity.moveTo(position); + // Use Vec3 accessor methods (x(), y(), z()) and set position via setPos(double,double,double) + // setPos is available in common mappings; if your mappings differ, adapt accordingly. + try { + // prefer absMoveTo if available (some mappings have it) + this.entity.getClass().getMethod("absMoveTo", double.class, double.class, double.class) + .invoke(this.entity, position.x(), position.y(), position.z()); + } catch (ReflectiveOperationException | LinkageError ignored) { + // fallback: setPos + this.entity.setPos(position.x(), position.y(), position.z()); + } return self(); } @@ -71,7 +81,15 @@ public B position(BlockPos position) { * @return This builder */ public B positionCentered(Vec3 position) { - this.entity.moveTo(position.subtract(0, this.entity.getBbHeight() / 2, 0)); + // center the entity by subtracting half the bounding box height from the y coordinate + Vec3 target = position.subtract(0.0, this.entity.getBbHeight() / 2.0, 0.0); + try { + // prefer absMoveTo if available + this.entity.getClass().getMethod("absMoveTo", double.class, double.class, double.class) + .invoke(this.entity, target.x(), target.y(), target.z()); + } catch (ReflectiveOperationException | LinkageError ignored) { + this.entity.setPos(target.x(), target.y(), target.z()); + } return self(); } @@ -91,11 +109,31 @@ public B positionCentered(BlockPos position) { * @return This builder */ public B rotation(float xRot, float yRot) { - this.entity.moveTo(this.entity.getX(), - this.entity.getY(), - this.entity.getZ(), - Mth.positiveModulo(yRot, 360.0F), - Mth.clamp(xRot, -90.0F, 90.0F)); + float yaw = Mth.positiveModulo(yRot, 360.0F); + float pitch = Mth.clamp(xRot, -90.0F, 90.0F); + + double x = this.entity.getX(); + double y = this.entity.getY(); + double z = this.entity.getZ(); + + // Try to call absMoveTo(x,y,z,yaw,pitch) if present; otherwise set pos and rotations separately. + try { + this.entity.getClass().getMethod("absMoveTo", double.class, double.class, double.class, float.class, float.class) + .invoke(this.entity, x, y, z, yaw, pitch); + } catch (ReflectiveOperationException | LinkageError ignored) { + try { + this.entity.setPos(x, y, z); + } catch (LinkageError ignored2) { + } + try { + this.entity.setYRot(yaw); + } catch (LinkageError ignored2) { + } + try { + this.entity.setXRot(pitch); + } catch (LinkageError ignored2) { + } + } return self(); } @@ -182,4 +220,4 @@ public B alwaysRenderName(boolean alwaysRenderName) { */ @ApiStatus.Internal protected abstract B self(); -} +} \ No newline at end of file diff --git a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/LieManager.java b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/LieManager.java index 25624a3..2e23bd2 100644 --- a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/LieManager.java +++ b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/LieManager.java @@ -77,8 +77,13 @@ public void migrateEntity(Entity entity) { } private static void doMigrateEntity(EntityGlowLieImpl lie, Entity entity) { - //noinspection unchecked - lie.setEntity((E) entity); + // Double-check safety here before the unchecked cast: + // we only proceed if UUID and exact runtime class match, so the cast to E is safe at runtime. + if (!lie.entity().getUUID().equals(entity.getUUID()) || lie.entity().getClass() != entity.getClass()) return; + + @SuppressWarnings("unchecked") + E casted = (E) entity; + lie.setEntity(casted); } ///////////////// @@ -114,4 +119,4 @@ public void removeEntityGlow(ServerPlayer player, EntityGlowLieImpl lie) { public Optional> getEntityGlowLieFromEntityUuid(ServerPlayer player, UUID uuid) { return entityGlowLies.get(player).stream().filter(glowLie -> glowLie.entity().getUUID().equals(uuid)).findFirst(); } -} +} \ No newline at end of file diff --git a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/entity/EntityLieImpl.java b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/entity/EntityLieImpl.java index 4d3f0ed..e2447ea 100644 --- a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/entity/EntityLieImpl.java +++ b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/impl/lying/entity/EntityLieImpl.java @@ -1,6 +1,8 @@ package red.jackf.jackfredlib.impl.lying.entity; import net.minecraft.ChatFormatting; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.server.level.ServerEntity; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -16,6 +18,8 @@ import red.jackf.jackfredlib.impl.lying.faketeams.FakeTeamManager; import red.jackf.jackfredlib.impl.lying.faketeams.FakeTeamUtil; +import java.util.function.Predicate; + public class EntityLieImpl extends LieImpl implements EntityLie { private final E entity; private final ServerEntity serverEntity; @@ -25,6 +29,16 @@ public class EntityLieImpl extends LieImpl implements EntityLi private final @Nullable LeftClickCallback leftClickCallback; private final @Nullable RightClickCallback rightClickCallback; + /** + * Creates a new entity lie with the specified entity and callbacks. + * + * @param entity Entity to manage + * @param glowColour Glow colour for this entity, or null for no glow + * @param tickCallback Callback invoked each tick for viewing players, or null + * @param fadeCallback Callback invoked when a player stops viewing this entity, or null + * @param leftClickCallback Callback invoked when a player left-clicks this entity, or null + * @param rightClickCallback Callback invoked when a player right-clicks this entity, or null + */ public EntityLieImpl( E entity, @Nullable ChatFormatting glowColour, @@ -44,7 +58,41 @@ public EntityLieImpl( entity, entity.getType().updateInterval(), entity.getType().trackDeltas(), - packet -> getViewingPlayers().forEach(player -> player.connection.send(packet)) + new ServerEntity.Synchronizer() { + public void sendToTracking(Packet packet) { + // forward packet to all current viewing players + for (ServerPlayer player : EntityLieImpl.this.getViewingPlayers()) { + player.connection.send(packet); + } + } + + public void sendToTrackingAndSelf(Packet packet) { + // forward packet to all viewing players (and you can add any additional logic for "self" if needed) + for (ServerPlayer player : EntityLieImpl.this.getViewingPlayers()) { + player.connection.send(packet); + } + } + + @Override + public void sendToTrackingPlayers(Packet packet) { + + } + + @Override + public void sendToTrackingPlayersAndSelf(Packet packet) { + + } + + @Override + public void sendToTrackingPlayersFiltered(Packet packet, Predicate filter) { + // forward packet only to viewing players that satisfy the provided filter + for (ServerPlayer player : EntityLieImpl.this.getViewingPlayers()) { + if (filter.test(player)) { + player.connection.send(packet); + } + } + } + } ); } @@ -120,4 +168,4 @@ public void rightClick(ServerPlayer player, boolean usingSecondaryAction, Intera if (this.rightClickCallback != null) this.rightClickCallback.onRightClick(player, this, usingSecondaryAction, hand, relativeToEntity); } -} +} \ No newline at end of file diff --git a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/mixins/lying/entityglow/ChunkMapTrackedEntityMixin.java b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/mixins/lying/entityglow/ChunkMapTrackedEntityMixin.java index 0c8e778..acabd56 100644 --- a/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/mixins/lying/entityglow/ChunkMapTrackedEntityMixin.java +++ b/jackfredlib-lying/src/main/java/red/jackf/jackfredlib/mixins/lying/entityglow/ChunkMapTrackedEntityMixin.java @@ -1,43 +1,55 @@ package red.jackf.jackfredlib.mixins.lying.entityglow; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; -import net.minecraft.server.level.ChunkMap; import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.server.level.ChunkMap; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; import red.jackf.jackfredlib.impl.lying.LieManager; import red.jackf.jackfredlib.impl.lying.glowing.FakeGlowPacketMeddling; +import java.util.function.Predicate; + /** - * Modifies an entities' initial data packet so as to add a glowing tag if needed by an entity glow lie.. - * - * @author JackFred + * Modifies an entities' tracking packets to add a glowing tag if needed by an entity glow lie. */ @Mixin(ChunkMap.TrackedEntity.class) public class ChunkMapTrackedEntityMixin { - @Shadow - @Final - Entity entity; + @Shadow @Final Entity entity; + + // Redirect inside: public void sendToTrackingPlayers(Packet packet) + @Redirect(method = "sendToTrackingPlayers(Lnet/minecraft/network/protocol/Packet;)V", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/network/ServerPlayerConnection;send(Lnet/minecraft/network/protocol/Packet;)V")) + private void jackfredlib$modifyDataPacketSendToTrackingPlayers(ServerPlayerConnection connection, Packet packet) { + if (packet instanceof ClientboundSetEntityDataPacket entityData) { + var lie = LieManager.INSTANCE.getEntityGlowLieFromEntityUuid(connection.getPlayer(), this.entity.getUUID()); + if (lie.isPresent()) { + connection.send(FakeGlowPacketMeddling.modifyPacket(entityData, lie.get())); + return; + } + } + connection.send(packet); + } - @WrapOperation(method = "broadcast(Lnet/minecraft/network/protocol/Packet;)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerConnection;send(Lnet/minecraft/network/protocol/Packet;)V")) - private void jackfredlib$modifyDataPacket( - ServerPlayerConnection connection, - Packet packet, - Operation original) { + // Redirect inside: public void sendToTrackingPlayersFiltered(Packet packet, Predicate filter) + @Redirect(method = "sendToTrackingPlayersFiltered(Lnet/minecraft/network/protocol/Packet;Ljava/util/function/Predicate;)V", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/network/ServerPlayerConnection;send(Lnet/minecraft/network/protocol/Packet;)V")) + private void jackfredlib$modifyDataPacketSendToTrackingPlayersFiltered(ServerPlayerConnection connection, Packet packet) { if (packet instanceof ClientboundSetEntityDataPacket entityData) { var lie = LieManager.INSTANCE.getEntityGlowLieFromEntityUuid(connection.getPlayer(), this.entity.getUUID()); if (lie.isPresent()) { - original.call(connection, FakeGlowPacketMeddling.modifyPacket(entityData, lie.get())); + connection.send(FakeGlowPacketMeddling.modifyPacket(entityData, lie.get())); return; } } - original.call(connection, packet); + connection.send(packet); } -} +} \ No newline at end of file diff --git a/jackfredlib-testmod/src/client/java/red/jackf/jackfredlib/testmod/client/ToastTest.java b/jackfredlib-testmod/src/client/java/red/jackf/jackfredlib/testmod/client/ToastTest.java index 95e8a27..8d003ff 100644 --- a/jackfredlib-testmod/src/client/java/red/jackf/jackfredlib/testmod/client/ToastTest.java +++ b/jackfredlib-testmod/src/client/java/red/jackf/jackfredlib/testmod/client/ToastTest.java @@ -64,7 +64,7 @@ public class ToastTest { public static void setup() { UseItemCallback.EVENT.register((player, world, hand) -> { - if (!world.isClientSide || hand != InteractionHand.MAIN_HAND) return InteractionResult.PASS; + if (!world.isClientSide() || hand != InteractionHand.MAIN_HAND) return InteractionResult.PASS; var stack = player.getItemInHand(hand); if (stack.is(Items.DIAMOND_PICKAXE)) { TITLE_AND_MESSAGE.get().setProgress(0f); diff --git a/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/CustomToastImpl.java b/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/CustomToastImpl.java index 75f2aeb..f8efd6d 100644 --- a/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/CustomToastImpl.java +++ b/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/CustomToastImpl.java @@ -4,8 +4,12 @@ import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.toasts.ToastManager; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderPipelines; +import net.minecraft.client.resources.metadata.gui.GuiMetadataSection; import net.minecraft.client.resources.metadata.gui.GuiSpriteScaling; +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.data.AtlasIds; import net.minecraft.network.chat.Component; import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; @@ -70,9 +74,10 @@ public void setMessage(List messages) { } private int leftWidth() { - var guiSprites = Minecraft.getInstance().getGuiSprites(); - var sprite = guiSprites.getSpriteScaling(guiSprites.getSprite(format.texture())); - if (sprite instanceof GuiSpriteScaling.NineSlice nineSlice) { + TextureAtlas guiAtlas = Minecraft.getInstance().getAtlasManager().getAtlasOrThrow(AtlasIds.GUI); + TextureAtlasSprite sprite = guiAtlas.getSprite(format.texture()); + GuiSpriteScaling scaling = ((GuiMetadataSection) sprite.contents().getAdditionalMetadata(GuiMetadataSection.TYPE).orElse(GuiMetadataSection.DEFAULT)).scaling(); + if (scaling instanceof GuiSpriteScaling.NineSlice nineSlice) { return nineSlice.border().left(); } else { return DEFAULT_PADDING; @@ -122,7 +127,7 @@ public void render(GuiGraphics graphics, Font font, long timeVisible) { if (progress >= 1f && progressCompleteTime == -1) progressCompleteTime = timeVisible; // background - graphics.blitSprite(RenderType::guiTextured, + graphics.blitSprite(RenderPipelines.GUI_TEXTURED, format.texture(), 0, 0, @@ -193,4 +198,4 @@ public long getTimeVisible() { public interface VisibilityChecker { Visibility check(CustomToastImpl customToast); } -} +} \ No newline at end of file diff --git a/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ImageIcon.java b/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ImageIcon.java index c0a61b4..bfb1146 100644 --- a/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ImageIcon.java +++ b/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ImageIcon.java @@ -1,8 +1,7 @@ package red.jackf.jackfredlib.client.impl.toasts.icon; -import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.RenderPipelines; import net.minecraft.resources.ResourceLocation; import org.apache.http.util.Args; import red.jackf.jackfredlib.client.api.toasts.CustomToast; @@ -55,15 +54,14 @@ public ImageIcon(ResourceLocation location, @Override public void render(CustomToast toast, GuiGraphics graphics, int x, int y) { - RenderSystem.enableBlend(); - graphics.blit(RenderType::guiTextured, + // Use RenderPipelines.GUI_TEXTURED — GuiGraphics expects a RenderPipeline constant here. + graphics.blit(RenderPipelines.GUI_TEXTURED, location, x, y, uOffset, vOffset, width, height, uWidth, vHeight, textureWidth, textureHeight); - RenderSystem.disableBlend(); } @Override @@ -75,4 +73,4 @@ public int width() { public int height() { return height; } -} +} \ No newline at end of file diff --git a/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ItemStackIcon.java b/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ItemStackIcon.java index 90e13f7..e396fe4 100644 --- a/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ItemStackIcon.java +++ b/jackfredlib-toasts/src/client/java/red/jackf/jackfredlib/client/impl/toasts/icon/ItemStackIcon.java @@ -28,11 +28,14 @@ public void render(CustomToast toast, GuiGraphics graphics, int x, int y) { int scale = 2 * sizeInSlots - 1; int index = Mth.clamp((int) (toast.getProgress() * this.items.size()), 0, this.items.size() - 1); - graphics.pose().pushPose(); - graphics.pose().translate(x + INSET, y + INSET, 0); - graphics.pose().scale(scale, scale, 1); + + graphics.pose().pushMatrix(); + graphics.pose().translate(x + INSET, y + INSET); + graphics.pose().scale((float) scale, (float) scale); + graphics.renderFakeItem(this.items.get(index), 0, 0); - graphics.pose().popPose(); + + graphics.pose().popMatrix(); } @Override @@ -44,4 +47,4 @@ public int width() { public int height() { return ToastIcon.slotsToHeight(sizeInSlots); } -} +} \ No newline at end of file