Skip to content

Commit

Permalink
Fix entities not saving when chunk was unloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Avanatiker committed Sep 5, 2023
1 parent 1c32be3 commit cf7f0fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions common/src/main/java/org/waste/of/time/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.waste.of.time.mixin;

import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.waste.of.time.WorldTools;

@Mixin(Entity.class)
public class EntityMixin {
@Inject(method = "setRemoved", at = @At("HEAD"), cancellable = true)
private void cancelMarkRemoved(Entity.RemovalReason reason, CallbackInfo ci) {
if (WorldTools.INSTANCE.getCaching() && reason == Entity.RemovalReason.DISCARDED) ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ object StorageManager {
putByte("Invulnerable", 1)
putByte("Silent", 1)
}

it.setRemoved(Entity.RemovalReason.DISCARDED)
})

cachedEntities.remove(it)
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/worldtools.mixins.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"BossBarHudMixin",
"ClientChunkManagerMixin",
"ClientPlayNetworkHandlerMixin",
"EntityMixin",
"MinecraftClientMixin",
"WorldChunkMixin",
"accessor.AdvancementProgressesAccessor",
Expand Down

0 comments on commit cf7f0fd

Please sign in to comment.