1.21-pre3

Co-authored-by: Drex <nicknamedrex@gmail.com>
This commit is contained in:
modmuss50 2024-06-05 13:00:45 +01:00
parent 6a6dfa1985
commit 98a7dbbb57
3 changed files with 32 additions and 70 deletions
fabric-lifecycle-events-v1/src
client/java/net/fabricmc/fabric/mixin/event/lifecycle/client
main/java/net/fabricmc/fabric/mixin/event/lifecycle/server
gradle.properties

View file

@ -18,6 +18,7 @@ package net.fabricmc.fabric.mixin.event.lifecycle.client;
import java.util.Map;
import com.llamalad7.mixinextras.sugar.Local;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -43,41 +44,21 @@ abstract class WorldChunkMixin {
@Shadow
public abstract World getWorld();
/*
* @Inject(method = "setBlockEntity", at = @At(value = "CONSTANT", args = "nullValue=true"), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
*
* i509VCB: Yes this is very brittle.
* Sadly mixin does not want to cooperate with the Inject annotation commented out above.
* Our goal is to place the inject JUST after the possibly removed block entity is stored onto the stack so we can use local capture:
*
* INVOKEVIRTUAL net/minecraft/util/math/BlockPos.toImmutable ()Lnet/minecraft/util/math/BlockPos;
* ALOAD 1
* INVOKEINTERFACE java/util/Map.put (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; (itf)
* CHECKCAST net/minecraft/block/entity/BlockEntity
* ASTORE 3
* <======== HERE
* L6
*/
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", shift = At.Shift.BY, by = 3), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onLoadBlockEntity(BlockEntity blockEntity, CallbackInfo ci, BlockPos blockPos, @Nullable BlockEntity removedBlockEntity) {
// Only fire the load event if the block entity has actually changed
if (blockEntity != null && blockEntity != removedBlockEntity) {
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.invoker().onLoad(blockEntity, (ServerWorld) this.getWorld());
} else if (this.getWorld() instanceof ClientWorld) {
ClientBlockEntityEvents.BLOCK_ENTITY_LOAD.invoker().onLoad(blockEntity, (ClientWorld) this.getWorld());
}
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;markRemoved()V"))
private void onLoadBlockEntity(BlockEntity blockEntity, CallbackInfo ci, @Local(ordinal = 1) BlockEntity removedBlockEntity) {
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.invoker().onLoad(blockEntity, (ServerWorld) this.getWorld());
} else if (this.getWorld() instanceof ClientWorld) {
ClientBlockEntityEvents.BLOCK_ENTITY_LOAD.invoker().onLoad(blockEntity, (ClientWorld) this.getWorld());
}
}
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;markRemoved()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onRemoveBlockEntity(BlockEntity blockEntity, CallbackInfo info, BlockPos blockPos, @Nullable BlockEntity removedBlockEntity) {
if (removedBlockEntity != null) {
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.invoker().onUnload(removedBlockEntity, (ServerWorld) this.getWorld());
} else if (this.getWorld() instanceof ClientWorld) {
ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.invoker().onUnload(removedBlockEntity, (ClientWorld) this.getWorld());
}
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;markRemoved()V", shift = At.Shift.AFTER))
private void onRemoveBlockEntity(BlockEntity blockEntity, CallbackInfo info, @Local(ordinal = 1) BlockEntity removedBlockEntity) {
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.invoker().onUnload(removedBlockEntity, (ServerWorld) this.getWorld());
} else if (this.getWorld() instanceof ClientWorld) {
ClientBlockEntityEvents.BLOCK_ENTITY_UNLOAD.invoker().onUnload(removedBlockEntity, (ClientWorld) this.getWorld());
}
}
@ -85,8 +66,7 @@ abstract class WorldChunkMixin {
@Redirect(method = "getBlockEntity(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/chunk/WorldChunk$CreationType;)Lnet/minecraft/block/entity/BlockEntity;", at = @At(value = "INVOKE", target = "Ljava/util/Map;remove(Ljava/lang/Object;)Ljava/lang/Object;"),
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;createBlockEntity(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/entity/BlockEntity;")))
private <K, V> Object onRemoveBlockEntity(Map<K, V> map, K key) {
@Nullable
final V removed = map.remove(key);
@Nullable final V removed = map.remove(key);
if (removed != null) {
if (this.getWorld() instanceof ServerWorld) {

View file

@ -18,6 +18,7 @@ package net.fabricmc.fabric.mixin.event.lifecycle.server;
import java.util.Map;
import com.llamalad7.mixinextras.sugar.Local;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -46,37 +47,18 @@ abstract class WorldChunkMixin {
@Shadow
public abstract World getWorld();
/*
* @Inject(method = "setBlockEntity", at = @At(value = "CONSTANT", args = "nullValue=true"), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
*
* i509VCB: Yes this is very brittle.
* Sadly mixin does not want to cooperate with the Inject annotation commented out above.
* Our goal is to place the inject JUST after the possibly removed block entity is stored onto the stack so we can use local capture:
*
* INVOKEVIRTUAL net/minecraft/util/math/BlockPos.toImmutable ()Lnet/minecraft/util/math/BlockPos;
* ALOAD 1
* INVOKEINTERFACE java/util/Map.put (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; (itf)
* CHECKCAST net/minecraft/block/entity/BlockEntity
* ASTORE 3
* <======== HERE
* L6
*/
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", shift = At.Shift.BY, by = 3), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onLoadBlockEntity(BlockEntity blockEntity, CallbackInfo ci, BlockPos blockPos, @Nullable BlockEntity removedBlockEntity) {
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;markRemoved()V"))
private void onLoadBlockEntity(BlockEntity blockEntity, CallbackInfo ci, @Local(ordinal = 1) BlockEntity removedBlockEntity) {
// Only fire the load event if the block entity has actually changed
if (blockEntity != null && blockEntity != removedBlockEntity) {
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.invoker().onLoad(blockEntity, (ServerWorld) this.getWorld());
}
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.invoker().onLoad(blockEntity, (ServerWorld) this.getWorld());
}
}
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;markRemoved()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onRemoveBlockEntity(BlockEntity blockEntity, CallbackInfo info, BlockPos blockPos, @Nullable BlockEntity removedBlockEntity) {
if (removedBlockEntity != null) {
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.invoker().onUnload(removedBlockEntity, (ServerWorld) this.getWorld());
}
@Inject(method = "setBlockEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;markRemoved()V", shift = At.Shift.AFTER))
private void onRemoveBlockEntity(BlockEntity blockEntity, CallbackInfo info, @Local(ordinal = 1) BlockEntity removedBlockEntity) {
if (this.getWorld() instanceof ServerWorld) {
ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.invoker().onUnload(removedBlockEntity, (ServerWorld) this.getWorld());
}
}

View file

@ -2,8 +2,8 @@ org.gradle.jvmargs=-Xmx2560M
org.gradle.parallel=true
fabric.loom.multiProjectOptimisation=true
version=0.99.4
minecraft_version=1.21-pre2
version=0.99.5
minecraft_version=1.21-pre3
yarn_version=+build.1
loader_version=0.15.11
installer_version=1.0.1
@ -13,7 +13,7 @@ curseforge_minecraft_version=1.21-Snapshot
# Do not manually update, use the bumpversions task:
fabric-api-base-version=0.4.42
fabric-api-lookup-api-v1-version=1.6.64
fabric-api-lookup-api-v1-version=1.6.65
fabric-biome-api-v1-version=13.0.28
fabric-block-api-v1-version=1.0.22
fabric-block-view-api-v2-version=1.0.10
@ -21,10 +21,10 @@ fabric-blockrenderlayer-v1-version=1.1.52
fabric-command-api-v1-version=1.2.48
fabric-command-api-v2-version=2.2.27
fabric-commands-v0-version=0.2.65
fabric-content-registries-v0-version=8.0.10
fabric-content-registries-v0-version=8.0.11
fabric-crash-report-info-v1-version=0.2.29
fabric-data-attachment-api-v1-version=1.1.21
fabric-data-generation-api-v1-version=20.2.3
fabric-data-generation-api-v1-version=20.2.4
fabric-dimensions-v1-version=4.0.0
fabric-entity-events-v1-version=1.6.12
fabric-events-interaction-v0-version=0.7.10
@ -34,7 +34,7 @@ fabric-item-api-v1-version=11.0.0
fabric-item-group-api-v1-version=4.0.43
fabric-key-binding-api-v1-version=1.0.47
fabric-keybindings-v0-version=0.2.45
fabric-lifecycle-events-v1-version=2.3.8
fabric-lifecycle-events-v1-version=2.3.9
fabric-loot-api-v2-version=3.0.9
fabric-message-api-v1-version=6.0.13
fabric-model-loading-api-v1-version=1.0.14
@ -55,8 +55,8 @@ fabric-resource-loader-v0-version=1.1.3
fabric-screen-api-v1-version=2.0.24
fabric-screen-handler-api-v1-version=1.3.77
fabric-sound-api-v1-version=1.0.23
fabric-transfer-api-v1-version=5.1.11
fabric-transfer-api-v1-version=5.1.12
fabric-transitive-access-wideners-v1-version=6.0.12
fabric-convention-tags-v1-version=2.0.9
fabric-convention-tags-v2-version=2.1.4
fabric-convention-tags-v1-version=2.0.10
fabric-convention-tags-v2-version=2.1.5
fabric-client-tags-api-v1-version=1.1.15