diff --git a/fabric-data-attachment-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/gametest/AttachmentCopyTests.java b/fabric-data-attachment-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/gametest/AttachmentCopyTests.java index def57d8c71..90f1db04b0 100644 --- a/fabric-data-attachment-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/gametest/AttachmentCopyTests.java +++ b/fabric-data-attachment-api-v1/src/testmod/java/net/fabricmc/fabric/test/attachment/gametest/AttachmentCopyTests.java @@ -28,6 +28,7 @@ import net.minecraft.test.GameTestException; import net.minecraft.test.TestContext; import net.minecraft.util.Identifier; +import net.minecraft.world.TeleportTarget; import net.minecraft.world.World; import net.fabricmc.fabric.api.attachment.v1.AttachmentRegistry; @@ -56,7 +57,7 @@ public void testCrossWorldTeleport(TestContext context) { entity.setAttached(DUMMY, () -> 10); entity.setAttached(COPY_ON_DEATH, () -> 10); - Entity moved = entity.moveToWorld(end); + Entity moved = entity.moveToWorld(() -> new TeleportTarget(end)); if (moved == null) throw new GameTestException("Cross-world teleportation failed"); IntSupplier attached1 = moved.getAttached(DUMMY); diff --git a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/api/dimension/v1/FabricDimensions.java b/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/api/dimension/v1/FabricDimensions.java index fa4251ec96..074fd0b102 100644 --- a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/api/dimension/v1/FabricDimensions.java +++ b/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/api/dimension/v1/FabricDimensions.java @@ -20,7 +20,6 @@ import org.jetbrains.annotations.Nullable; import net.minecraft.entity.Entity; -import net.minecraft.server.world.ServerWorld; import net.minecraft.world.TeleportTarget; import net.fabricmc.fabric.impl.dimension.FabricDimensionInternals; @@ -33,19 +32,16 @@ private FabricDimensions() { throw new AssertionError(); } + // TODO 1.21 - This is just a Vanilla wrapper now /** * Teleports an entity to a different dimension, placing it at the specified destination. * - *

Using this method will circumvent Vanilla's portal placement code. - * *

When teleporting to another dimension, the entity may be replaced with a new entity in the target * dimension. This is not the case for players, but needs to be accounted for by the caller. * * @param teleported the entity to teleport - * @param destination the dimension the entity will be teleported to * @param target where the entity will be placed in the target world. * As in Vanilla, the target's velocity is not applied to players. - * If target is null, the entity will not be teleported. * @param the type of the teleported entity * @return Returns the teleported entity in the target dimension, which may be a new entity or teleported, * depending on the entity type. @@ -53,10 +49,10 @@ private FabricDimensions() { * @apiNote this method must be called from the main server thread */ @Nullable - public static E teleport(E teleported, ServerWorld destination, TeleportTarget target) { + public static E teleport(E teleported, TeleportTarget target) { Preconditions.checkNotNull(target, "A target must be provided"); Preconditions.checkState(!teleported.getWorld().isClient, "Entities can only be teleported on the server side"); - return FabricDimensionInternals.changeDimension(teleported, destination, target); + return FabricDimensionInternals.changeDimension(teleported, target); } } diff --git a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/impl/dimension/FabricDimensionInternals.java b/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/impl/dimension/FabricDimensionInternals.java index e7db168441..d2200b372e 100644 --- a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/impl/dimension/FabricDimensionInternals.java +++ b/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/impl/dimension/FabricDimensionInternals.java @@ -29,30 +29,24 @@ private FabricDimensionInternals() { } @SuppressWarnings("unchecked") - public static E changeDimension(E teleported, ServerWorld dimension, TeleportTarget target) { + public static E changeDimension(E teleported, TeleportTarget target) { Preconditions.checkArgument(!teleported.getWorld().isClient, "Entities can only be teleported on the server side"); Preconditions.checkArgument(Thread.currentThread() == ((ServerWorld) teleported.getWorld()).getServer().getThread(), "Entities must be teleported from the main server thread"); - try { - ((Teleportable) teleported).fabric_setCustomTeleportTarget(target); - - // Fast path for teleporting within the same dimension. - if (teleported.getWorld() == dimension) { - if (teleported instanceof ServerPlayerEntity serverPlayerEntity) { - serverPlayerEntity.networkHandler.requestTeleport(target.position.x, target.position.y, target.position.z, target.yaw, target.pitch); - } else { - teleported.refreshPositionAndAngles(target.position.x, target.position.y, target.position.z, target.yaw, target.pitch); - } - - teleported.setVelocity(target.velocity); - teleported.setHeadYaw(target.yaw); - - return teleported; + // Fast path for teleporting within the same dimension. + if (teleported.getWorld() == target.newDimension()) { + if (teleported instanceof ServerPlayerEntity serverPlayerEntity) { + serverPlayerEntity.networkHandler.requestTeleport(target.position().x, target.position().y, target.position().z, target.yaw(), target.pitch()); + } else { + teleported.refreshPositionAndAngles(target.position().x, target.position().y, target.position().z, target.yaw(), target.pitch()); } - return (E) teleported.moveToWorld(dimension); - } finally { - ((Teleportable) teleported).fabric_setCustomTeleportTarget(null); + teleported.setVelocity(target.velocity()); + teleported.setHeadYaw(target.yaw()); + + return teleported; } + + return (E) teleported.moveToWorld(() -> target); } } diff --git a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/impl/dimension/Teleportable.java b/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/impl/dimension/Teleportable.java deleted file mode 100644 index 7ff61a933b..0000000000 --- a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/impl/dimension/Teleportable.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.impl.dimension; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.world.TeleportTarget; - -public interface Teleportable { - /** - * Sets the last target set when a user of the API requested teleportation, or null. - */ - void fabric_setCustomTeleportTarget(@Nullable TeleportTarget teleportTarget); -} diff --git a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/mixin/dimension/EntityMixin.java b/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/mixin/dimension/EntityMixin.java deleted file mode 100644 index c413032abc..0000000000 --- a/fabric-dimensions-v1/src/main/java/net/fabricmc/fabric/mixin/dimension/EntityMixin.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.fabric.mixin.dimension; - -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import net.minecraft.entity.Entity; -import net.minecraft.registry.RegistryKey; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.world.TeleportTarget; -import net.minecraft.world.World; - -import net.fabricmc.fabric.impl.dimension.Teleportable; - -/** - * This mixin implements {@link Entity#getTeleportTarget(ServerWorld)} for modded dimensions, as Vanilla will - * not return a teleport target for anything but Vanilla dimensions and prevents changing teleport target in - * {@link ServerPlayerEntity#getTeleportTarget(ServerWorld)} when teleporting to END using api. - * This also prevents several End dimension-specific code when teleporting using api. - */ -@Mixin(value = {ServerPlayerEntity.class, Entity.class}) -public class EntityMixin implements Teleportable { - @Unique - @Nullable - protected TeleportTarget customTeleportTarget; - - @Override - public void fabric_setCustomTeleportTarget(TeleportTarget teleportTarget) { - this.customTeleportTarget = teleportTarget; - } - - @Inject(method = "getTeleportTarget", at = @At("HEAD"), cancellable = true, allow = 1) - public void getTeleportTarget(ServerWorld destination, CallbackInfoReturnable cir) { - // Check if a destination has been set for the entity currently being teleported - TeleportTarget customTarget = this.customTeleportTarget; - - if (customTarget != null) { - cir.setReturnValue(customTarget); - } - } - - /** - * This stops the following behaviors, in 1 mixin. - * - ServerWorld#createEndSpawnPlatform in Entity - * - End-to-overworld spawning behavior in ServerPlayerEntity - * - ServerPlayerEntity#createEndSpawnPlatform in ServerPlayerEntity - */ - @Redirect(method = "moveToWorld", at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;END:Lnet/minecraft/registry/RegistryKey;")) - private RegistryKey stopEndSpecificBehavior() { - if (this.customTeleportTarget != null) return null; - return World.END; - } -} diff --git a/fabric-dimensions-v1/src/main/resources/fabric-dimensions-v1.mixins.json b/fabric-dimensions-v1/src/main/resources/fabric-dimensions-v1.mixins.json index 7b1e09ec57..3834a11427 100644 --- a/fabric-dimensions-v1/src/main/resources/fabric-dimensions-v1.mixins.json +++ b/fabric-dimensions-v1/src/main/resources/fabric-dimensions-v1.mixins.json @@ -3,7 +3,6 @@ "package": "net.fabricmc.fabric.mixin.dimension", "compatibilityLevel": "JAVA_17", "mixins": [ - "EntityMixin", "DimensionOptionsRegistryHolderMixin", "Schema2832Mixin", "TaggedChoiceMixin", diff --git a/fabric-dimensions-v1/src/testmod/java/net/fabricmc/fabric/test/dimension/FabricDimensionTest.java b/fabric-dimensions-v1/src/testmod/java/net/fabricmc/fabric/test/dimension/FabricDimensionTest.java index 9c7efe097c..09ff8b6fcb 100644 --- a/fabric-dimensions-v1/src/testmod/java/net/fabricmc/fabric/test/dimension/FabricDimensionTest.java +++ b/fabric-dimensions-v1/src/testmod/java/net/fabricmc/fabric/test/dimension/FabricDimensionTest.java @@ -78,15 +78,15 @@ public void onInitialize() { if (entity == null) throw new AssertionError("Could not create entity!"); if (!entity.getWorld().getRegistryKey().equals(World.OVERWORLD)) throw new AssertionError("Entity starting world isn't the overworld"); - TeleportTarget target = new TeleportTarget(Vec3d.ZERO, new Vec3d(1, 1, 1), 45f, 60f); + TeleportTarget target = new TeleportTarget(world, Vec3d.ZERO, new Vec3d(1, 1, 1), 45f, 60f); - Entity teleported = FabricDimensions.teleport(entity, world, target); + Entity teleported = FabricDimensions.teleport(entity, target); if (teleported == null) throw new AssertionError("Entity didn't teleport"); if (!teleported.getWorld().getRegistryKey().equals(WORLD_KEY)) throw new AssertionError("Target world not reached."); - if (!teleported.getPos().equals(target.position)) throw new AssertionError("Target Position not reached."); + if (!teleported.getPos().equals(target.position())) throw new AssertionError("Target Position not reached."); }); CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { @@ -124,8 +124,8 @@ private int swapTargeted(CommandContext context) throws Com ServerWorld modWorld = getModWorld(context); if (serverWorld != modWorld) { - TeleportTarget target = new TeleportTarget(new Vec3d(0.5, 101, 0.5), Vec3d.ZERO, 0, 0); - FabricDimensions.teleport(player, modWorld, target); + TeleportTarget target = new TeleportTarget(modWorld, new Vec3d(0.5, 101, 0.5), Vec3d.ZERO, 0, 0); + FabricDimensions.teleport(player, target); if (player.getWorld() != modWorld) { throw FAILED_EXCEPTION.create(); @@ -134,9 +134,9 @@ private int swapTargeted(CommandContext context) throws Com modWorld.setBlockState(new BlockPos(0, 100, 0), Blocks.DIAMOND_BLOCK.getDefaultState()); modWorld.setBlockState(new BlockPos(0, 101, 0), Blocks.TORCH.getDefaultState()); } else { - TeleportTarget target = new TeleportTarget(new Vec3d(0, 100, 0), Vec3d.ZERO, + TeleportTarget target = new TeleportTarget(getWorld(context, World.OVERWORLD), new Vec3d(0, 100, 0), Vec3d.ZERO, (float) Math.random() * 360 - 180, (float) Math.random() * 360 - 180); - FabricDimensions.teleport(player, getWorld(context, World.OVERWORLD), target); + FabricDimensions.teleport(player, target); } return 1; @@ -150,8 +150,8 @@ private int testDesync(CommandContext context) { return 1; } - TeleportTarget target = new TeleportTarget(player.getPos().add(5, 0, 0), player.getVelocity(), player.getYaw(), player.getPitch()); - FabricDimensions.teleport(player, (ServerWorld) player.getWorld(), target); + TeleportTarget target = new TeleportTarget((ServerWorld) player.getWorld(), player.getPos().add(5, 0, 0), player.getVelocity(), player.getYaw(), player.getPitch()); + FabricDimensions.teleport(player, target); return 1; } @@ -175,16 +175,16 @@ private int testEntityTeleport(CommandContext context) { return 1; } - TeleportTarget target = new TeleportTarget(player.getPos(), player.getVelocity(), player.getYaw(), player.getPitch()); - FabricDimensions.teleport(entity, (ServerWorld) entity.getWorld(), target); + TeleportTarget target = new TeleportTarget((ServerWorld) entity.getWorld(), player.getPos(), player.getVelocity(), player.getYaw(), player.getPitch()); + FabricDimensions.teleport(entity, target); return 1; } private int testVanillaTeleport(CommandContext context, ServerWorld targetWorld) throws CommandSyntaxException { Entity entity = context.getSource().getEntityOrThrow(); - TeleportTarget target = new TeleportTarget(entity.getPos(), entity.getVelocity(), entity.getYaw(), entity.getPitch()); - FabricDimensions.teleport(entity, targetWorld, target); + TeleportTarget target = new TeleportTarget(targetWorld, entity.getPos(), entity.getVelocity(), entity.getYaw(), entity.getPitch()); + FabricDimensions.teleport(entity, target); return 1; } diff --git a/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/EntityMixin.java b/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/EntityMixin.java index d194171c1d..1e9bfd883a 100644 --- a/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/EntityMixin.java +++ b/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/EntityMixin.java @@ -38,7 +38,7 @@ abstract class EntityMixin { public World world; @Inject(method = "moveToWorld", at = @At("RETURN")) - private void afterWorldChanged(ServerWorld destination, CallbackInfoReturnable cir) { + private void afterWorldChanged(Entity.class_9776 arg, CallbackInfoReturnable cir) { // Ret will only have an entity if the teleport worked (entity not removed, teleportTarget was valid, entity was successfully created) Entity ret = cir.getReturnValue(); diff --git a/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/PlayerManagerMixin.java b/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/PlayerManagerMixin.java index b8cad5305e..027d1a2b2e 100644 --- a/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/PlayerManagerMixin.java +++ b/fabric-entity-events-v1/src/main/java/net/fabricmc/fabric/mixin/entity/event/PlayerManagerMixin.java @@ -21,6 +21,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import net.minecraft.entity.Entity; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; @@ -29,7 +30,7 @@ @Mixin(PlayerManager.class) abstract class PlayerManagerMixin { @Inject(method = "respawnPlayer", at = @At("TAIL")) - private void afterRespawn(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfoReturnable cir) { + private void afterRespawn(ServerPlayerEntity oldPlayer, boolean alive, Entity.RemovalReason removalReason, CallbackInfoReturnable cir) { ServerPlayerEvents.AFTER_RESPAWN.invoker().afterRespawn(oldPlayer, cir.getReturnValue(), alive); } } diff --git a/fabric-events-interaction-v0/src/client/java/net/fabricmc/fabric/mixin/event/interaction/client/ClientPlayerInteractionManagerMixin.java b/fabric-events-interaction-v0/src/client/java/net/fabricmc/fabric/mixin/event/interaction/client/ClientPlayerInteractionManagerMixin.java index ab3ba8b67f..bf83832575 100644 --- a/fabric-events-interaction-v0/src/client/java/net/fabricmc/fabric/mixin/event/interaction/client/ClientPlayerInteractionManagerMixin.java +++ b/fabric-events-interaction-v0/src/client/java/net/fabricmc/fabric/mixin/event/interaction/client/ClientPlayerInteractionManagerMixin.java @@ -40,7 +40,6 @@ import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket; import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket; import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket; -import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; @@ -118,7 +117,7 @@ public void interactBlock(ClientPlayerEntity player, Hand hand, BlockHitResult b } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", ordinal = 0), method = "interactItem", cancellable = true) + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;syncSelectedSlot()V", ordinal = 0), method = "interactItem", cancellable = true) public void interactItem(PlayerEntity player, Hand hand, CallbackInfoReturnable info) { // hook interactBlock between the spectator check and sending the first packet to invoke the use item event first // this needs to be in interactBlock to avoid sending a packet in line with the event javadoc @@ -126,10 +125,8 @@ public void interactItem(PlayerEntity player, Hand hand, CallbackInfoReturnable< if (result.getResult() != ActionResult.PASS) { if (result.getResult() == ActionResult.SUCCESS) { - // send the move packet like vanilla to ensure the position+view vectors are accurate - networkHandler.sendPacket(new PlayerMoveC2SPacket.Full(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch(), player.isOnGround())); // send interaction packet to the server with a new sequentially assigned id - sendSequencedPacket((ClientWorld) player.getWorld(), id -> new PlayerInteractItemC2SPacket(hand, id)); + sendSequencedPacket((ClientWorld) player.getWorld(), id -> new PlayerInteractItemC2SPacket(hand, id, player.getYaw(), player.getPitch())); } info.setReturnValue(result.getResult()); diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemStackMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemStackMixin.java index 6c9992a930..9ce6415226 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemStackMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/ItemStackMixin.java @@ -16,6 +16,8 @@ package net.fabricmc.fabric.mixin.item; +import java.util.function.Consumer; + import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; @@ -36,10 +38,14 @@ @Mixin(ItemStack.class) public abstract class ItemStackMixin implements FabricItemStack { - @Shadow public abstract Item getItem(); + @Shadow + public abstract Item getItem(); + + @Shadow + public abstract void decrement(int amount); - @WrapOperation(method = "damage(ILnet/minecraft/entity/LivingEntity;Lnet/minecraft/entity/EquipmentSlot;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/server/world/ServerWorld;Lnet/minecraft/server/network/ServerPlayerEntity;Ljava/lang/Runnable;)V")) - private void hookDamage(ItemStack instance, int amount, ServerWorld serverWorld, ServerPlayerEntity serverPlayerEntity, Runnable runnable, Operation original, @Local(argsOnly = true) EquipmentSlot slot) { + @WrapOperation(method = "damage(ILnet/minecraft/entity/LivingEntity;Lnet/minecraft/entity/EquipmentSlot;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/server/world/ServerWorld;Lnet/minecraft/server/network/ServerPlayerEntity;Ljava/util/function/Consumer;)V")) + private void hookDamage(ItemStack instance, int amount, ServerWorld serverWorld, ServerPlayerEntity serverPlayerEntity, Consumer consumer, Operation original, @Local(argsOnly = true) EquipmentSlot slot) { CustomDamageHandler handler = ((ItemExtensions) getItem()).fabric_getCustomDamageHandler(); if (handler != null) { @@ -47,13 +53,14 @@ private void hookDamage(ItemStack instance, int amount, ServerWorld serverWorld, MutableBoolean mut = new MutableBoolean(false); amount = handler.damage((ItemStack) (Object) this, amount, serverPlayerEntity, slot, () -> { mut.setTrue(); - runnable.run(); + this.decrement(1); + consumer.accept(this.getItem()); }); // If item is broken, there's no reason to call the original. if (mut.booleanValue()) return; } - original.call(instance, amount, serverWorld, serverPlayerEntity, runnable); + original.call(instance, amount, serverWorld, serverPlayerEntity, consumer); } } diff --git a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java index d147509d47..f90c7a2647 100644 --- a/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java +++ b/fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java @@ -31,7 +31,7 @@ @Mixin(LivingEntity.class) abstract class LivingEntityMixin { @Inject(method = "getPreferredEquipmentSlot", at = @At(value = "HEAD"), cancellable = true) - private static void onGetPreferredEquipmentSlot(ItemStack stack, CallbackInfoReturnable info) { + private void onGetPreferredEquipmentSlot(ItemStack stack, CallbackInfoReturnable info) { EquipmentSlotProvider equipmentSlotProvider = ((ItemExtensions) stack.getItem()).fabric_getEquipmentSlotProvider(); if (equipmentSlotProvider != null) { diff --git a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ChunkGeneratingMixin.java b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ChunkGeneratingMixin.java index 13f84b2fed..f7b1fd6c02 100644 --- a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ChunkGeneratingMixin.java +++ b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ChunkGeneratingMixin.java @@ -21,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.class_9761; +import net.minecraft.world.chunk.AbstractChunkHolder; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ChunkGenerating; import net.minecraft.world.chunk.ChunkGenerationContext; @@ -32,7 +32,7 @@ @Mixin(ChunkGenerating.class) abstract class ChunkGeneratingMixin { @Inject(method = "method_60553", at = @At("TAIL")) - private static void onChunkLoad(Chunk chunk, ChunkGenerationContext chunkGenerationContext, class_9761 arg, CallbackInfoReturnable callbackInfoReturnable) { + private static void onChunkLoad(Chunk chunk, ChunkGenerationContext chunkGenerationContext, AbstractChunkHolder chunkHolder, CallbackInfoReturnable callbackInfoReturnable) { // We fire the event at TAIL since the chunk is guaranteed to be a WorldChunk then. ServerChunkEvents.CHUNK_LOAD.invoker().onChunkLoad(chunkGenerationContext.world(), (WorldChunk) callbackInfoReturnable.getReturnValue()); } diff --git a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ThreadedAnvilChunkStorageMixin.java b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ServerChunkLoadingManagerMixin.java similarity index 90% rename from fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ThreadedAnvilChunkStorageMixin.java rename to fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ServerChunkLoadingManagerMixin.java index d13b1bcb47..c2443ee608 100644 --- a/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ThreadedAnvilChunkStorageMixin.java +++ b/fabric-lifecycle-events-v1/src/main/java/net/fabricmc/fabric/mixin/event/lifecycle/ServerChunkLoadingManagerMixin.java @@ -24,14 +24,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.server.world.ChunkHolder; +import net.minecraft.server.world.ServerChunkLoadingManager; import net.minecraft.server.world.ServerWorld; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; import net.minecraft.world.chunk.WorldChunk; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents; -@Mixin(ThreadedAnvilChunkStorage.class) -public abstract class ThreadedAnvilChunkStorageMixin { +@Mixin(ServerChunkLoadingManager.class) +public abstract class ServerChunkLoadingManagerMixin { @Shadow @Final private ServerWorld world; @@ -45,6 +45,6 @@ public abstract class ThreadedAnvilChunkStorageMixin { */ @Inject(method = "method_60440", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;setLoadedToWorld(Z)V", shift = At.Shift.AFTER)) private void onChunkUnload(ChunkHolder chunkHolder, long l, CallbackInfo ci) { - ServerChunkEvents.CHUNK_UNLOAD.invoker().onChunkUnload(this.world, (WorldChunk) chunkHolder.method_60471()); + ServerChunkEvents.CHUNK_UNLOAD.invoker().onChunkUnload(this.world, (WorldChunk) chunkHolder.getLatest()); } } diff --git a/fabric-lifecycle-events-v1/src/main/resources/fabric-lifecycle-events-v1.mixins.json b/fabric-lifecycle-events-v1/src/main/resources/fabric-lifecycle-events-v1.mixins.json index 2477321f77..f186b59c2d 100644 --- a/fabric-lifecycle-events-v1/src/main/resources/fabric-lifecycle-events-v1.mixins.json +++ b/fabric-lifecycle-events-v1/src/main/resources/fabric-lifecycle-events-v1.mixins.json @@ -10,7 +10,7 @@ "PlayerManagerMixin", "ServerWorldServerEntityHandlerMixin", "ServerWorldMixin", - "ThreadedAnvilChunkStorageMixin", + "ServerChunkLoadingManagerMixin", "WorldMixin" ], "server": [ diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/PlayerLookup.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/PlayerLookup.java index 73e2f5c93e..5543cb8a81 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/PlayerLookup.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/PlayerLookup.java @@ -26,9 +26,9 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.PlayerAssociatedNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerChunkLoadingManager; import net.minecraft.server.world.ServerChunkManager; import net.minecraft.server.world.ServerWorld; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3d; @@ -36,7 +36,7 @@ import net.minecraft.world.chunk.ChunkManager; import net.fabricmc.fabric.mixin.networking.accessor.EntityTrackerAccessor; -import net.fabricmc.fabric.mixin.networking.accessor.ThreadedAnvilChunkStorageAccessor; +import net.fabricmc.fabric.mixin.networking.accessor.ServerChunkLoadingManagerAccessor; /** * Helper methods to lookup players in a server. @@ -91,7 +91,7 @@ public static Collection tracking(ServerWorld world, ChunkPo Objects.requireNonNull(world, "The world cannot be null"); Objects.requireNonNull(pos, "The chunk pos cannot be null"); - return world.getChunkManager().threadedAnvilChunkStorage.getPlayersWatchingChunk(pos, false); + return world.getChunkManager().chunkLoadingManager.getPlayersWatchingChunk(pos, false); } /** @@ -112,8 +112,8 @@ public static Collection tracking(Entity entity) { ChunkManager manager = entity.getWorld().getChunkManager(); if (manager instanceof ServerChunkManager) { - ThreadedAnvilChunkStorage storage = ((ServerChunkManager) manager).threadedAnvilChunkStorage; - EntityTrackerAccessor tracker = ((ThreadedAnvilChunkStorageAccessor) storage).getEntityTrackers().get(entity.getId()); + ServerChunkLoadingManager chunkLoadingManager = ((ServerChunkManager) manager).chunkLoadingManager; + EntityTrackerAccessor tracker = ((ServerChunkLoadingManagerAccessor) chunkLoadingManager).getEntityTrackers().get(entity.getId()); // return an immutable collection to guard against accidental removals. if (tracker != null) { diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/EntityTrackerAccessor.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/EntityTrackerAccessor.java index d3c472897a..c52d424b09 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/EntityTrackerAccessor.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/EntityTrackerAccessor.java @@ -23,7 +23,7 @@ import net.minecraft.server.network.PlayerAssociatedNetworkHandler; -@Mixin(targets = "net/minecraft/server/world/ThreadedAnvilChunkStorage$EntityTracker") +@Mixin(targets = "net/minecraft/server/world/ServerChunkLoadingManager$EntityTracker") public interface EntityTrackerAccessor { @Accessor("listeners") Set getPlayersTracking(); diff --git a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ThreadedAnvilChunkStorageAccessor.java b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerChunkLoadingManagerAccessor.java similarity index 85% rename from fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ThreadedAnvilChunkStorageAccessor.java rename to fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerChunkLoadingManagerAccessor.java index 65adb6c418..6c8b498df9 100644 --- a/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ThreadedAnvilChunkStorageAccessor.java +++ b/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/mixin/networking/accessor/ServerChunkLoadingManagerAccessor.java @@ -20,10 +20,10 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -import net.minecraft.server.world.ThreadedAnvilChunkStorage; +import net.minecraft.server.world.ServerChunkLoadingManager; -@Mixin(ThreadedAnvilChunkStorage.class) -public interface ThreadedAnvilChunkStorageAccessor { +@Mixin(ServerChunkLoadingManager.class) +public interface ServerChunkLoadingManagerAccessor { @Accessor Int2ObjectMap getEntityTrackers(); } diff --git a/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json b/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json index 73c21a5583..4ec0e45e81 100644 --- a/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json +++ b/fabric-networking-api-v1/src/main/resources/fabric-networking-api-v1.mixins.json @@ -20,7 +20,7 @@ "accessor.EntityTrackerAccessor", "accessor.ServerCommonNetworkHandlerAccessor", "accessor.ServerLoginNetworkHandlerAccessor", - "accessor.ThreadedAnvilChunkStorageAccessor" + "accessor.ServerChunkLoadingManagerAccessor" ], "injectors": { "defaultRequire": 1 diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/block/FabricBlockSettings.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/block/FabricBlockSettings.java index 3e072bd15c..d1391a88a2 100644 --- a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/block/FabricBlockSettings.java +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/block/FabricBlockSettings.java @@ -23,7 +23,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.MapColor; -import net.minecraft.block.enums.Instrument; +import net.minecraft.block.enums.NoteBlockInstrument; import net.minecraft.block.piston.PistonBehavior; import net.minecraft.entity.EntityType; import net.minecraft.loot.LootTable; @@ -375,7 +375,7 @@ public FabricBlockSettings pistonBehavior(PistonBehavior pistonBehavior) { @Deprecated @Override - public FabricBlockSettings instrument(Instrument instrument) { + public FabricBlockSettings instrument(NoteBlockInstrument instrument) { super.instrument(instrument); return this; } diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/AbstractBlockSettingsAccessor.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/AbstractBlockSettingsAccessor.java index 35e85bc3aa..0960cd2e71 100644 --- a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/AbstractBlockSettingsAccessor.java +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/mixin/object/builder/AbstractBlockSettingsAccessor.java @@ -26,7 +26,7 @@ import net.minecraft.block.AbstractBlock; import net.minecraft.block.BlockState; import net.minecraft.block.MapColor; -import net.minecraft.block.enums.Instrument; +import net.minecraft.block.enums.NoteBlockInstrument; import net.minecraft.block.piston.PistonBehavior; import net.minecraft.entity.EntityType; import net.minecraft.loot.LootTable; @@ -125,7 +125,7 @@ public interface AbstractBlockSettingsAccessor { PistonBehavior getPistonBehavior(); @Accessor - Instrument getInstrument(); + NoteBlockInstrument getInstrument(); @Accessor boolean getReplaceable(); diff --git a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/api/client/rendering/v1/WorldRenderContext.java b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/api/client/rendering/v1/WorldRenderContext.java index ef3b78985d..791572f7f1 100644 --- a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/api/client/rendering/v1/WorldRenderContext.java +++ b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/api/client/rendering/v1/WorldRenderContext.java @@ -20,6 +20,7 @@ import org.joml.Matrix4f; import net.minecraft.block.BlockState; +import net.minecraft.class_9779; import net.minecraft.client.render.Camera; import net.minecraft.client.render.Frustum; import net.minecraft.client.render.GameRenderer; @@ -51,9 +52,8 @@ public interface WorldRenderContext { @Nullable MatrixStack matrixStack(); - float tickDelta(); - - long limitTime(); + // TODO 1.21 + class_9779 delta(); boolean blockOutlines(); diff --git a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/WorldRenderContextImpl.java b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/WorldRenderContextImpl.java index 224389fe8a..7763ea9699 100644 --- a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/WorldRenderContextImpl.java +++ b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/WorldRenderContextImpl.java @@ -19,6 +19,7 @@ import org.joml.Matrix4f; import net.minecraft.block.BlockState; +import net.minecraft.class_9779; import net.minecraft.client.render.Camera; import net.minecraft.client.render.Frustum; import net.minecraft.client.render.GameRenderer; @@ -37,9 +38,8 @@ public final class WorldRenderContextImpl implements WorldRenderContext.BlockOutlineContext, WorldRenderContext { private WorldRenderer worldRenderer; + private class_9779 delta; private MatrixStack matrixStack; - private float tickDelta; - private long limitTime; private boolean blockOutlines; private Camera camera; private Frustum frustum; @@ -63,8 +63,7 @@ public final class WorldRenderContextImpl implements WorldRenderContext.BlockOut public void prepare( WorldRenderer worldRenderer, - float tickDelta, - long limitTime, + class_9779 delta, boolean blockOutlines, Camera camera, GameRenderer gameRenderer, @@ -77,9 +76,8 @@ public void prepare( ClientWorld world ) { this.worldRenderer = worldRenderer; + this.delta = delta; this.matrixStack = null; - this.tickDelta = tickDelta; - this.limitTime = limitTime; this.blockOutlines = blockOutlines; this.camera = camera; this.gameRenderer = gameRenderer; @@ -127,13 +125,8 @@ public MatrixStack matrixStack() { } @Override - public float tickDelta() { - return tickDelta; - } - - @Override - public long limitTime() { - return limitTime; + public class_9779 delta() { + return this.delta; } @Override diff --git a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/InGameHudMixin.java b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/InGameHudMixin.java index 48f53a2116..87c41379fa 100644 --- a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/InGameHudMixin.java +++ b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/InGameHudMixin.java @@ -22,6 +22,7 @@ import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.class_9779; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; @@ -29,8 +30,9 @@ @Mixin(InGameHud.class) public class InGameHudMixin { - @Inject(method = "render", at = @At(value = "TAIL"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/LayeredDrawer;render(Lnet/minecraft/client/gui/DrawContext;F)V"))) - public void render(DrawContext drawContext, float tickDelta, CallbackInfo callbackInfo) { - HudRenderCallback.EVENT.invoker().onHudRender(drawContext, tickDelta); + @Inject(method = "render", at = @At(value = "TAIL"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/LayeredDrawer;render(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/class_9779;)V"))) + public void render(DrawContext drawContext, class_9779 delta, CallbackInfo callbackInfo) { + // TODO 1.21 + HudRenderCallback.EVENT.invoker().onHudRender(drawContext, delta.method_60636()); } } diff --git a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java index e6b5972889..0960f36856 100644 --- a/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java +++ b/fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/WorldRendererMixin.java @@ -28,6 +28,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.block.BlockState; +import net.minecraft.class_9779; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gl.PostEffectProcessor; import net.minecraft.client.render.BufferBuilderStorage; @@ -61,8 +62,8 @@ public abstract class WorldRendererMixin { @Unique private final WorldRenderContextImpl context = new WorldRenderContextImpl(); @Inject(method = "render", at = @At("HEAD")) - private void beforeRender(float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, Matrix4f projectionMatrix, CallbackInfo ci) { - context.prepare((WorldRenderer) (Object) this, tickDelta, limitTime, renderBlockOutline, camera, gameRenderer, lightmapTextureManager, projectionMatrix, positionMatrix, bufferBuilders.getEntityVertexConsumers(), world.getProfiler(), transparencyPostProcessor != null, world); + private void beforeRender(class_9779 delta, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, Matrix4f projectionMatrix, CallbackInfo ci) { + context.prepare((WorldRenderer) (Object) this, delta, renderBlockOutline, camera, gameRenderer, lightmapTextureManager, projectionMatrix, positionMatrix, bufferBuilders.getEntityVertexConsumers(), world.getProfiler(), transparencyPostProcessor != null, world); WorldRenderEvents.START.invoker().onStart(context); } diff --git a/gradle.properties b/gradle.properties index 8ea08cfdcd..2086b59158 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.parallel=true fabric.loom.multiProjectOptimisation=true version=0.98.1 -minecraft_version=24w19b -yarn_version=+build.1 +minecraft_version=24w20a +yarn_version=+build.2 loader_version=0.15.11 installer_version=1.0.1