Search in sources :

Example 1 with EntityEnderPearl

use of net.minecraft.entity.item.EntityEnderPearl in project SpongeCommon by SpongePowered.

the class MixinWorld method createEntity.

private Entity createEntity(EntityType type, Vector3d position, boolean naturally) throws IllegalArgumentException, IllegalStateException {
    checkNotNull(type, "The entity type cannot be null!");
    checkNotNull(position, "The position cannot be null!");
    Entity entity = null;
    Class<? extends Entity> entityClass = type.getEntityClass();
    double x = position.getX();
    double y = position.getY();
    double z = position.getZ();
    if (entityClass.isAssignableFrom(EntityPlayerMP.class) || entityClass.isAssignableFrom(MultiPartEntityPart.class)) {
        // Unable to construct these
        throw new IllegalArgumentException("Cannot construct " + type.getId() + " please look to using entity types correctly!");
    }
    net.minecraft.world.World world = (net.minecraft.world.World) (Object) this;
    // Not all entities have a single World parameter as their constructor
    if (entityClass.isAssignableFrom(EntityLightningBolt.class)) {
        entity = (Entity) new EntityLightningBolt(world, x, y, z, false);
    } else if (entityClass.isAssignableFrom(EntityEnderPearl.class)) {
        EntityArmorStand tempEntity = new EntityArmorStand(world, x, y, z);
        tempEntity.posY -= tempEntity.getEyeHeight();
        entity = (Entity) new EntityEnderPearl(world, tempEntity);
        ((EnderPearl) entity).setShooter(ProjectileSource.UNKNOWN);
    }
    // set them is to use the more specialised constructor).
    if (entityClass.isAssignableFrom(EntityFallingBlock.class)) {
        entity = (Entity) new EntityFallingBlock(world, x, y, z, Blocks.SAND.getDefaultState());
    } else if (entityClass.isAssignableFrom(EntityItem.class)) {
        entity = (Entity) new EntityItem(world, x, y, z, new ItemStack(Blocks.STONE));
    }
    if (entity == null) {
        try {
            entity = ConstructorUtils.invokeConstructor(entityClass, this);
            ((net.minecraft.entity.Entity) entity).setPosition(x, y, z);
        } catch (Exception e) {
            throw new RuntimeException("There was an issue attempting to construct " + type.getId(), e);
        }
    }
    if (naturally && entity instanceof EntityLiving) {
        // Adding the default equipment
        ((EntityLiving) entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(x, y, z)), null);
    }
    if (entity instanceof EntityPainting) {
        // This is default when art is null when reading from NBT, could
        // choose a random art instead?
        ((EntityPainting) entity).art = EnumArt.KEBAB;
    }
    return entity;
}
Also used : Entity(org.spongepowered.api.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityLiving(net.minecraft.entity.EntityLiving) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) EntityEnderPearl(net.minecraft.entity.item.EntityEnderPearl) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) EntityPainting(net.minecraft.entity.item.EntityPainting) PositionOutOfBoundsException(org.spongepowered.api.util.PositionOutOfBoundsException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityLiving (net.minecraft.entity.EntityLiving)1 MultiPartEntityPart (net.minecraft.entity.MultiPartEntityPart)1 EntityLightningBolt (net.minecraft.entity.effect.EntityLightningBolt)1 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)1 EntityEnderPearl (net.minecraft.entity.item.EntityEnderPearl)1 EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPainting (net.minecraft.entity.item.EntityPainting)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 Entity (org.spongepowered.api.entity.Entity)1 PositionOutOfBoundsException (org.spongepowered.api.util.PositionOutOfBoundsException)1 World (org.spongepowered.api.world.World)1 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)1 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)1 IMixinBlockPos (org.spongepowered.common.interfaces.util.math.IMixinBlockPos)1 IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)1