Skip to content

Commit

Permalink
Port to 1.21 (#511)
Browse files Browse the repository at this point in the history
* 1.21-pre1

* progress

* fix MixinGameRenderer

* update the access widener

* pass removal reason in the player respawn event

* Update MixinGameRenderer.java

* fix more mixins

* fix more 1.21 stuff

* Update TestRegistries.java

* remove enchantments (it's data driven)

* rename 1.20.6 files to 1.21

* update to 1.21-pre4

* lol

* fix neoforge

* Finish port to 1.21

---------

Co-authored-by: shedaniel <[email protected]>
  • Loading branch information
Jab125 and shedaniel authored Jun 13, 2024
1 parent 7f76087 commit 289ed46
Show file tree
Hide file tree
Showing 42 changed files with 162 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- '**.properties'
- '**/src/**'
branches:
- "1.20.6"
- "1.21"
types: [ opened, synchronize, reopened ]
jobs:
validate-gradle:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '**/src/**'
- '.github/**'
branches:
- "1.20.6"
- "1.21"
workflow_dispatch:
inputs:
norelease:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import dev.architectury.hooks.client.screen.ScreenAccess;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
Expand Down Expand Up @@ -81,7 +82,7 @@ interface RenderHud {
* @param graphics The graphics context.
* @param tickDelta The tick delta.
*/
void renderHud(GuiGraphics graphics, float tickDelta);
void renderHud(GuiGraphics graphics, DeltaTracker deltaTracker);
}

@Environment(EnvType.CLIENT)
Expand Down Expand Up @@ -136,7 +137,7 @@ interface ScreenRenderPre {
* @return A {@link EventResult} determining the outcome of the event,
* the vanilla render may be cancelled by the result.
*/
EventResult render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
EventResult render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, DeltaTracker delta);
}

@Environment(EnvType.CLIENT)
Expand All @@ -151,7 +152,7 @@ interface ScreenRenderPost {
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param delta The current tick delta.
*/
void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, DeltaTracker delta);
}

@Environment(EnvType.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface PlayerEvent {
*/
Event<PlayerQuit> PLAYER_QUIT = EventFactory.createLoop();
/**
* @see PlayerRespawn#respawn(ServerPlayer, boolean)
* @see PlayerRespawn#respawn(ServerPlayer, boolean, net.minecraft.world.entity.Entity.RemovalReason)
*/
Event<PlayerRespawn> PLAYER_RESPAWN = EventFactory.createLoop();
/**
Expand Down Expand Up @@ -129,7 +129,7 @@ interface PlayerRespawn {
* @param newPlayer The respawned player.
* @param conqueredEnd Whether the player has conquered the end. This is true when the player joined the end and now is leaving it. {@link ServerPlayer#wonGame}
*/
void respawn(ServerPlayer newPlayer, boolean conqueredEnd);
void respawn(ServerPlayer newPlayer, boolean conqueredEnd, Entity.RemovalReason removalReason);
}

interface PlayerClone {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static NetworkChannel create(ResourceLocation id) {
public <T> void register(Class<T> type, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, BiConsumer<T, Supplier<PacketContext>> messageConsumer) {
// TODO: this is pretty wasteful; add a way to specify custom or numeric ids
var s = UUID.nameUUIDFromBytes(type.getName().getBytes(StandardCharsets.UTF_8)).toString().replace("-", "");
var info = new MessageInfo<T>(new ResourceLocation(id + "/" + s), encoder, decoder, messageConsumer);
var info = new MessageInfo<T>(ResourceLocation.parse(id + "/" + s), encoder, decoder, messageConsumer);
encoders.put(type, info);
NetworkManager.NetworkReceiver<RegistryFriendlyByteBuf> receiver = (buf, context) -> {
info.messageConsumer.accept(info.decoder.apply(buf), () -> context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -202,7 +203,7 @@ public static boolean canPlayerReceive(ServerPlayer player, CustomPacketPayload.
* @see Entity#getAddEntityPacket()
*/
@ExpectPlatform
public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity) {
public static Packet<ClientGamePacketListener> createAddEntityPacket(Entity entity, ServerEntity serverEntity) {
throw new AssertionError();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
Expand All @@ -34,6 +35,7 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;

Expand All @@ -43,15 +45,15 @@
* @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 ResourceLocation PACKET_ID = ResourceLocation.fromNamespaceAndPath("architectury", "spawn_entity_packet");
private static final CustomPacketPayload.Type<PacketPayload> PACKET_TYPE = new CustomPacketPayload.Type<>(PACKET_ID);
private static final StreamCodec<RegistryFriendlyByteBuf, PacketPayload> PACKET_CODEC = CustomPacketPayload.codec(PacketPayload::write, PacketPayload::new);

public static Packet<ClientGamePacketListener> create(Entity entity) {
public static Packet<ClientGamePacketListener> create(Entity entity, ServerEntity serverEntity) {
if (entity.level().isClientSide()) {
throw new IllegalStateException("SpawnPacketUtil.create called on the logical client!");
}
return (Packet<ClientGamePacketListener>) NetworkManager.toPacket(NetworkManager.s2c(), new PacketPayload(entity), entity.registryAccess());
return (Packet<ClientGamePacketListener>) NetworkManager.toPacket(NetworkManager.s2c(), new PacketPayload(entity, serverEntity), entity.registryAccess());
}

public static void register() {
Expand Down Expand Up @@ -106,9 +108,16 @@ public PacketPayload(RegistryFriendlyByteBuf buf) {
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(),
public PacketPayload(Entity entity, ServerEntity serverEntity) {
this(entity.getType(), entity.getUUID(), entity.getId(), serverEntity.getPositionBase().x(),
serverEntity.getPositionBase().y(), serverEntity.getPositionBase().z(), serverEntity.getLastSentXRot(),
serverEntity.getLastSentYRot(), serverEntity.getLastSentYHeadRot(), serverEntity.getLastSentMovement().x,
serverEntity.getLastSentMovement().y, serverEntity.getLastSentMovement().z, saveExtra(entity));
}

public PacketPayload(Entity entity, BlockPos pos) {
this(entity.getType(), entity.getUUID(), entity.getId(), pos.getX(),
pos.getY(), pos.getZ(), entity.getXRot(), entity.getYRot(), entity.getYHeadRot(),
entity.getDeltaMovement().x, entity.getDeltaMovement().y, entity.getDeltaMovement().z, saveExtra(entity));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public MessageType registerS2C(String id, MessageDecoder<BaseS2CMessage> decoder
*/
@ApiStatus.Experimental
public MessageType registerS2C(String id, MessageDecoder<BaseS2CMessage> decoder, List<PacketTransformer> transformers) {
MessageType messageType = new MessageType(this, new ResourceLocation(namespace, id), NetworkManager.s2c());
MessageType messageType = new MessageType(this, ResourceLocation.fromNamespaceAndPath(namespace, id), NetworkManager.s2c());

if (Platform.getEnvironment() == Env.CLIENT) {
NetworkManager.NetworkReceiver<RegistryFriendlyByteBuf> receiver = decoder.createReceiver();
Expand Down Expand Up @@ -107,7 +107,7 @@ public MessageType registerC2S(String id, MessageDecoder<BaseC2SMessage> decoder
*/
@ApiStatus.Experimental
public MessageType registerC2S(String id, MessageDecoder<BaseC2SMessage> decoder, List<PacketTransformer> transformers) {
MessageType messageType = new MessageType(this, new ResourceLocation(namespace, id), NetworkManager.c2s());
MessageType messageType = new MessageType(this, ResourceLocation.fromNamespaceAndPath(namespace, id), NetworkManager.c2s());
NetworkManager.NetworkReceiver<RegistryFriendlyByteBuf> receiver = decoder.createReceiver();
NetworkManager.registerReceiver(NetworkManager.c2s(), messageType.getId(), transformers, receiver);
return messageType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public <R extends T> RegistrySupplier<R> register(String id, Supplier<? extends
throw new NullPointerException("You must create the deferred register with a mod id to register entries without the namespace!");
}

return register(new ResourceLocation(modId, id), supplier);
return register(ResourceLocation.fromNamespaceAndPath(modId, id), supplier);
}

public <R extends T> RegistrySupplier<R> register(ResourceLocation id, Supplier<? extends R> supplier) {
Expand Down
5 changes: 0 additions & 5 deletions common/src/main/resources/architectury.accessWidener
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ accessible class net/minecraft/client/resources/model/AtlasSet$AtlasEntry
accessible field net/minecraft/world/item/SpawnEggItem BY_ID Ljava/util/Map;
accessible field net/minecraft/world/item/SpawnEggItem defaultType Lnet/minecraft/world/entity/EntityType;
mutable field net/minecraft/world/item/SpawnEggItem defaultType Lnet/minecraft/world/entity/EntityType;
accessible field net/minecraft/world/item/RecordItem BY_NAME Ljava/util/Map;
accessible field net/minecraft/client/particle/ParticleEngine textureAtlas Lnet/minecraft/client/renderer/texture/TextureAtlas;
accessible class net/minecraft/client/particle/ParticleEngine$MutableSpriteSet
accessible field net/minecraft/client/particle/ParticleEngine$MutableSpriteSet sprites Ljava/util/List;
Expand All @@ -141,7 +140,6 @@ accessible field net/minecraft/client/multiplayer/MultiPlayerGameMode connection

# Constructors of non-abstract item classes
transitive-accessible method net/minecraft/world/item/DiggerItem <init> (Lnet/minecraft/world/item/Tier;Lnet/minecraft/tags/TagKey;Lnet/minecraft/world/item/Item$Properties;)V
transitive-accessible method net/minecraft/world/item/RecordItem <init> (ILnet/minecraft/sounds/SoundEvent;Lnet/minecraft/world/item/Item$Properties;I)V

# Constructors of non-abstract block classes
transitive-accessible method net/minecraft/world/level/block/AttachedStemBlock <init> (Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
Expand Down Expand Up @@ -253,7 +251,6 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard TRANS
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_LIGHTMAP_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_TEX_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_TEX_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_TEX_LIGHTMAP_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
Expand Down Expand Up @@ -282,11 +279,9 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDE
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_LEASH_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_WATER_MASK_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_OUTLINE_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ARMOR_GLINT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ARMOR_ENTITY_GLINT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GLINT_TRANSLUCENT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GLINT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GLINT_DIRECT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_GLINT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_ENTITY_GLINT_DIRECT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_CRUMBLING_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

public class DyeColorHooksImpl {
public static int getColorValue(DyeColor color) {
var colors = color.getTextureDiffuseColors();
return ((int) (colors[0] * 255.0F + 0.5D) & 255) << 16 | ((int) (colors[1] * 255.0F + 0.5D) & 255) << 8 | (int) (colors[2] * 255.0F + 0.5D);
return color.getTextureDiffuseColor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.chunk.status.ChunkType;
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
import net.minecraft.world.level.chunk.storage.RegionStorageInfo;
import net.minecraft.world.level.levelgen.blending.BlendingData;
import net.minecraft.world.level.lighting.LevelLightEngine;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -43,7 +44,7 @@
@Mixin(ChunkSerializer.class)
public class MixinChunkSerializer {
@Inject(method = "read", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void load(ServerLevel serverLevel, PoiManager poiManager, ChunkPos chunkPos, CompoundTag compoundTag,
private static void load(ServerLevel serverLevel, PoiManager poiManager, RegionStorageInfo regionStorageInfo, ChunkPos chunkPos, CompoundTag compoundTag,
CallbackInfoReturnable<ProtoChunk> cir, ChunkPos chunkPos2, UpgradeData upgradeData,
boolean bl, ListTag listTag, int i, LevelChunkSection[] levelChunkSections, boolean bl2,
ChunkSource chunkSource, LevelLightEngine levelLightEngine, Registry<Biome> registry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void hurt(DamageSource damageSource, float f, CallbackInfoReturnable<Boo
}

@Inject(method = "getEquipmentSlotForItem", at = @At("HEAD"), cancellable = true)
private static void getEquipmentSlotForItem(ItemStack stack, CallbackInfoReturnable<EquipmentSlot> cir) {
private void getEquipmentSlotForItem(ItemStack stack, CallbackInfoReturnable<EquipmentSlot> cir) {
var item = stack.getItem();
if (item instanceof ItemExtension extension) {
var slot = extension.getCustomEquipmentSlot(stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -43,7 +44,7 @@ private void remove(ServerPlayer serverPlayer, CallbackInfo ci) {
}

@Inject(method = "respawn", at = @At("RETURN"))
private void respawn(ServerPlayer serverPlayer, boolean bl, CallbackInfoReturnable<ServerPlayer> cir) {
PlayerEvent.PLAYER_RESPAWN.invoker().respawn(cir.getReturnValue(), bl);
private void respawn(ServerPlayer serverPlayer, boolean bl, Entity.RemovalReason removalReason, CallbackInfoReturnable<ServerPlayer> cir) {
PlayerEvent.PLAYER_RESPAWN.invoker().respawn(cir.getReturnValue(), bl, removalReason);
}
}
Loading

0 comments on commit 289ed46

Please sign in to comment.