From 8effe4a56df26e13610c599ac632baa1a6ac4b2a Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 12 Apr 2024 15:51:56 +0900 Subject: [PATCH] Port to 1.20.5-pre1 Signed-off-by: shedaniel --- .../events/client/ClientTooltipEvent.java | 11 +- .../networking/NetworkChannel.java | 1 + .../networking/NetworkManager.java | 33 ++++- .../networking/SpawnEntityPacket.java | 129 +++++++++++------- .../particle/ParticleProviderRegistry.java | 8 +- .../main/resources/architectury.accessWidener | 2 +- .../event/fabric/EventHandlerImpl.java | 2 +- .../fabric/ParticleProviderRegistryImpl.java | 8 +- gradle.properties | 10 +- settings.gradle | 8 +- 10 files changed, 134 insertions(+), 78 deletions(-) diff --git a/common/src/main/java/dev/architectury/event/events/client/ClientTooltipEvent.java b/common/src/main/java/dev/architectury/event/events/client/ClientTooltipEvent.java index 80a91cc27..64dd037de 100644 --- a/common/src/main/java/dev/architectury/event/events/client/ClientTooltipEvent.java +++ b/common/src/main/java/dev/architectury/event/events/client/ClientTooltipEvent.java @@ -38,7 +38,7 @@ @Environment(EnvType.CLIENT) public interface ClientTooltipEvent { /** - * @see Item#append(ItemStack, List, TooltipFlag) + * @see Item#append(ItemStack, List, net.minecraft.world.item.Item.TooltipContext, TooltipFlag) */ Event ITEM = EventFactory.createLoop(); /** @@ -73,11 +73,12 @@ interface Item { * Equivalent to Forge's {@code ItemTooltipEvent} event and * Fabric's {@code ItemTooltipCallback}. * - * @param stack The rendered stack. - * @param lines The mutable list of tooltip components. - * @param flag A flag indicating if advanced mode is active. + * @param stack The rendered stack. + * @param lines The mutable list of tooltip components. + * @param tooltipContext The tooltip context. + * @param flag A flag indicating if advanced mode is active. */ - void append(ItemStack stack, List lines, TooltipFlag flag); + void append(ItemStack stack, List lines, net.minecraft.world.item.Item.TooltipContext tooltipContext, TooltipFlag flag); } @Environment(EnvType.CLIENT) diff --git a/common/src/main/java/dev/architectury/networking/NetworkChannel.java b/common/src/main/java/dev/architectury/networking/NetworkChannel.java index c0c560b42..cb4ead8fd 100644 --- a/common/src/main/java/dev/architectury/networking/NetworkChannel.java +++ b/common/src/main/java/dev/architectury/networking/NetworkChannel.java @@ -47,6 +47,7 @@ /** * Forge {@code SimpleChannel} like network wrapper of {@link NetworkManager}. */ +@Deprecated(forRemoval = true) public final class NetworkChannel { private final ResourceLocation id; private final Map, MessageInfo> encoders = Maps.newHashMap(); diff --git a/common/src/main/java/dev/architectury/networking/NetworkManager.java b/common/src/main/java/dev/architectury/networking/NetworkManager.java index 7a6e9c4f0..db4b7b43a 100644 --- a/common/src/main/java/dev/architectury/networking/NetworkManager.java +++ b/common/src/main/java/dev/architectury/networking/NetworkManager.java @@ -51,6 +51,7 @@ public final class NetworkManager { * For S2C types, {@link #registerReceiver} should be called on the client side, * while {@link #registerS2CPayloadType} should be called on the server side. */ + @Deprecated(forRemoval = true) public static void registerS2CPayloadType(ResourceLocation id) { NetworkAggregator.registerS2CType(id, List.of()); } @@ -67,6 +68,7 @@ public static void registerS2CPayloadType(Custom * For S2C types, {@link #registerReceiver} should be called on the client side, * while {@link #registerS2CPayloadType} should be called on the server side. */ + @Deprecated(forRemoval = true) public static void registerS2CPayloadType(ResourceLocation id, List packetTransformers) { NetworkAggregator.registerS2CType(id, packetTransformers); } @@ -79,11 +81,13 @@ public static void registerS2CPayloadType(Custom NetworkAggregator.registerS2CType(type, codec, packetTransformers); } + @Deprecated(forRemoval = true) public static void registerReceiver(Side side, ResourceLocation id, NetworkReceiver receiver) { registerReceiver(side, id, Collections.emptyList(), receiver); } @ApiStatus.Experimental + @Deprecated(forRemoval = true) public static void registerReceiver(Side side, ResourceLocation id, List packetTransformers, NetworkReceiver receiver) { NetworkAggregator.registerReceiver(side, id, packetTransformers, receiver); } @@ -97,20 +101,33 @@ public static void registerReceiver(Side side, C NetworkAggregator.registerReceiver(side, id, codec, packetTransformers, receiver); } - @Deprecated + @Deprecated(forRemoval = true) public static Packet toPacket(Side side, ResourceLocation id, RegistryFriendlyByteBuf buf) { SinglePacketCollector sink = new SinglePacketCollector(null); collectPackets(sink, side, id, buf); return sink.getPacket(); } - @Deprecated + @Deprecated(forRemoval = true) public static List> toPackets(Side side, ResourceLocation id, RegistryFriendlyByteBuf buf) { PacketCollector sink = new PacketCollector(null); collectPackets(sink, side, id, buf); return sink.collect(); } + public static Packet toPacket(Side side, T payload, RegistryAccess access) { + SinglePacketCollector sink = new SinglePacketCollector(null); + collectPackets(sink, side, payload, access); + return sink.getPacket(); + } + + public static List> toPackets(Side side, T payload, RegistryAccess access) { + PacketCollector sink = new PacketCollector(null); + collectPackets(sink, side, payload, access); + return sink.collect(); + } + + @Deprecated(forRemoval = true) public static void collectPackets(PacketSink sink, Side side, ResourceLocation id, RegistryFriendlyByteBuf buf) { NetworkAggregator.collectPackets(sink, side, id, buf); } @@ -119,15 +136,18 @@ public static void collectPackets(PacketSink sin NetworkAggregator.collectPackets(sink, side, payload, access); } + @Deprecated(forRemoval = true) public static void sendToPlayer(ServerPlayer player, ResourceLocation id, RegistryFriendlyByteBuf buf) { collectPackets(PacketSink.ofPlayer(player), serverToClient(), id, buf); } + @Deprecated(forRemoval = true) public static void sendToPlayers(Iterable players, ResourceLocation id, RegistryFriendlyByteBuf buf) { collectPackets(PacketSink.ofPlayers(players), serverToClient(), id, buf); } @Environment(EnvType.CLIENT) + @Deprecated(forRemoval = true) public static void sendToServer(ResourceLocation id, RegistryFriendlyByteBuf buf) { collectPackets(PacketSink.client(), clientToServer(), id, buf); } @@ -160,6 +180,15 @@ public static boolean canPlayerReceive(ServerPlayer player, ResourceLocation id) throw new AssertionError(); } + @Environment(EnvType.CLIENT) + public static boolean canServerReceive(CustomPacketPayload.Type type) { + return canServerReceive(type.id()); + } + + public static boolean canPlayerReceive(ServerPlayer player, CustomPacketPayload.Type type) { + return canPlayerReceive(player, type.id()); + } + /** * Easy to use utility method to create an entity spawn packet. * This packet is needed everytime any mod adds a non-living entity. diff --git a/common/src/main/java/dev/architectury/networking/SpawnEntityPacket.java b/common/src/main/java/dev/architectury/networking/SpawnEntityPacket.java index d5e993f59..bc517fe40 100644 --- a/common/src/main/java/dev/architectury/networking/SpawnEntityPacket.java +++ b/common/src/main/java/dev/architectury/networking/SpawnEntityPacket.java @@ -20,51 +20,42 @@ package dev.architectury.networking; import dev.architectury.extensions.network.EntitySpawnExtension; +import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; + +import java.util.UUID; /** * @see net.minecraft.network.protocol.game.ClientboundAddEntityPacket */ public class SpawnEntityPacket { private static final ResourceLocation PACKET_ID = new ResourceLocation("architectury", "spawn_entity_packet"); + private static final CustomPacketPayload.Type PACKET_TYPE = new CustomPacketPayload.Type<>(PACKET_ID); + private static final StreamCodec PACKET_CODEC = CustomPacketPayload.codec(PacketPayload::write, PacketPayload::new); public static Packet create(Entity entity) { if (entity.level().isClientSide()) { throw new IllegalStateException("SpawnPacketUtil.create called on the logical client!"); } - var buffer = new RegistryFriendlyByteBuf(Unpooled.buffer(), entity.registryAccess()); - buffer.writeVarInt(BuiltInRegistries.ENTITY_TYPE.getId(entity.getType())); - buffer.writeUUID(entity.getUUID()); - buffer.writeVarInt(entity.getId()); - var position = entity.position(); - buffer.writeDouble(position.x); - buffer.writeDouble(position.y); - buffer.writeDouble(position.z); - buffer.writeFloat(entity.getXRot()); - buffer.writeFloat(entity.getYRot()); - buffer.writeFloat(entity.getYHeadRot()); - var deltaMovement = entity.getDeltaMovement(); - buffer.writeDouble(deltaMovement.x); - buffer.writeDouble(deltaMovement.y); - buffer.writeDouble(deltaMovement.z); - if (entity instanceof EntitySpawnExtension ext) { - ext.saveAdditionalSpawnData(buffer); - } - return (Packet) NetworkManager.toPacket(NetworkManager.s2c(), PACKET_ID, buffer); + return (Packet) NetworkManager.toPacket(NetworkManager.s2c(), new PacketPayload(entity), entity.registryAccess()); } public static void register() { - NetworkManager.registerS2CPayloadType(PACKET_ID); + NetworkManager.registerS2CPayloadType(PACKET_TYPE, PACKET_CODEC); } @@ -72,52 +63,86 @@ public static void register() { public static class Client { @Environment(EnvType.CLIENT) public static void register() { - NetworkManager.registerReceiver(NetworkManager.s2c(), PACKET_ID, Client::receive); + NetworkManager.registerReceiver(NetworkManager.s2c(), PACKET_TYPE, PACKET_CODEC, Client::receive); } @Environment(EnvType.CLIENT) - public static void receive(FriendlyByteBuf buf, NetworkManager.PacketContext context) { - var entityTypeId = buf.readVarInt(); - var uuid = buf.readUUID(); - var id = buf.readVarInt(); - var x = buf.readDouble(); - var y = buf.readDouble(); - var z = buf.readDouble(); - var xRot = buf.readFloat(); - var yRot = buf.readFloat(); - var yHeadRot = buf.readFloat(); - var deltaX = buf.readDouble(); - var deltaY = buf.readDouble(); - var deltaZ = buf.readDouble(); - // Retain this buffer so we can use it in the queued task (EntitySpawnExtension) - buf.retain(); + private static void receive(PacketPayload payload, NetworkManager.PacketContext context) { context.queue(() -> { - var entityType = BuiltInRegistries.ENTITY_TYPE.byId(entityTypeId); - if (entityType == null) { - throw new IllegalStateException("Entity type (" + entityTypeId + ") is unknown, spawning at (" + x + ", " + y + ", " + z + ")"); - } if (Minecraft.getInstance().level == null) { throw new IllegalStateException("Client world is null!"); } - var entity = entityType.create(Minecraft.getInstance().level); + var entity = payload.entityType().create(Minecraft.getInstance().level); if (entity == null) { throw new IllegalStateException("Created entity is null!"); } - entity.setUUID(uuid); - entity.setId(id); - entity.syncPacketPositionCodec(x, y, z); - entity.moveTo(x, y, z); - entity.setXRot(xRot); - entity.setYRot(yRot); - entity.setYHeadRot(yHeadRot); - entity.setYBodyRot(yHeadRot); + entity.setUUID(payload.uuid()); + entity.setId(payload.id()); + entity.syncPacketPositionCodec(payload.x(), payload.y(), payload.z()); + entity.moveTo(payload.x(), payload.y(), payload.z()); + entity.setXRot(payload.xRot()); + entity.setYRot(payload.yRot()); + entity.setYHeadRot(payload.yHeadRot()); + entity.setYBodyRot(payload.yHeadRot()); if (entity instanceof EntitySpawnExtension ext) { + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(payload.data()), context.registryAccess()); ext.loadAdditionalSpawnData(buf); + buf.release(); } - buf.release(); Minecraft.getInstance().level.addEntity(entity); - entity.lerpMotion(deltaX, deltaY, deltaZ); + entity.lerpMotion(payload.deltaX(), payload.deltaY(), payload.deltaZ()); }); } } + + private record PacketPayload(EntityType entityType, UUID uuid, int id, double x, double y, double z, float xRot, + float yRot, + float yHeadRot, + double deltaX, double deltaY, double deltaZ, + byte[] data) implements CustomPacketPayload { + public PacketPayload(RegistryFriendlyByteBuf buf) { + this(ByteBufCodecs.registry(Registries.ENTITY_TYPE).decode(buf), buf.readUUID(), buf.readVarInt(), buf.readDouble(), buf.readDouble(), buf.readDouble(), + buf.readFloat(), buf.readFloat(), buf.readFloat(), buf.readDouble(), buf.readDouble(), buf.readDouble(), + buf.readByteArray()); + } + + public PacketPayload(Entity entity) { + this(entity.getType(), entity.getUUID(), entity.getId(), entity.getX(), + entity.getY(), entity.getZ(), entity.getXRot(), entity.getYRot(), entity.getYHeadRot(), + entity.getDeltaMovement().x, entity.getDeltaMovement().y, entity.getDeltaMovement().z, saveExtra(entity)); + } + + private static byte[] saveExtra(Entity entity) { + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); + try { + if (entity instanceof EntitySpawnExtension ext) { + ext.saveAdditionalSpawnData(buf); + } + return ByteBufUtil.getBytes(buf); + } finally { + buf.release(); + } + } + + public void write(RegistryFriendlyByteBuf buf) { + ByteBufCodecs.registry(Registries.ENTITY_TYPE).encode(buf, entityType); + buf.writeUUID(uuid); + buf.writeVarInt(id); + buf.writeDouble(x); + buf.writeDouble(y); + buf.writeDouble(z); + buf.writeFloat(xRot); + buf.writeFloat(yRot); + buf.writeFloat(yHeadRot); + buf.writeDouble(deltaX); + buf.writeDouble(deltaY); + buf.writeDouble(deltaZ); + buf.writeByteArray(data); + } + + @Override + public Type type() { + return PACKET_TYPE; + } + } } diff --git a/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java b/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java index 63c4104d6..771decf77 100644 --- a/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java +++ b/common/src/main/java/dev/architectury/registry/client/particle/ParticleProviderRegistry.java @@ -60,14 +60,14 @@ public static void register(RegistrySupplier register(it, provider)); } - @ExpectPlatform + // @ExpectPlatform public static void register(ParticleType type, ParticleProvider provider) { - throw new AssertionError(); + // throw new AssertionError(); } - @ExpectPlatform + // @ExpectPlatform public static void register(ParticleType type, DeferredParticleProvider provider) { - throw new AssertionError(); + // throw new AssertionError(); } @FunctionalInterface diff --git a/common/src/main/resources/architectury.accessWidener b/common/src/main/resources/architectury.accessWidener index a9325b609..7f55f29db 100644 --- a/common/src/main/resources/architectury.accessWidener +++ b/common/src/main/resources/architectury.accessWidener @@ -172,7 +172,7 @@ transitive-accessible method net/minecraft/world/level/block/DecoratedPotBlock < transitive-accessible method net/minecraft/world/level/block/DirtPathBlock (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V transitive-accessible method net/minecraft/world/level/block/DispenserBlock (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V transitive-accessible method net/minecraft/world/level/block/DoorBlock (Lnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V -transitive-accessible method net/minecraft/world/level/block/EnchantmentTableBlock (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V +transitive-accessible method net/minecraft/world/level/block/EnchantingTableBlock (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V transitive-accessible method net/minecraft/world/level/block/EndGatewayBlock (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V transitive-accessible method net/minecraft/world/level/block/EndPortalBlock (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V transitive-accessible method net/minecraft/world/level/block/EndRodBlock (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V diff --git a/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java b/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java index e7f035f17..6cd47e392 100644 --- a/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java +++ b/fabric/src/main/java/dev/architectury/event/fabric/EventHandlerImpl.java @@ -53,7 +53,7 @@ public static void registerClient() { ClientTickEvents.START_WORLD_TICK.register(instance -> ClientTickEvent.CLIENT_LEVEL_PRE.invoker().tick(instance)); ClientTickEvents.END_WORLD_TICK.register(instance -> ClientTickEvent.CLIENT_LEVEL_POST.invoker().tick(instance)); - ItemTooltipCallback.EVENT.register((itemStack, tooltipFlag, list) -> ClientTooltipEvent.ITEM.invoker().append(itemStack, list, tooltipFlag)); + ItemTooltipCallback.EVENT.register((itemStack, tooltipContext, tooltipFlag, list) -> ClientTooltipEvent.ITEM.invoker().append(itemStack, list, tooltipContext, tooltipFlag)); HudRenderCallback.EVENT.register((graphics, tickDelta) -> ClientGuiEvent.RENDER_HUD.invoker().renderHud(graphics, tickDelta)); ClientCommandRegistrationCallback.EVENT.register((dispatcher, access) -> { diff --git a/fabric/src/main/java/dev/architectury/registry/client/particle/fabric/ParticleProviderRegistryImpl.java b/fabric/src/main/java/dev/architectury/registry/client/particle/fabric/ParticleProviderRegistryImpl.java index a3984a121..dc47352f7 100644 --- a/fabric/src/main/java/dev/architectury/registry/client/particle/fabric/ParticleProviderRegistryImpl.java +++ b/fabric/src/main/java/dev/architectury/registry/client/particle/fabric/ParticleProviderRegistryImpl.java @@ -20,8 +20,8 @@ package dev.architectury.registry.client.particle.fabric; import dev.architectury.registry.client.particle.ParticleProviderRegistry; -import net.fabricmc.fabric.api.client.particle.v1.FabricSpriteProvider; -import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; +//import net.fabricmc.fabric.api.client.particle.v1.FabricSpriteProvider; +//import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; import net.minecraft.client.particle.ParticleProvider; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -32,7 +32,7 @@ import java.util.List; public class ParticleProviderRegistryImpl { - public record ExtendedSpriteSetImpl( + /*public record ExtendedSpriteSetImpl( FabricSpriteProvider delegate ) implements ParticleProviderRegistry.ExtendedSpriteSet { @Override @@ -63,5 +63,5 @@ public static void register(ParticleType type, Pa public static void register(ParticleType type, ParticleProviderRegistry.DeferredParticleProvider provider) { ParticleFactoryRegistry.getInstance().register(type, sprites -> provider.create(new ExtendedSpriteSetImpl(sprites))); - } + }*/ } diff --git a/gradle.properties b/gradle.properties index f31d1ca80..403f71ede 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,10 @@ org.gradle.jvmargs=-Xmx6G org.gradle.daemon=false -platforms=fabric,neoforge +platforms=fabric -minecraft_version=24w14a -supported_version=1.20.5 (24w14a) +minecraft_version=1.20.5-pre1 +supported_version=1.20.5-pre1 artifact_type=beta @@ -15,14 +15,14 @@ maven_group=dev.architectury version_suffix=-beta fabric_loader_version=0.15.9 -fabric_api_version=0.96.14+1.20.5 +fabric_api_version=0.96.15+1.20.5 mod_menu_version=9.0.0 forge_version=49.0.14 neoforge_version=20.5.0-alpha.24w14a.20240407.201521 # Set to empty if not snapshots -neoforge_pr=787 +neoforge_pr=794 curseforge_id=419699 modrinth_id=lhGA9TYQ diff --git a/settings.gradle b/settings.gradle index aab12c8cc..8c6bf2876 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,18 +7,18 @@ pluginManagement { } } -if (JavaVersion.current().ordinal() + 1 < 17) { - throw new IllegalStateException("Please run gradle with Java 17+!") +if (JavaVersion.current().ordinal() + 1 < 21) { + throw new IllegalStateException("Please run gradle with Java 21+!") } include("common") include("fabric") //include("forge") //include("minecraftforge") -include("neoforge") +//include("neoforge") include("testmod-common") include("testmod-fabric") //include("testmod-forge") -include("testmod-neoforge") +//include("testmod-neoforge") rootProject.name = "architectury"