Workaround for MinecraftForge#7519
This commit is contained in:
parent
414085d5da
commit
678786d426
@ -164,6 +164,16 @@ public abstract class ServerWorldMixin extends WorldMixin implements ServerWorld
|
||||
return this.convertable;
|
||||
}
|
||||
|
||||
@Inject(method = "addEntityIfNotDuplicate", at = @At("HEAD"))
|
||||
private void arclight$worldGenAddStart(Entity entityIn, CallbackInfoReturnable<Boolean> cir) {
|
||||
ArclightCaptures.captureWorldGenAddEntity();
|
||||
}
|
||||
|
||||
@Inject(method = "addEntityIfNotDuplicate", at = @At("RETURN"))
|
||||
private void arclight$worldGenAddEnd(Entity entityIn, CallbackInfoReturnable<Boolean> cir) {
|
||||
ArclightCaptures.resetWorldGenAddEntity();
|
||||
}
|
||||
|
||||
@Inject(method = "onEntityAdded", at = @At("RETURN"))
|
||||
private void arclight$validEntity(Entity entityIn, CallbackInfo ci) {
|
||||
((EntityBridge) entityIn).bridge$setValid(true);
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
package io.izzel.arclight.common.mixin.forge;
|
||||
|
||||
import io.izzel.arclight.common.mod.util.ArclightCaptures;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.common.ForgeInternalHandler;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ForgeInternalHandler.class)
|
||||
public class ForgeInternalHandlerMixin {
|
||||
|
||||
// Workaround for MinecraftForge#7519
|
||||
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z"))
|
||||
private boolean arclight$addDuringWorldGen(World world, Entity entityIn) {
|
||||
return world instanceof ServerWorld && ArclightCaptures.isWorldGenAdd()
|
||||
? ((ServerWorld) world).addEntityIfNotDuplicate(entityIn)
|
||||
: world.addEntity(entityIn);
|
||||
}
|
||||
}
|
||||
@ -230,6 +230,20 @@ public class ArclightCaptures {
|
||||
}
|
||||
}
|
||||
|
||||
private static transient boolean worldGenAdd;
|
||||
|
||||
public static void captureWorldGenAddEntity() {
|
||||
worldGenAdd = true;
|
||||
}
|
||||
|
||||
public static boolean isWorldGenAdd() {
|
||||
return worldGenAdd;
|
||||
}
|
||||
|
||||
public static void resetWorldGenAddEntity() {
|
||||
worldGenAdd = false;
|
||||
}
|
||||
|
||||
private static void recapture(String type) {
|
||||
throw new IllegalStateException("Recapturing " + type);
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
"setSourceFile": true,
|
||||
"mixins": [
|
||||
"ForgeEventFactoryMixin",
|
||||
"ForgeHooksMixin"
|
||||
"ForgeHooksMixin",
|
||||
"ForgeInternalHandlerMixin"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user