Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
CaveNightingale committed Dec 30, 2022
1 parent 6e35f6a commit 841cdce
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/main/java/wearblackallday/dimthread/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,25 @@ public void onMoveToWorld(ServerWorld destination, CallbackInfoReturnable<Entity
return;

if (DimThread.owns(Thread.currentThread())) {
nbtCachedForMoveToWorld = writeNbt(new NbtCompound());
uncompletedTeleportTargetForMoveToWorld = createTeleportTargetUncompleted(destination);
destination.getServer().execute(
() -> {
Entity entity = this.moveToWorld(destination);
if(entity == null) {
this.unsetRemoved();
nbtCachedForMoveToWorld.putInt("PortalCooldown", this.netherPortalCooldown);
this.readNbt(nbtCachedForMoveToWorld);
this.uncompletedTeleportTargetForMoveToWorld = null;
this.nbtCachedForMoveToWorld = null;
this.world.spawnEntity((Entity) (Object) this);// if the teleporting failed, we need to add it back to the world
LOGGER.debug("Failed to teleport {}, return it to its previous world", this);
if (nbtCachedForMoveToWorld == null) { // Some entity may invoke moveToWorld many times, which may cause https://github.com/CaveNightingale/DimensionalThreading/issues/1
nbtCachedForMoveToWorld = writeNbt(new NbtCompound());
uncompletedTeleportTargetForMoveToWorld = createTeleportTargetUncompleted(destination);
destination.getServer().execute(
() -> {
Entity entity = this.moveToWorld(destination);
if (entity == null) {
this.unsetRemoved();
nbtCachedForMoveToWorld.putInt("PortalCooldown", this.netherPortalCooldown);
this.readNbt(nbtCachedForMoveToWorld);
this.uncompletedTeleportTargetForMoveToWorld = null;
this.nbtCachedForMoveToWorld = null;
this.world.spawnEntity((Entity) (Object) this);// if the teleporting failed, we need to add it back to the world
LOGGER.debug("Failed to teleport {}, return it to its previous world", this);
}
}
}
);
this.removeFromDimension();
);
this.removeFromDimension();
}
ci.setReturnValue(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package wearblackallday.dimthread.mixin;

import com.mojang.brigadier.CommandDispatcher;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.dedicated.command.PerfCommand;
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;

@Mixin(PerfCommand.class)
public abstract class PerfCommandMixin {
/**
* Remove /perf because it's not thread-safe
*/
@Inject(method = "register", at = @At("HEAD"), cancellable = true)
private static void removePerfCommand(CommandDispatcher<ServerCommandSource> dispatcher, CallbackInfo ci) {
ci.cancel();
}
}
1 change: 1 addition & 0 deletions src/main/resources/dimthread.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"EntityMixin",
"MinecraftDedicatedServerMixin",
"MinecraftServerMixin",
"PerfCommandMixin",
"RedstoneWireBlockMixin",
"ServerChunkManagerMixin",
"ServerWorldMixin",
Expand Down

0 comments on commit 841cdce

Please sign in to comment.