当前位置: 首页>>代码示例>>Java>>正文


Java EntityList.createEntityByName方法代码示例

本文整理汇总了Java中net.minecraft.entity.EntityList.createEntityByName方法的典型用法代码示例。如果您正苦于以下问题:Java EntityList.createEntityByName方法的具体用法?Java EntityList.createEntityByName怎么用?Java EntityList.createEntityByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.entity.EntityList的用法示例。


在下文中一共展示了EntityList.createEntityByName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onHitEntity

import net.minecraft.entity.EntityList; //导入方法依赖的package包/类
@SubscribeEvent
public void onHitEntity(LivingHurtEvent event) {
	
	if (event.getAmount() <= 0 || event.getEntityLiving() instanceof EntityPlayer) return;
	
	if (!(event.getSource().getSourceOfDamage() instanceof EntityPlayer)) return;
	
	ItemStack transformer = BaublesApi.getBaublesHandler((EntityPlayer)event.getSource().getSourceOfDamage()).getStackInSlot(6);
	if (transformer == null || (transformer != null && transformer.getItem() != this)) return;
	
	Random rand = new Random();
	if (rand.nextInt(100) != 0) return;
	
	EntityLivingBase elb = event.getEntityLiving();
	List<String> entities = new ArrayList<String>(EntityList.ENTITY_EGGS.keySet());
	String randomString = entities.get(rand.nextInt(entities.size()));
	Entity entity = EntityList.createEntityByName(randomString, elb.worldObj);
	if (!entity.isNonBoss()) return;
	entity.setPositionAndRotation(elb.posX, elb.posY, elb.posZ, elb.rotationYaw, elb.rotationPitch);
	
	elb.worldObj.spawnEntityInWorld(entity);
	elb.setDead();
}
 
开发者ID:bafomdad,项目名称:uniquecrops,代码行数:24,代码来源:EmblemTransformation.java

示例2: func_180612_a

import net.minecraft.entity.EntityList; //导入方法依赖的package包/类
public Entity func_180612_a(World worldIn)
{
    if (this.cachedEntity == null)
    {
        Entity entity = EntityList.createEntityByName(this.getEntityNameToSpawn(), worldIn);

        if (entity != null)
        {
            entity = this.spawnNewEntity(entity, false);
            this.cachedEntity = entity;
        }
    }

    return this.cachedEntity;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:16,代码来源:MobSpawnerBaseLogic.java

示例3: onItemUse

import net.minecraft.entity.EntityList; //导入方法依赖的package包/类
@Override
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    }
    if (!item.hasTagCompound()) {
        return false;
    }
    if(player == null) {
        return false;
    }

    String entityId = item.stackTagCompound.getCompoundTag("entity").getString("id");
    Entity entityToSpawn = EntityList.createEntityByName(entityId, world);

    Block blk = world.getBlock(x,y,z);
    double spawnX = x + Facing.offsetsXForSide[facing] + 0.5;
    double spawnY = y + Facing.offsetsYForSide[facing];
    double spawnZ = z + Facing.offsetsZForSide[facing] + 0.5;
    if(facing == ForgeDirection.UP.ordinal() && (blk instanceof BlockFence || blk instanceof BlockWall)) {
        spawnY += 0.5;
    }
    if(entityToSpawn instanceof EntitySlime) {
        ((EntitySlime) entityToSpawn).setSlimeSize(item.stackTagCompound.getCompoundTag("entity").getInteger("slimesize"));
    }
    if(entityToSpawn instanceof EntityZombie){
        if(item.stackTagCompound.getCompoundTag("entity").getBoolean("isBabyZombie"))
            ((EntityZombie) entityToSpawn).setChild(true);
        else
            ((EntityZombie) entityToSpawn).setChild(false);
    }
    entityToSpawn.setLocationAndAngles(spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0);
    world.spawnEntityInWorld(entityToSpawn);
    if(entityToSpawn instanceof EntityLiving) {
        ((EntityLiving)entityToSpawn).playLivingSound();
        ((EntityLiving)entityToSpawn).setHealth(item.stackTagCompound.getCompoundTag("entity").getFloat("health"));
    }

    Entity riddenByEntity = entityToSpawn.riddenByEntity;
    while(riddenByEntity != null) {
        riddenByEntity.setLocationAndAngles(spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0.0F);
        world.spawnEntityInWorld(riddenByEntity);
        if(riddenByEntity instanceof EntityLiving) {
            ((EntityLiving)riddenByEntity).playLivingSound();
        }
        riddenByEntity = riddenByEntity.riddenByEntity;
    }
    item.setTagCompound(null);
    player.setCurrentItemOrArmor(0, item);
    return true;
}
 
开发者ID:SihenZhang,项目名称:CursedLasso,代码行数:52,代码来源:ItemCursedLasso.java

示例4: updateSpawner

import net.minecraft.entity.EntityList; //导入方法依赖的package包/类
public void updateSpawner()
{
    if (this.isActivated())
    {
        BlockPos blockpos = this.getSpawnerPosition();

        if (this.getSpawnerWorld().isRemote)
        {
            double d3 = (double)((float)blockpos.getX() + this.getSpawnerWorld().rand.nextFloat());
            double d4 = (double)((float)blockpos.getY() + this.getSpawnerWorld().rand.nextFloat());
            double d5 = (double)((float)blockpos.getZ() + this.getSpawnerWorld().rand.nextFloat());
            this.getSpawnerWorld().spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d3, d4, d5, 0.0D, 0.0D, 0.0D, new int[0]);
            this.getSpawnerWorld().spawnParticle(EnumParticleTypes.FLAME, d3, d4, d5, 0.0D, 0.0D, 0.0D, new int[0]);

            if (this.spawnDelay > 0)
            {
                --this.spawnDelay;
            }

            this.prevMobRotation = this.mobRotation;
            this.mobRotation = (this.mobRotation + (double)(1000.0F / ((float)this.spawnDelay + 200.0F))) % 360.0D;
        }
        else
        {
            if (this.spawnDelay == -1)
            {
                this.resetTimer();
            }

            if (this.spawnDelay > 0)
            {
                --this.spawnDelay;
                return;
            }

            boolean flag = false;

            for (int i = 0; i < this.spawnCount; ++i)
            {
                Entity entity = EntityList.createEntityByName(this.getEntityNameToSpawn(), this.getSpawnerWorld());

                if (entity == null)
                {
                    return;
                }

                int j = this.getSpawnerWorld().getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ(), (double)(blockpos.getX() + 1), (double)(blockpos.getY() + 1), (double)(blockpos.getZ() + 1))).expand((double)this.spawnRange, (double)this.spawnRange, (double)this.spawnRange)).size();

                if (j >= this.maxNearbyEntities)
                {
                    this.resetTimer();
                    return;
                }

                double d0 = (double)blockpos.getX() + (this.getSpawnerWorld().rand.nextDouble() - this.getSpawnerWorld().rand.nextDouble()) * (double)this.spawnRange + 0.5D;
                double d1 = (double)(blockpos.getY() + this.getSpawnerWorld().rand.nextInt(3) - 1);
                double d2 = (double)blockpos.getZ() + (this.getSpawnerWorld().rand.nextDouble() - this.getSpawnerWorld().rand.nextDouble()) * (double)this.spawnRange + 0.5D;
                EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null;
                entity.setLocationAndAngles(d0, d1, d2, this.getSpawnerWorld().rand.nextFloat() * 360.0F, 0.0F);

                if (entityliving == null || entityliving.getCanSpawnHere() && entityliving.isNotColliding())
                {
                    this.spawnNewEntity(entity, true);
                    this.getSpawnerWorld().playAuxSFX(2004, blockpos, 0);

                    if (entityliving != null)
                    {
                        entityliving.spawnExplosionParticle();
                    }

                    flag = true;
                }
            }

            if (flag)
            {
                this.resetTimer();
            }
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:82,代码来源:MobSpawnerBaseLogic.java

示例5: spawnNewEntity

import net.minecraft.entity.EntityList; //导入方法依赖的package包/类
private Entity spawnNewEntity(Entity entityIn, boolean spawn)
{
    if (this.getRandomEntity() != null)
    {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        entityIn.writeToNBTOptional(nbttagcompound);

        for (String s : this.getRandomEntity().nbtData.getKeySet())
        {
            NBTBase nbtbase = this.getRandomEntity().nbtData.getTag(s);
            nbttagcompound.setTag(s, nbtbase.copy());
        }

        entityIn.readFromNBT(nbttagcompound);

        if (entityIn.worldObj != null && spawn)
        {
            entityIn.worldObj.spawnEntityInWorld(entityIn);
        }

        NBTTagCompound nbttagcompound2;

        for (Entity entity = entityIn; nbttagcompound.hasKey("Riding", 10); nbttagcompound = nbttagcompound2)
        {
            nbttagcompound2 = nbttagcompound.getCompoundTag("Riding");
            Entity entity1 = EntityList.createEntityByName(nbttagcompound2.getString("id"), entityIn.worldObj);

            if (entity1 != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                entity1.writeToNBTOptional(nbttagcompound1);

                for (String s1 : nbttagcompound2.getKeySet())
                {
                    NBTBase nbtbase1 = nbttagcompound2.getTag(s1);
                    nbttagcompound1.setTag(s1, nbtbase1.copy());
                }

                entity1.readFromNBT(nbttagcompound1);
                entity1.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);

                if (entityIn.worldObj != null && spawn)
                {
                    entityIn.worldObj.spawnEntityInWorld(entity1);
                }

                entity.mountEntity(entity1);
            }

            entity = entity1;
        }
    }
    else if (entityIn instanceof EntityLivingBase && entityIn.worldObj != null && spawn)
    {
        if (entityIn instanceof EntityLiving)
        {
            ((EntityLiving)entityIn).onInitialSpawn(entityIn.worldObj.getDifficultyForLocation(new BlockPos(entityIn)), (IEntityLivingData)null);
        }

        entityIn.worldObj.spawnEntityInWorld(entityIn);
    }

    return entityIn;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:65,代码来源:MobSpawnerBaseLogic.java

示例6: construct

import net.minecraft.entity.EntityList; //导入方法依赖的package包/类
/**
 * Construct entity by class in the world
 * @param world Target world
 * @return Spawned entity
 * */
public Entity construct(UWorld world) {
    return EntityList.createEntityByName(getName(), world.getWorld());
}
 
开发者ID:ternsip,项目名称:StructPro,代码行数:9,代码来源:UEntityClass.java


注:本文中的net.minecraft.entity.EntityList.createEntityByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。