Skip to content

Commit

Permalink
Attempt 3
Browse files Browse the repository at this point in the history
  • Loading branch information
yikerman committed Apr 23, 2022
1 parent ec68a93 commit 12eae97
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/java/wearblackallday/dimthread/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import net.minecraft.server.world.ServerWorld;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import wearblackallday.dimthread.DimThread;

Expand All @@ -17,6 +19,11 @@
@Mixin(Entity.class)
public abstract class EntityMixin implements Cloneable {

public boolean isCloned = false;

@Shadow @Final
abstract void setRemoved(Entity.RemovalReason reason);

/**
* Schedules moving entities between dimensions to the server thread. Once all
* the world finish ticking, {@code moveToWorld()} is processed in a safe manner
Expand All @@ -42,11 +49,26 @@ public void moveToWorld(ServerWorld destination, CallbackInfoReturnable<Entity>
destination.getServer().execute(
() -> finalSnapshot.moveToWorld(destination)
);
this.removeFromDimension();
ci.setReturnValue(null);
}
}

/**
* @author xiaoyu2006
* @reason If this is a cloned entity, it should not execute removeFromDimension.
*/
@Overwrite
public void removeFromDimension() {
if (this.isCloned) {
return;
}
this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
}

protected Object clone() throws CloneNotSupportedException {
return super.clone();
EntityMixin cloned = (EntityMixin) super.clone();
cloned.isCloned = true;
return cloned;
}
}

0 comments on commit 12eae97

Please sign in to comment.