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

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

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

World.spawnEntity介绍

暂无

代码示例

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

  1. @Override
  2. public void dropItem(Vector3 position, BaseItemStack item) {
  3. checkNotNull(position);
  4. checkNotNull(item);
  5. if (item.getType() == ItemTypes.AIR) {
  6. return;
  7. }
  8. EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), ForgeWorldEdit.toForgeItemStack(item));
  9. entity.setPickupDelay(10);
  10. getWorld().spawnEntity(entity);
  11. }

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

  1. @Nullable
  2. @Override
  3. public Entity createEntity(Location location, BaseEntity entity) {
  4. World world = getWorld();
  5. net.minecraft.entity.Entity createdEntity = EntityList.createEntityByIDFromName(new ResourceLocation(entity.getType().getId()), world);
  6. if (createdEntity != null) {
  7. CompoundTag nativeTag = entity.getNbtData();
  8. if (nativeTag != null) {
  9. NBTTagCompound tag = NBTConverter.toNative(entity.getNbtData());
  10. for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
  11. tag.removeTag(name);
  12. }
  13. createdEntity.readFromNBT(tag);
  14. }
  15. createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
  16. world.spawnEntity(createdEntity);
  17. return new ForgeEntity(createdEntity);
  18. } else {
  19. return null;
  20. }
  21. }

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

  1. 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 )
  2. {
  3. super( w, x, y, z, r, g, b );
  4. this.motionX = 0;
  5. this.motionY = 0;
  6. this.motionZ = 0;
  7. this.speed = speed;
  8. final ItemStack displayItem = is.asItemStackRepresentation();
  9. this.fi = new EntityFloatingItem( this, w, x, y, z, displayItem );
  10. w.spawnEntity( this.fi );
  11. this.particleMaxAge = (int) Math.ceil( Math.max( 1, 100.0f / speed ) ) + 2;
  12. }

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

  1. private void spawnMissile() {
  2. EntityMagicMissile missile = new EntityMagicMissile(this, true);
  3. 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));
  4. if(missile.findTarget()) {
  5. playSound(ModSounds.missile, 0.6F, 0.8F + (float) Math.random() * 0.2F);
  6. world.spawnEntity(missile);
  7. }
  8. }

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

  1. private void dropAndKill() {
  2. ItemStack stack = getItemStack();
  3. EntityItem item = new EntityItem(world, posX, posY, posZ, stack);
  4. world.spawnEntity(item);
  5. setDead();
  6. }

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

  1. @Nonnull
  2. @Override
  3. public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
  4. if(!player.capabilities.isCreativeMode)
  5. player.getHeldItem(hand).shrink(1);
  6. 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));
  7. if(!world.isRemote) {
  8. EntityVineBall ball = new EntityVineBall(player, true);
  9. ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
  10. world.spawnEntity(ball);
  11. }
  12. return ActionResult.newResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
  13. }

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

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

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

  1. public boolean spawnMissile(World world, EntityLivingBase thrower, double x, double y, double z) {
  2. EntityMagicMissile missile;
  3. if(thrower != null)
  4. missile = new EntityMagicMissile(thrower, false);
  5. else missile = new EntityMagicMissile(world);
  6. missile.setPosition(x, y, z);
  7. if(missile.findTarget()) {
  8. if(!world.isRemote) {
  9. missile.playSound(ModSounds.missile, 0.6F, 0.8F + (float) Math.random() * 0.2F);
  10. world.spawnEntity(missile);
  11. }
  12. return true;
  13. }
  14. return false;
  15. }

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

  1. public void eject(ItemStack stack, boolean redstone) {
  2. EntityItem item = new EntityItem(world, pos.getX() + 0.5, pos.getY() - 0.5, pos.getZ() + 0.5, stack);
  3. item.motionX = 0;
  4. item.motionY = 0;
  5. item.motionZ = 0;
  6. if (redstone)
  7. item.age = -200;
  8. itemHandler.setStackInSlot(0, ItemStack.EMPTY);
  9. world.spawnEntity(item);
  10. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. @Override
  2. protected ItemStack dispenseStack( final IBlockSource dispenser, final ItemStack dispensedItem )
  3. {
  4. final EnumFacing enumfacing = dispenser.getBlockState().getValue( BlockDispenser.FACING );
  5. final World world = dispenser.getWorld();
  6. final int i = dispenser.getBlockPos().getX() + enumfacing.getFrontOffsetX();
  7. final int j = dispenser.getBlockPos().getY() + enumfacing.getFrontOffsetY();
  8. final int k = dispenser.getBlockPos().getZ() + enumfacing.getFrontOffsetZ();
  9. final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( world, i + 0.5F, j + 0.5F, k + 0.5F, null );
  10. world.spawnEntity( primedTinyTNTEntity );
  11. dispensedItem.setCount( dispensedItem.getCount() - 1 );
  12. return dispensedItem;
  13. }
  14. }

相关文章

World类方法