Fix throwing egg crashes server

This commit is contained in:
IzzelAliz 2020-10-30 21:54:47 +08:00
parent 9b4cfe81f0
commit e537455453
2 changed files with 5 additions and 5 deletions

View File

@ -1,13 +1,13 @@
package io.izzel.arclight.common.mixin.bukkit;
import io.izzel.arclight.common.bridge.bukkit.EntityTypeBridge;
import io.izzel.arclight.common.bridge.entity.EntityBridge;
import io.izzel.arclight.common.bridge.world.server.ServerWorldBridge;
import net.minecraft.world.server.ServerWorld;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@ -20,17 +20,18 @@ import java.io.File;
import java.util.function.Function;
@Mixin(value = CraftWorld.class, remap = false)
public class CraftWorldMixin {
public abstract class CraftWorldMixin {
// @formatter:off
@Shadow @Final private ServerWorld world;
@Shadow public abstract <T extends Entity> T addEntity(net.minecraft.entity.Entity entity, CreatureSpawnEvent.SpawnReason reason) throws IllegalArgumentException;
// @formatter:on
@Inject(method = "spawnEntity", cancellable = true, at = @At("HEAD"))
private void arclight$useFactory(Location loc, EntityType entityType, CallbackInfoReturnable<Entity> cir) {
Function<Location, ? extends net.minecraft.entity.Entity> factory = ((EntityTypeBridge) (Object) entityType).bridge$entityFactory();
if (factory != null) {
cir.setReturnValue(((EntityBridge) factory.apply(loc)).bridge$getBukkitEntity());
cir.setReturnValue(this.addEntity(factory.apply(loc), CreatureSpawnEvent.SpawnReason.CUSTOM));
}
}

View File

@ -9,7 +9,6 @@ import net.minecraft.entity.projectile.EggEntity;
import net.minecraft.util.math.RayTraceResult;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v.entity.CraftEntity;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Egg;
import org.bukkit.event.entity.CreatureSpawnEvent;
@ -47,7 +46,7 @@ public abstract class EggEntityMixin extends ThrowableEntityMixin {
}
if (hatching) {
for (int i = 0; i < b0; ++i) {
Entity entity = ((CraftEntity) ((WorldBridge) this.world).bridge$getWorld().spawnEntity(new Location(((WorldBridge) this.world).bridge$getWorld(), this.getPosX(), this.getPosY(), this.getPosZ(), this.rotationYaw, 0.0f), hatchingType)).getHandle();
Entity entity = ((WorldBridge) this.world).bridge$getWorld().createEntity(new Location(((WorldBridge) this.world).bridge$getWorld(), this.getPosX(), this.getPosY(), this.getPosZ(), this.rotationYaw, 0.0f), hatchingType.getEntityClass());
if (((EntityBridge) entity).bridge$getBukkitEntity() instanceof Ageable) {
((Ageable) ((EntityBridge) entity).bridge$getBukkitEntity()).setBaby();
}