net.minecraft.world.World.spawnEntity()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(331)

本文整理了Java中net.minecraft.world.World.spawnEntity()方法的一些代码示例,展示了World.spawnEntity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。World.spawnEntity()方法的具体详情如下:
包路径:net.minecraft.world.World
类名称:World
方法名:spawnEntity

World.spawnEntity介绍

暂无

代码示例

代码示例来源:origin: EngineHub/WorldEdit

@Override
public void dropItem(Vector3 position, BaseItemStack item) {
  checkNotNull(position);
  checkNotNull(item);
  if (item.getType() == ItemTypes.AIR) {
    return;
  }
  EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item));
  entity.setPickupDelay(10);
  getWorld().spawnEntity(entity);
}

代码示例来源:origin: EngineHub/WorldEdit

@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
  World world = getWorld();
  net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getType().getId()), world);
  if (createdEntity != null) {
    CompoundTag nativeTag = entity.getNbtData();
    if (nativeTag != null) {
      NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData());
      for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
        tag.removeTag(name);
      }
      createdEntity.readFromNBT(tag);
    }
    createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    world.spawnEntity(createdEntity);
    return new ForgeEntity(createdEntity);
  } else {
    return null;
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public AssemblerFX( final World w, final double x, final double y, final double z, final double r, final double g, final double b, final float speed, final IAEItemStack is )
{
  super( w, x, y, z, r, g, b );
  this.motionX = 0;
  this.motionY = 0;
  this.motionZ = 0;
  this.speed = speed;
  final ItemStack displayItem = is.asItemStackRepresentation();
  this.fi = new EntityFloatingItem( this, w, x, y, z, displayItem );
  w.spawnEntity( this.fi );
  this.particleMaxAge = (int) Math.ceil( Math.max( 1, 100.0f / speed ) ) + 2;
}

代码示例来源:origin: Vazkii/Botania

private void spawnMissile() {
  EntityMagicMissile missile = new EntityMagicMissile(this, true);
  missile.setPosition(posX + (Math.random() - 0.5 * 0.1), posY + 2.4 + (Math.random() - 0.5 * 0.1), posZ + (Math.random() - 0.5 * 0.1));
  if(missile.findTarget()) {
    playSound(ModSounds.missile, 0.6F, 0.8F + (float) Math.random() * 0.2F);
    world.spawnEntity(missile);
  }
}

代码示例来源:origin: Vazkii/Botania

private void dropAndKill() {
  ItemStack stack = getItemStack();
  EntityItem item = new EntityItem(world, posX, posY, posZ, stack);
  world.spawnEntity(item);
  setDead();
}

代码示例来源:origin: Vazkii/Botania

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
  if(!player.capabilities.isCreativeMode)
    player.getHeldItem(hand).shrink(1);
  world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  if(!world.isRemote) {
    EntityVineBall ball = new EntityVineBall(player, true);
    ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
    world.spawnEntity(ball);
  }
  return ActionResult.newResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}

代码示例来源:origin: Vazkii/Botania

@Override
public void breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
  TileEnchanter enchanter = (TileEnchanter) world.getTileEntity(pos);
  if(!enchanter.itemToEnchant.isEmpty()) {
    world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), enchanter.itemToEnchant));
  }
  world.updateComparatorOutputLevel(pos, state.getBlock());
  super.breakBlock(world, pos, state);
}

代码示例来源:origin: Vazkii/Botania

public boolean spawnMissile(World world, EntityLivingBase thrower, double x, double y, double z) {
  EntityMagicMissile missile;
  if(thrower != null)
    missile = new EntityMagicMissile(thrower, false);
  else missile = new EntityMagicMissile(world);
  missile.setPosition(x, y, z);
  if(missile.findTarget()) {
    if(!world.isRemote) {
      missile.playSound(ModSounds.missile, 0.6F, 0.8F + (float) Math.random() * 0.2F);
      world.spawnEntity(missile);
    }
    return true;
  }
  return false;
}

代码示例来源:origin: Vazkii/Botania

public void eject(ItemStack stack, boolean redstone) {
  EntityItem item = new EntityItem(world, pos.getX() + 0.5, pos.getY() - 0.5, pos.getZ() + 0.5, stack);
  item.motionX = 0;
  item.motionY = 0;
  item.motionZ = 0;
  if (redstone)
    item.age = -200;
  itemHandler.setStackInSlot(0, ItemStack.EMPTY);
  world.spawnEntity(item);
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public void startFuse( final World w, final BlockPos pos, final EntityLivingBase igniter )
{
  if( !w.isRemote )
  {
    final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( w, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, igniter );
    w.spawnEntity( primedTinyTNTEntity );
    w.playSound( null, primedTinyTNTEntity.posX, primedTinyTNTEntity.posY, primedTinyTNTEntity.posZ, SoundEvents.ENTITY_TNT_PRIMED,
        SoundCategory.BLOCKS, 1, 1 );
  }
}

代码示例来源:origin: Vazkii/Botania

private void spawnItem(ItemStack stack) {
  EntityItem item = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, stack);
  item.getEntityData().setBoolean(TAG_PORTAL_FLAG, true);
  world.spawnEntity(item);
  ticksSinceLastItem = 0;
}

代码示例来源:origin: Vazkii/Botania

public void mountEntity(Entity e) {
  BlockPos nextDest = getNextDestination();
  if(e.isRiding() || world.isRemote || nextDest == null || !isValidBinding())
    return;
  EntityPlayerMover mover = new EntityPlayerMover(world, pos, nextDest);
  world.spawnEntity(mover);
  e.startRiding(mover);
  if(!(e instanceof EntityItem)) {
    mover.playSound(ModSounds.lightRelay, 0.2F, (float) Math.random() * 0.3F + 0.7F);
  }
  if(e instanceof EntityPlayerMP) {
    PlayerHelper.grantCriterion((EntityPlayerMP) e, new ResourceLocation(LibMisc.MOD_ID, "main/luminizer_ride"), "code_triggered");
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
public void onBlockExploded( final World w, final BlockPos pos, final Explosion exp )
{
  super.onBlockExploded( w, pos, exp );
  if( !w.isRemote )
  {
    final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( w, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, exp
        .getExplosivePlacedBy() );
    primedTinyTNTEntity.setFuse( w.rand.nextInt( primedTinyTNTEntity.getFuse() / 4 ) + primedTinyTNTEntity.getFuse() / 8 );
    w.spawnEntity( primedTinyTNTEntity );
  }
}

代码示例来源:origin: Vazkii/Botania

@Override
public void doCorporeaRequest(Object request, int count, ICorporeaSpark spark) {
  if(!(request instanceof String))
    return;
  List<ItemStack> stacks = CorporeaHelper.requestItem((String) request, count, spark, true);
  spark.onItemsRequested(stacks);
  for(ItemStack stack : stacks)
    if(!stack.isEmpty()) {
      EntityItem item = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, stack);
      world.spawnEntity(item);
    }
}

代码示例来源:origin: Vazkii/Botania

@Override
public boolean collideBurst(IManaBurst burst, EntityThrowable entity, RayTraceResult pos, boolean isManaBlock, boolean dead, ItemStack stack) {
  if(!entity.world.isRemote && !burst.isFake()) {
    BlockPos coords = burst.getBurstSourceBlockPos();
    if(pos.entityHit == null && !isManaBlock && (pos.getBlockPos() == null || !pos.getBlockPos().equals(coords))) {
      ItemStack fireworkStack = generateFirework(burst.getColor());
      EntityFireworkRocket rocket = new EntityFireworkRocket(entity.world, entity.posX, entity.posY, entity.posZ, fireworkStack);
      entity.world.spawnEntity(rocket);
    }
  } else dead = false;
  return dead;
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onBurstCollision(IManaBurst burst, World world, BlockPos pos) {
  if(!burst.isFake() && !world.isRemote) {
    world.playEvent(2001, pos, Block.getStateId(getDefaultState()));
    world.setBlockToAir(pos);
    EntityManaStorm storm = new EntityManaStorm(world);
    storm.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
    world.spawnEntity(storm);
  }
}

代码示例来源:origin: Vazkii/Botania

public void trySpawnBurst(EntityPlayer player) {
  if (!player.getHeldItemMainhand().isEmpty()
      && player.getHeldItemMainhand().getItem() == this
      && player.getCooledAttackStrength(0) == 1) {
    EntityManaBurst burst = getBurst(player, player.getHeldItemMainhand());
    player.world.spawnEntity(burst);
    ToolCommons.damageItem(player.getHeldItemMainhand(), 1, player, MANA_PER_DAMAGE);
    player.world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.terraBlade, SoundCategory.PLAYERS, 0.4F, 1.4F);
  }
}

代码示例来源:origin: Vazkii/Botania

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing s, float xs, float ys, float zs) {
  ItemStack stack = player.getHeldItem(hand);
  if(!stack.isEmpty() && stack.getItem() == ModItems.manaResource && stack.getItemDamage() < 3) {
    if(!world.isRemote) {
      ItemStack target = stack.splitStack(1);
      EntityItem item = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, target);
      item.setPickupDelay(40);
      item.motionX = item.motionY = item.motionZ = 0;
      world.spawnEntity(item);
    }
    return true;
  }
  return false;
}

代码示例来源:origin: Vazkii/Botania

@Override
public void onAvatarUpdate(IAvatarTile tile, ItemStack stack) {
  TileEntity te = (TileEntity) tile;
  World world = te.getWorld();
  if(!world.isRemote && tile.getCurrentMana() >= COST && tile.getElapsedFunctionalTicks() % 300 == 0 && tile.isEnabled()) {
    EntityFlameRing entity = new EntityFlameRing(world);
    entity.setPosition(te.getPos().getX() + 0.5, te.getPos().getY(), te.getPos().getZ() + 0.5);
    world.spawnEntity(entity);
    tile.recieveMana(-COST);
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
  protected ItemStack dispenseStack( final IBlockSource dispenser, final ItemStack dispensedItem )
  {
    final EnumFacing enumfacing = dispenser.getBlockState().getValue( BlockDispenser.FACING );
    final World world = dispenser.getWorld();
    final int i = dispenser.getBlockPos().getX() + enumfacing.getFrontOffsetX();
    final int j = dispenser.getBlockPos().getY() + enumfacing.getFrontOffsetY();
    final int k = dispenser.getBlockPos().getZ() + enumfacing.getFrontOffsetZ();
    final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( world, i + 0.5F, j + 0.5F, k + 0.5F, null );
    world.spawnEntity( primedTinyTNTEntity );
    dispensedItem.setCount( dispensedItem.getCount() - 1 );
    return dispensedItem;
  }
}

相关文章

微信公众号

最新文章

更多

World类方法