From f04a7d19cf01e31c527b6d221642169e24fa2de0 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Thu, 30 Nov 2023 23:15:29 +0100 Subject: [PATCH] Update to 1.20.3-rc1 --- build.gradle | 5 +-- gradle.properties | 11 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- .../pb4/polymer/autohost/impl/AutoHost.java | 2 +- .../impl/providers/WebServerProvider.java | 12 +++---- .../src/main/resources/fabric.mod.json | 2 +- .../src/main/resources/fabric.mod.json | 2 +- polymer-common/build.gradle | 2 -- .../common/api/PolymerCommonUtils.java | 17 ++++++++- .../ServerCommonNetworkHandlerMixin.java | 2 +- .../src/main/resources/fabric.mod.json | 7 ++-- polymer-core/build.gradle | 1 - .../src/main/resources/fabric.mod.json | 2 +- polymer-networking/build.gradle | 1 - .../src/main/resources/fabric.mod.json | 2 +- polymer-reg-sync-manipulator/build.gradle | 1 - polymer-resource-pack/build.gradle | 3 +- .../api/PolymerResourcePackUtils.java | 17 +++++---- .../impl/PolymerResourcePackMod.java | 4 +-- .../client/rendering/PolymerResourcePack.java | 7 ++-- .../src/main/resources/fabric.mod.json | 4 +-- polymer-virtual-entity/build.gradle | 1 - .../virtualentity/api/VirtualEntityUtils.java | 27 ++++++++++---- .../impl/VirtualEntityImplUtils.java | 14 -------- .../PlaySoundFromEntityS2CPacketAccessor.java | 36 +++++++++++++++++++ .../src/main/resources/fabric.mod.json | 4 +-- .../polymer-virtual-entity.mixins.json | 1 + 27 files changed, 117 insertions(+), 72 deletions(-) delete mode 100644 polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/impl/VirtualEntityImplUtils.java create mode 100644 polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/accessors/PlaySoundFromEntityS2CPacketAccessor.java diff --git a/build.gradle b/build.gradle index fe43925e..d92addb8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.0+' + id 'fabric-loom' version '1.4.+' id "com.modrinth.minotaur" version "2.+" id 'com.matthewprenger.cursegradle' version '1.4.0' } @@ -75,8 +75,6 @@ allprojects { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modCompileOnly "net.fabricmc:fabric-loader:${project.loader_version}" modLocalRuntime "net.fabricmc:fabric-loader:${project.loader_version}" - - annotationProcessor("io.github.llamalad7:mixinextras-fabric:${mixin_extras_version}") } loom { @@ -113,7 +111,6 @@ subprojects { // Disable the gen sources task on sub projects genSourcesWithFernFlower.enabled = false genSourcesWithCfr.enabled = false - unpickJar.enabled = false } } diff --git a/gradle.properties b/gradle.properties index 3f059457..53cd948b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,20 +3,19 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.20.3-pre2 -yarn_mappings=1.20.3-pre2+build.1 -loader_version=0.14.24 +minecraft_version=1.20.3-rc1 +yarn_mappings=1.20.3-rc1+build.1 +loader_version=0.15.0 #Fabric api -fabric_version=0.90.10+1.20.3 +fabric_version=0.90.11+1.20.3 maven_group = eu.pb4 -mod_version = 0.7.0-dev +mod_version = 0.7.0 minecraft_version_supported = ">=1.20.3-" packet_tweaker_version = 0.5.0+1.20.2-rc1 -mixin_extras_version = 0.2.1 is_stable = true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102e..e411586a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java index f60dabec..9a84b7aa 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/AutoHost.java @@ -63,7 +63,7 @@ public static void end(MinecraftServer server) { public static void generateAndCall(MinecraftServer server, Consumer messageConsumer, Runnable runnable) { Util.getIoWorkerExecutor().execute(() -> { messageConsumer.accept(Text.literal("Starting resource pack generation...")); - boolean success = PolymerResourcePackUtils.build(); + boolean success = PolymerResourcePackUtils.buildMain(); server.execute(() -> { if (success) { diff --git a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/WebServerProvider.java b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/WebServerProvider.java index da979955..d37d4f4b 100644 --- a/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/WebServerProvider.java +++ b/polymer-autohost/src/main/java/eu/pb4/polymer/autohost/impl/providers/WebServerProvider.java @@ -76,9 +76,9 @@ public void serverStopped(MinecraftServer minecraftServer) { private void updateHash() { try { - hash = com.google.common.io.Files.asByteSource(PolymerResourcePackUtils.DEFAULT_PATH.toFile()).hash(Hashing.sha1()).toString(); - size = Files.size(PolymerResourcePackUtils.DEFAULT_PATH); - lastUpdate = Files.getLastModifiedTime(PolymerResourcePackUtils.DEFAULT_PATH).toMillis(); + hash = com.google.common.io.Files.asByteSource(PolymerResourcePackUtils.getMainPath().toFile()).hash(Hashing.sha1()).toString(); + size = Files.size(PolymerResourcePackUtils.getMainPath()); + lastUpdate = Files.getLastModifiedTime(PolymerResourcePackUtils.getMainPath()).toMillis(); this.fullAddress = this.baseAddress + this.hash + ".zip"; } catch (Exception e) { hash = ""; @@ -99,14 +99,14 @@ private static InetSocketAddress createBindAddress(MinecraftServer server, Confi public void handle(HttpExchange exchange) throws IOException { if ("GET".equals(exchange.getRequestMethod())) { - if (Files.exists(PolymerResourcePackUtils.DEFAULT_PATH)) { - var updateTime = Files.getLastModifiedTime(PolymerResourcePackUtils.DEFAULT_PATH).toMillis(); + if (Files.exists(PolymerResourcePackUtils.getMainPath())) { + var updateTime = Files.getLastModifiedTime(PolymerResourcePackUtils.getMainPath()).toMillis(); if (updateTime > lastUpdate) { updateHash(); } try ( - var input = Files.newInputStream(PolymerResourcePackUtils.DEFAULT_PATH); + var input = Files.newInputStream(PolymerResourcePackUtils.getMainPath()); var output = exchange.getResponseBody() ) { exchange.getResponseHeaders().add("Server", "polymer-autohost"); diff --git a/polymer-autohost/src/main/resources/fabric.mod.json b/polymer-autohost/src/main/resources/fabric.mod.json index b86f1371..661bfa2a 100644 --- a/polymer-autohost/src/main/resources/fabric.mod.json +++ b/polymer-autohost/src/main/resources/fabric.mod.json @@ -17,7 +17,7 @@ "depends": { "polymer-resource-pack": ">=${version}", "polymer-common": ">=${version}", - "fabricloader": ">=0.14.0" + "fabricloader": ">=0.15.0" }, "entrypoints": { "main": [ diff --git a/polymer-blocks/src/main/resources/fabric.mod.json b/polymer-blocks/src/main/resources/fabric.mod.json index bb44a27f..3d81369e 100644 --- a/polymer-blocks/src/main/resources/fabric.mod.json +++ b/polymer-blocks/src/main/resources/fabric.mod.json @@ -24,7 +24,7 @@ ], "depends": { "polymer-core": ">=${version}", - "fabricloader": ">=0.14.0" + "fabricloader": ">=0.15.0" }, "custom": { "modmenu": { diff --git a/polymer-common/build.gradle b/polymer-common/build.gradle index 79e1bdaa..a912685e 100644 --- a/polymer-common/build.gradle +++ b/polymer-common/build.gradle @@ -11,7 +11,6 @@ dependencies { modApi include("xyz.nucleoid:packet-tweaker:${packet_tweaker_version}") { transitive(false) } - modApi(include(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${mixin_extras_version}"))) modCompileOnly "xyz.nucleoid:disguiselib-fabric:1.2.2" modCompileOnly "org.geysermc.floodgate:api:2.2.0-SNAPSHOT" } @@ -20,7 +19,6 @@ afterEvaluate { // Disable the gen sources task on sub projects genSourcesWithFernFlower.enabled = true genSourcesWithCfr.enabled = false - unpickJar.enabled = true } processResources { diff --git a/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java b/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java index 03b69df0..80189a38 100644 --- a/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java +++ b/polymer-common/src/main/java/eu/pb4/polymer/common/api/PolymerCommonUtils.java @@ -7,6 +7,7 @@ import eu.pb4.polymer.common.impl.compat.FloodGateUtils; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.ClientConnection; +import net.minecraft.network.packet.s2c.play.PlaySoundFromEntityS2CPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerCommonNetworkHandler; import net.minecraft.server.network.ServerPlayNetworkHandler; @@ -28,7 +29,7 @@ private PolymerCommonUtils(){} public static final SimpleEvent ON_RESOURCE_PACK_STATUS_CHANGE = new SimpleEvent<>(); private static Path cachedClientPath; - private final static String SAFE_CLIENT_SHA1 = "8e9187433bab399843d78585e83bf812422a507d"; + private final static String SAFE_CLIENT_SHA1 = "224c056f3cc6c6e1b5b90e63a0c621811f6a0681"; private final static String SAFE_CLIENT_URL = "https://piston-data.mojang.com/v1/objects/" + SAFE_CLIENT_SHA1 + "/client.jar"; private static Path cachedClientJarRoot; @@ -209,6 +210,20 @@ public static void setHasResourcePack(ClientConnection player, UUID uuid, boolea ((CommonClientConnectionExt) player).polymerCommon$setResourcePack(uuid, status); } + /** + * Creates instance of object by using unsafe, bypassing initializers. + * All of its fields will be set to null or similar. + * + * Useful for bad packet implementations™™ + * + * @param clazz class to instantiate + * @return New instance + * @param Anything you want + */ + public static T createUnsafe(Class clazz) { + return CommonImplUtils.createUnsafe(clazz); + } + public interface ResourcePackChangeCallback { void onResourcePackChange(ServerCommonNetworkHandler handler, UUID uuid, boolean oldStatus, boolean newStatus); } diff --git a/polymer-common/src/main/java/eu/pb4/polymer/common/mixin/ServerCommonNetworkHandlerMixin.java b/polymer-common/src/main/java/eu/pb4/polymer/common/mixin/ServerCommonNetworkHandlerMixin.java index 55b087c4..1fb73236 100644 --- a/polymer-common/src/main/java/eu/pb4/polymer/common/mixin/ServerCommonNetworkHandlerMixin.java +++ b/polymer-common/src/main/java/eu/pb4/polymer/common/mixin/ServerCommonNetworkHandlerMixin.java @@ -27,7 +27,7 @@ public abstract class ServerCommonNetworkHandlerMixin implements CommonNetworkHa if (!CommonImplUtils.disableResourcePackCheck) { if (!this.polymerCommon$ignoreNextStatus) { ((CommonClientConnectionExt) this.connection).polymerCommon$setResourcePack(packet.id(), switch (packet.status()) { - case SUCCESSFULLY_LOADED, ACCEPTED -> true; + case SUCCESSFULLY_LOADED, DOWNLOADED, ACCEPTED -> true; case DECLINED, FAILED_DOWNLOAD, INVALID_URL, FAILED_RELOAD, DISCARDED -> false; }); } diff --git a/polymer-common/src/main/resources/fabric.mod.json b/polymer-common/src/main/resources/fabric.mod.json index aa6f6bdd..e3a6e87a 100644 --- a/polymer-common/src/main/resources/fabric.mod.json +++ b/polymer-common/src/main/resources/fabric.mod.json @@ -19,11 +19,12 @@ "icon": "assets/iconm.png", "environment": "*", "depends": { - "minecraft": ">=1.20.2-", - "fabricloader": ">=0.14.4" + "minecraft": ">=1.20.3-", + "fabricloader": ">=0.15.0" }, "conflicts": { - "banner": "*" + "banner": "*", + "cardboard": "*" }, "custom": { "modmenu": { diff --git a/polymer-core/build.gradle b/polymer-core/build.gradle index f179669e..9c719f01 100644 --- a/polymer-core/build.gradle +++ b/polymer-core/build.gradle @@ -110,5 +110,4 @@ afterEvaluate { // Disable the gen sources task on sub projects genSourcesWithFernFlower.enabled = true genSourcesWithCfr.enabled = false - unpickJar.enabled = true } diff --git a/polymer-core/src/main/resources/fabric.mod.json b/polymer-core/src/main/resources/fabric.mod.json index 6788c657..04296364 100644 --- a/polymer-core/src/main/resources/fabric.mod.json +++ b/polymer-core/src/main/resources/fabric.mod.json @@ -52,7 +52,7 @@ "depends": { "polymer-common": ">=${version}", - "fabricloader": ">=0.14.0" + "fabricloader": ">=0.15.0" }, "custom": { "modmenu": { diff --git a/polymer-networking/build.gradle b/polymer-networking/build.gradle index 358b9559..c2ff88dc 100644 --- a/polymer-networking/build.gradle +++ b/polymer-networking/build.gradle @@ -14,7 +14,6 @@ afterEvaluate { // Disable the gen sources task on sub projects genSourcesWithFernFlower.enabled = true genSourcesWithCfr.enabled = false - unpickJar.enabled = true } processResources { diff --git a/polymer-networking/src/main/resources/fabric.mod.json b/polymer-networking/src/main/resources/fabric.mod.json index 72a9f29f..8469db1b 100644 --- a/polymer-networking/src/main/resources/fabric.mod.json +++ b/polymer-networking/src/main/resources/fabric.mod.json @@ -24,7 +24,7 @@ "environment": "*", "depends": { "polymer-common": ">=${version}", - "fabricloader": ">=0.14.0" + "fabricloader": ">=0.15.0" }, "custom": { "modmenu": { diff --git a/polymer-reg-sync-manipulator/build.gradle b/polymer-reg-sync-manipulator/build.gradle index 2728fa48..814db274 100644 --- a/polymer-reg-sync-manipulator/build.gradle +++ b/polymer-reg-sync-manipulator/build.gradle @@ -35,7 +35,6 @@ afterEvaluate { // Disable the gen sources task on sub projects genSourcesWithFernFlower.enabled = true genSourcesWithCfr.enabled = false - unpickJar.enabled = true } diff --git a/polymer-resource-pack/build.gradle b/polymer-resource-pack/build.gradle index 8a33dd4a..10b67252 100644 --- a/polymer-resource-pack/build.gradle +++ b/polymer-resource-pack/build.gradle @@ -18,6 +18,8 @@ dependencies { modCompileOnly ('com.github.TheEpicBlock:PolyMc:5.4.0') { exclude(group: "org.quiltmc", module: "quilt-loader") } + modCompileOnly "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}" + api include(project(path: ':polymer-common', configuration: 'namedElements')) } @@ -25,7 +27,6 @@ afterEvaluate { // Disable the gen sources task on sub projects genSourcesWithFernFlower.enabled = true genSourcesWithCfr.enabled = false - unpickJar.enabled = true } processResources { diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java index a1fa9a3c..e7ab2396 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/api/PolymerResourcePackUtils.java @@ -10,7 +10,6 @@ import net.minecraft.item.Item; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; -import net.minecraft.util.Uuids; import org.jetbrains.annotations.Nullable; import java.nio.file.FileSystems; @@ -25,7 +24,7 @@ * Global utilities allowing creation of single, polymer mod compatible resource pack */ public final class PolymerResourcePackUtils { - public static final Path DEFAULT_PATH = FabricLoader.getInstance().getGameDir().resolve("polymer-resourcepack.zip").toAbsolutePath().normalize(); + private static final Path DEFAULT_PATH = FabricLoader.getInstance().getGameDir().resolve("polymer-resourcepack.zip").toAbsolutePath().normalize(); private PolymerResourcePackUtils() { } @@ -120,6 +119,10 @@ public static boolean hasMainPack(@Nullable ServerPlayerEntity player) { return hasPack(player, getMainUuid()); } + public static Path getMainPath() { + return DEFAULT_PATH; + } + public static UUID getMainUuid() { return PolymerResourcePackImpl.MAIN_UUID; } @@ -172,15 +175,15 @@ public static ResourcePackBuilder createBuilder(Path output) { return new DefaultRPBuilder(output); } - public static boolean build() { - return build(PolymerResourcePackUtils.DEFAULT_PATH); + public static boolean buildMain() { + return buildMain(PolymerResourcePackUtils.getMainPath()); } - public static boolean build(Path output) { - return build(output, (s) -> {}); + public static boolean buildMain(Path output) { + return buildMain(output, (s) -> {}); } - public static boolean build(Path output, Consumer status) { + public static boolean buildMain(Path output, Consumer status) { try { return INSTANCE.build(output, status); } catch (Exception e) { diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java index dcc22389..246dc38b 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/PolymerResourcePackMod.java @@ -54,14 +54,14 @@ public static int generateResources(CommandContext context) Util.getIoWorkerExecutor().execute(() -> { context.getSource().sendFeedback(() -> Text.literal("Starting resource pack generation..."), true); - boolean success = PolymerResourcePackUtils.build(); + boolean success = PolymerResourcePackUtils.buildMain(); context.getSource().getServer().execute(() -> { if (success) { context.getSource().sendFeedback(() -> Text.literal("Resource pack created successfully! You can find it in game folder as ") .append(Text.literal("polymer-resourcepack.zip") - .setStyle(Style.EMPTY.withUnderline(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(PolymerResourcePackUtils.DEFAULT_PATH.toAbsolutePath().toString()))))), + .setStyle(Style.EMPTY.withUnderline(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal(PolymerResourcePackUtils.getMainPath().toAbsolutePath().toString()))))), true ); } else { diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/client/rendering/PolymerResourcePack.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/client/rendering/PolymerResourcePack.java index 45eae023..2e8bf242 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/client/rendering/PolymerResourcePack.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/client/rendering/PolymerResourcePack.java @@ -4,17 +4,14 @@ import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.SharedConstants; import net.minecraft.resource.*; import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.text.Text; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.io.File; import java.nio.file.Path; import java.util.List; -import java.util.Set; import java.util.function.Consumer; @ApiStatus.Internal @@ -24,8 +21,8 @@ public class PolymerResourcePack { @Nullable public static ResourcePackProfile.PackFactory setup() { - Path outputPath = PolymerResourcePackUtils.DEFAULT_PATH; - if ((outputPath.toFile().exists() && generated) || PolymerResourcePackUtils.build(outputPath)) { + Path outputPath = PolymerResourcePackUtils.getMainPath(); + if ((outputPath.toFile().exists() && generated) || PolymerResourcePackUtils.buildMain(outputPath)) { generated = true; return new ZipResourcePack.ZipBackedFactory(outputPath.toFile(), true); } else { diff --git a/polymer-resource-pack/src/main/resources/fabric.mod.json b/polymer-resource-pack/src/main/resources/fabric.mod.json index ac1e651b..fd141d1e 100644 --- a/polymer-resource-pack/src/main/resources/fabric.mod.json +++ b/polymer-resource-pack/src/main/resources/fabric.mod.json @@ -29,8 +29,8 @@ ], "depends": { - "minecraft": ">=1.20", - "fabricloader": ">=0.14.0" + "polymer-common": ">=${version}", + "fabricloader": ">=0.15.0" }, "custom": { "modmenu": { diff --git a/polymer-virtual-entity/build.gradle b/polymer-virtual-entity/build.gradle index d9578fe5..97d099d7 100644 --- a/polymer-virtual-entity/build.gradle +++ b/polymer-virtual-entity/build.gradle @@ -25,7 +25,6 @@ afterEvaluate { // Disable the gen sources task on sub projects genSourcesWithFernFlower.enabled = true genSourcesWithCfr.enabled = false - unpickJar.enabled = true } processResources { diff --git a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java index 2f4a6ba2..dbe73c5b 100644 --- a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java +++ b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/api/VirtualEntityUtils.java @@ -1,14 +1,13 @@ package eu.pb4.polymer.virtualentity.api; +import eu.pb4.polymer.common.api.PolymerCommonUtils; import eu.pb4.polymer.common.impl.CompatStatus; -import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment; import eu.pb4.polymer.virtualentity.impl.EntityExt; -import eu.pb4.polymer.virtualentity.impl.VirtualEntityImplUtils; import eu.pb4.polymer.virtualentity.impl.compat.ImmersivePortalsUtils; import eu.pb4.polymer.virtualentity.mixin.EntityPassengersSetS2CPacketAccessor; import eu.pb4.polymer.virtualentity.mixin.accessors.EntityAccessor; import eu.pb4.polymer.virtualentity.mixin.accessors.EntityPositionS2CPacketAccessor; -import eu.pb4.polymer.virtualentity.mixin.accessors.ThreadedAnvilChunkStorageAccessor; +import eu.pb4.polymer.virtualentity.mixin.accessors.PlaySoundFromEntityS2CPacketAccessor; import it.unimi.dsi.fastutil.ints.IntList; import net.minecraft.entity.Entity; import net.minecraft.network.listener.ClientPlayPacketListener; @@ -16,9 +15,12 @@ import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket; import net.minecraft.network.packet.s2c.play.EntityS2CPacket; +import net.minecraft.network.packet.s2c.play.PlaySoundFromEntityS2CPacket; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.chunk.WorldChunk; @@ -55,6 +57,19 @@ public static void removeVirtualPassenger(Entity entity, int... passengerId) { ((EntityExt) entity).polymerVE$markVirtualRiddenDirty(); } + public static PlaySoundFromEntityS2CPacket createPlaySoundFromEntityPacket(int entityId, RegistryEntry sound, SoundCategory category, float volume, float pitch, long seed) { + var packet = PolymerCommonUtils.createUnsafe(PlaySoundFromEntityS2CPacket.class); + var ac = (PlaySoundFromEntityS2CPacketAccessor) packet; + ac.setEntityId(entityId); + ac.setSound(sound); + ac.setCategory(category); + ac.setVolume(volume); + ac.setPitch(pitch); + ac.setSeed(seed); + return packet; + } + + @Nullable public static Packet createMovePacket(int id, Vec3d oldPos, Vec3d newPos, boolean rotate, float yaw, float pitch) { var i = MathHelper.floor(yaw * 256.0F / 360.0F); @@ -82,7 +97,7 @@ public static Packet createMovePacket(int id, Vec3d ol } public static Packet createSimpleMovePacket(int id, Vec3d newPos, byte yaw, byte pitch) { - var packet = VirtualEntityImplUtils.createUnsafe(EntityPositionS2CPacket.class); + var packet = PolymerCommonUtils.createUnsafe(EntityPositionS2CPacket.class); var accessor = (EntityPositionS2CPacketAccessor) packet; accessor.setId(id); accessor.setX(newPos.x); @@ -99,7 +114,7 @@ public static EntityPassengersSetS2CPacket createRidePacket(int id, IntList list } public static EntityPassengersSetS2CPacket createRidePacket(int id, int[] list) { - var packet = VirtualEntityImplUtils.createUnsafe(EntityPassengersSetS2CPacket.class); + var packet = PolymerCommonUtils.createUnsafe(EntityPassengersSetS2CPacket.class); ((EntityPassengersSetS2CPacketAccessor) packet).setId(id); ((EntityPassengersSetS2CPacketAccessor) packet).setPassengerIds(list); return packet; diff --git a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/impl/VirtualEntityImplUtils.java b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/impl/VirtualEntityImplUtils.java deleted file mode 100644 index 9be62e09..00000000 --- a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/impl/VirtualEntityImplUtils.java +++ /dev/null @@ -1,14 +0,0 @@ -package eu.pb4.polymer.virtualentity.impl; - -import io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess; - -public class VirtualEntityImplUtils { - public static T createUnsafe(Class tClass) { - try { - return (T) UnsafeAccess.UNSAFE.allocateInstance(tClass); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } -} diff --git a/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/accessors/PlaySoundFromEntityS2CPacketAccessor.java b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/accessors/PlaySoundFromEntityS2CPacketAccessor.java new file mode 100644 index 00000000..f8bbd1cb --- /dev/null +++ b/polymer-virtual-entity/src/main/java/eu/pb4/polymer/virtualentity/mixin/accessors/PlaySoundFromEntityS2CPacketAccessor.java @@ -0,0 +1,36 @@ +package eu.pb4.polymer.virtualentity.mixin.accessors; + +import net.minecraft.network.packet.s2c.play.PlaySoundFromEntityS2CPacket; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(PlaySoundFromEntityS2CPacket.class) +public interface PlaySoundFromEntityS2CPacketAccessor { + @Mutable + @Accessor + void setSound(RegistryEntry sound); + + @Mutable + @Accessor + void setCategory(SoundCategory category); + + @Mutable + @Accessor + void setEntityId(int entityId); + + @Mutable + @Accessor + void setVolume(float volume); + + @Mutable + @Accessor + void setPitch(float pitch); + + @Mutable + @Accessor + void setSeed(long seed); +} diff --git a/polymer-virtual-entity/src/main/resources/fabric.mod.json b/polymer-virtual-entity/src/main/resources/fabric.mod.json index c50ad745..2303b282 100644 --- a/polymer-virtual-entity/src/main/resources/fabric.mod.json +++ b/polymer-virtual-entity/src/main/resources/fabric.mod.json @@ -25,8 +25,8 @@ ], "depends": { - "minecraft": ">=1.20", - "fabricloader": ">=0.14.0" + "polymer-common": ">=${version}", + "fabricloader": ">=0.15.0" }, "custom": { "modmenu": { diff --git a/polymer-virtual-entity/src/main/resources/polymer-virtual-entity.mixins.json b/polymer-virtual-entity/src/main/resources/polymer-virtual-entity.mixins.json index 272ec6c4..f6e7e9d1 100644 --- a/polymer-virtual-entity/src/main/resources/polymer-virtual-entity.mixins.json +++ b/polymer-virtual-entity/src/main/resources/polymer-virtual-entity.mixins.json @@ -23,6 +23,7 @@ "accessors.EntityTrackerEntryAccessor", "accessors.InteractionEntityAccessor", "accessors.ItemDisplayEntityAccessor", + "accessors.PlaySoundFromEntityS2CPacketAccessor", "accessors.TextDisplayEntityAccessor", "accessors.ThreadedAnvilChunkStorageAccessor", "block.ServerWorldMixin",