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

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

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

World.spawnEntityInWorld介绍

暂无

代码示例

代码示例来源:origin: AlgorithmX2/Chisels-and-Bits

  1. private static void spawnItem(
  2. World world,
  3. EntityItem ei )
  4. {
  5. if ( world.isRemote ) // no spawning items on the client.
  6. return;
  7. world.spawnEntityInWorld( ei );
  8. }
  9. }

代码示例来源:origin: coolAlias/Tutorial-Demo

  1. @Override
  2. public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
  3. if (!player.capabilities.isCreativeMode) {
  4. --stack.stackSize;
  5. }
  6. world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  7. if (!world.isRemote) {
  8. world.spawnEntityInWorld(new EntityThrowingRock(world, player));
  9. }
  10. return stack;
  11. }
  12. }

代码示例来源:origin: Electrical-Age/ElectricalAge

  1. public static void dropItem(ItemStack itemStack, int x, int y, int z, World world) {
  2. if (itemStack == null)
  3. return;
  4. if (world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
  5. float var6 = 0.7F;
  6. double var7 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
  7. double var9 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
  8. double var11 = (double) (world.rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
  9. EntityItem var13 = new EntityItem(world, (double) x + var7, (double) y + var9, (double) z + var11, itemStack);
  10. var13.delayBeforeCanPickup = 10;
  11. world.spawnEntityInWorld(var13);
  12. }
  13. }

代码示例来源:origin: squeek502/VeganOption

  1. @Override
  2. public ActionResult<ItemStack> onItemRightClick(ItemStack itemStack, World world, EntityPlayer player, EnumHand hand)
  3. {
  4. if (!player.capabilities.isCreativeMode)
  5. {
  6. --itemStack.stackSize;
  7. }
  8. player.playSound(throwSound, 0.5F, 0.4F / (RandomHelper.random.nextFloat() * 0.4F + 0.8F));
  9. if (!world.isRemote)
  10. {
  11. EntityThrowable entity = getNewThrownEntity(world, player);
  12. entity.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, throwSpeed, 1.0F);
  13. world.spawnEntityInWorld(entity);
  14. }
  15. return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
  16. }

代码示例来源:origin: squeek502/VeganOption

  1. public void freeze()
  2. {
  3. if (!this.worldObj.isRemote)
  4. {
  5. EntityItem frozenBubble = new EntityItem(worldObj, posX, posY, posZ, new ItemStack(FrozenBubble.frozenBubble));
  6. worldObj.spawnEntityInWorld(frozenBubble);
  7. this.setDead();
  8. }
  9. }

代码示例来源:origin: Electrical-Age/ElectricalAge

  1. public void dropItem(ItemStack itemStack) {
  2. if (itemStack == null) return;
  3. if (coordonate.world().getGameRules().getGameRuleBooleanValue("doTileDrops")) {
  4. float var6 = 0.7F;
  5. double var7 = (double) (coordonate.world().rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
  6. double var9 = (double) (coordonate.world().rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
  7. double var11 = (double) (coordonate.world().rand.nextFloat() * var6) + (double) (1.0F - var6) * 0.5D;
  8. EntityItem var13 = new EntityItem(coordonate.world(), (double) coordonate.x + var7, (double) coordonate.y + var9, (double) coordonate.z + var11, itemStack);
  9. var13.delayBeforeCanPickup = 10;
  10. coordonate.world().spawnEntityInWorld(var13);
  11. }
  12. }

代码示例来源:origin: Electrical-Age/ElectricalAge

  1. @Override
  2. protected void updateAITick() {
  3. super.updateAITick();
  4. //setDead();
  5. hunger += 0.05 / hungerTime;
  6. if (hunger > 1 && Math.random() < 0.05 / 5) {
  7. attackEntityFrom(DamageSource.starve, 1);
  8. }
  9. if (hunger < 0.5 && Math.random() * 10 < 0.05) {
  10. heal(1f);
  11. }
  12. if (hunger < hungerToDuplicate) {
  13. ReplicatorEntity entityliving = new ReplicatorEntity(this.worldObj);
  14. entityliving.setLocationAndAngles(this.posX, this.posY, this.posZ, 0f, 0f);
  15. entityliving.rotationYawHead = entityliving.rotationYaw;
  16. entityliving.renderYawOffset = entityliving.rotationYaw;
  17. worldObj.spawnEntityInWorld(entityliving);
  18. entityliving.playLivingSound();
  19. hunger = 0;
  20. }
  21. }

代码示例来源:origin: portablejim/VeinMiner

  1. private void spawnDrops() {
  2. for(Map.Entry<ItemStackID, Integer> schedDrop : drops.entrySet()) {
  3. ItemStackID itemStack = schedDrop.getKey();
  4. String itemName = itemStack.getItemId();
  5. Item foundItem = Item.getByNameOrId(itemName);
  6. if(foundItem == null) {
  7. continue;
  8. }
  9. int itemDamage = itemStack.getDamage();
  10. int numItems = schedDrop.getValue();
  11. while (numItems > itemStack.getMaxStackSize()) {
  12. ItemStack newItemStack = new ItemStack(foundItem, itemStack.getMaxStackSize(), itemDamage);
  13. EntityItem newEntityItem = new EntityItem(world, initalBlock.getX() + 0.5F, initalBlock.getY() + 0.5F, initalBlock.getZ() + 0.5F, newItemStack);
  14. world.spawnEntityInWorld(newEntityItem);
  15. numItems -= itemStack.getMaxStackSize();
  16. }
  17. ItemStack newItemStack = new ItemStack(foundItem, numItems, itemDamage);
  18. newItemStack.setItemDamage(itemStack.getDamage());
  19. EntityItem newEntityItem = new EntityItem(world, initalBlock.getX() + 0.5F, initalBlock.getY() + 0.5F, initalBlock.getZ() + 0.5F, newItemStack);
  20. world.spawnEntityInWorld(newEntityItem);
  21. }
  22. drops.clear();
  23. }

代码示例来源:origin: joshiejack/Mariculture

  1. @Override
  2. @Nonnull
  3. @SuppressWarnings("ConstantConditions")
  4. public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, @Nonnull World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
  5. if (playerIn.fishEntity != null) {
  6. FishingRod rod = FishingAPI.INSTANCE.getFishingRodFromStack(stack);
  7. if (rod != null) rod.setCastStatus(false);
  8. int damage = playerIn.fishEntity.handleHookRetraction();
  9. for (FishingTrait trait: FishingRodHelper.getTraits(stack)) {
  10. damage = trait.modifyDamage(worldIn.rand, damage);
  11. }
  12. if (damage > 0 && FishingRodHelper.isDamageable(stack)) {
  13. stack.damageItem(damage, playerIn);
  14. }
  15. playerIn.swingArm(hand);
  16. } else {
  17. worldIn.playSound(null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  18. FishingRod rod = FishingAPI.INSTANCE.getFishingRodFromStack(stack);
  19. if (rod != null) rod.setCastStatus(true);
  20. if (!worldIn.isRemote) {
  21. worldIn.spawnEntityInWorld(new EntityFishHookMC(worldIn, playerIn, null));
  22. }
  23. playerIn.swingArm(hand);
  24. playerIn.addStat(StatList.getObjectUseStats(this));
  25. }
  26. return new ActionResult<>(EnumActionResult.SUCCESS, stack);
  27. }

代码示例来源:origin: squeek502/VeganOption

  1. @Override
  2. public ItemStack onItemUseFinish(ItemStack itemStack, World world, EntityLivingBase player)
  3. {
  4. if (!world.isRemote)
  5. {
  6. EntityBubble bubble = new EntityBubble(world, player);
  7. bubble.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, BUBBLE_INITIAL_VELOCITY, 1.0F);
  8. world.spawnEntityInWorld(bubble);
  9. }
  10. itemStack.damageItem(1, player);
  11. if (itemStack.stackSize == 0 && getContainerItem() != null)
  12. {
  13. return new ItemStack(getContainerItem());
  14. }
  15. return super.onItemUseFinish(itemStack, world, player);
  16. }

代码示例来源:origin: ata4/dragon-mounts

  1. /**
  2. * Spawns a baby animal of the same type.
  3. */
  4. private void spawnBaby() {
  5. EntityTameableDragon dragonBaby = (EntityTameableDragon) dragon.createChild(dragonMate);
  6. if (dragonBaby != null) {
  7. dragon.setGrowingAge(6000);
  8. dragonMate.setGrowingAge(6000);
  9. dragon.resetInLove();
  10. dragonMate.resetInLove();
  11. dragonBaby.setLocationAndAngles(dragon.posX, dragon.posY, dragon.posZ, 0, 0);
  12. dragonBaby.getLifeStageHelper().setLifeStage(EnumDragonLifeStage.EGG);
  13. world.spawnEntityInWorld(dragonBaby);
  14. // TODO: particles for the clients?
  15. }
  16. }
  17. }

代码示例来源:origin: Electrical-Age/ElectricalAge

  1. @Override
  2. public void process(double time) {
  3. energy -= powerResistor.getP() * time;
  4. if (inventory.getStackInSlot(EggIncubatorContainer.EggSlotId) != null) {
  5. descriptor.setState(powerResistor, true);
  6. if (energy <= 0) {
  7. inventory.decrStackSize(EggIncubatorContainer.EggSlotId, 1);
  8. EntityChicken chicken = new EntityChicken(node.coordonate.world());
  9. chicken.setGrowingAge(-24000);
  10. EntityLiving entityliving = (EntityLiving) chicken;
  11. entityliving.setLocationAndAngles(node.coordonate.x + 0.5, node.coordonate.y + 0.5, node.coordonate.z + 0.5, MathHelper.wrapAngleTo180_float(node.coordonate.world().rand.nextFloat() * 360.0F), 0.0F);
  12. entityliving.rotationYawHead = entityliving.rotationYaw;
  13. entityliving.renderYawOffset = entityliving.rotationYaw;
  14. //entityliving.func_110161_a((EntityLivingData)null); 1.6.4
  15. node.coordonate.world().spawnEntityInWorld(entityliving);
  16. entityliving.playLivingSound();
  17. //node.coordonate.world().spawnEntityInWorld());
  18. resetEnergy();
  19. needPublish();
  20. }
  21. } else {
  22. descriptor.setState(powerResistor, false);
  23. resetEnergy();
  24. }
  25. if (Math.abs(powerLoad.getU() - lastVoltagePublish) / descriptor.nominalVoltage > 0.1) needPublish();
  26. }

代码示例来源:origin: Electrical-Age/ElectricalAge

  1. entityliving.rotationYawHead = entityliving.rotationYaw;
  2. entityliving.renderYawOffset = entityliving.rotationYaw;
  3. world.spawnEntityInWorld(entityliving);
  4. entityliving.playLivingSound();
  5. entityliving.isSpawnedFromWeather = true;

代码示例来源:origin: joshiejack/Mariculture

  1. @SubscribeEvent
  2. public void onKillChicken(LivingDeathEvent event) {
  3. if (Debug.CHICKEN_FISHING > 0) {
  4. EntityPlayer angler = event.getSource().getEntity() instanceof EntityPlayer ? (EntityPlayer) event.getSource().getEntity() : null;
  5. if (angler != null && !angler.worldObj.isRemote && event.getEntityLiving() instanceof EntityChicken) {
  6. for (int i = 0; i < Debug.CHICKEN_FISHING; i++) {
  7. LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) angler.worldObj);
  8. lootcontext$builder.withLuck((float) EnchantmentHelper.getLuckOfSeaModifier(angler) + angler.getLuck());
  9. lootcontext$builder.withPlayer(angler); //Added by Mariculture
  10. lootcontext$builder.withLootedEntity(event.getEntityLiving()); //Added by Mariculture
  11. for (ItemStack itemstack : angler.worldObj.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(this.rand, lootcontext$builder.build())) {
  12. EntityItem entityitem = new EntityItem(angler.worldObj, event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, itemstack);
  13. double d0 = angler.posX - event.getEntityLiving().posX;
  14. double d1 = angler.posY - event.getEntityLiving().posY;
  15. double d2 = angler.posZ - event.getEntityLiving().posZ;
  16. double d3 = (double) MathHelper.sqrt_double(d0 * d0 + d1 * d1 + d2 * d2);
  17. double d4 = 0.1D;
  18. entityitem.motionX = d0 * d4;
  19. entityitem.motionY = d1 * d4 + (double) MathHelper.sqrt_double(d3) * 0.08D;
  20. entityitem.motionZ = d2 * d4;
  21. angler.worldObj.spawnEntityInWorld(entityitem);
  22. angler.worldObj.spawnEntityInWorld(new EntityXPOrb(angler.worldObj, angler.posX, angler.posY + 0.5D, angler.posZ + 0.5D, this.rand.nextInt(6) + 1));
  23. }
  24. }
  25. }
  26. }
  27. }
  28. }

代码示例来源:origin: joshiejack/Mariculture

  1. entityitem.motionY = d1 * d4 + (double) MathHelper.sqrt_double(d3) * 0.08D;
  2. entityitem.motionZ = d2 * d4;
  3. worldObj.spawnEntityInWorld(entityitem);
  4. angler.worldObj.spawnEntityInWorld(new EntityXPOrb(angler.worldObj, angler.posX, angler.posY + 0.5D, angler.posZ + 0.5D, xp));

代码示例来源:origin: AlgorithmX2/Chisels-and-Bits

  1. player.getEntityWorld().spawnEntityInWorld( ei );

代码示例来源:origin: squeek502/VeganOption

  1. public boolean tryFillContainersInside()
  2. {
  3. if (worldObj == null || worldObj.isRemote || !couldFillContainers())
  4. return false;
  5. List<EntityItem> entityItemsWithin = WorldHelper.getItemEntitiesWithin(worldObj, ((BlockBasin) Basin.basin).getInnerBoundingBox(worldObj, pos.getX(), pos.getY(), pos.getZ()));
  6. for (EntityItem entityItemWithin : entityItemsWithin)
  7. {
  8. if (!FluidContainerHelper.isEmptyContainer(entityItemWithin.getEntityItem()))
  9. continue;
  10. EntityItem entityItemToFill = entityItemWithin;
  11. ItemStack containerToFill = entityItemWithin.getEntityItem().splitStack(1);
  12. FluidContainerHelper.drainHandlerIntoContainer(fluidTank, fluidTank.getFluid(), containerToFill);
  13. if (!FluidContainerHelper.isEmptyContainer(containerToFill))
  14. {
  15. entityItemToFill = new EntityItem(entityItemToFill.worldObj, entityItemToFill.posX, entityItemToFill.posY, entityItemToFill.posZ, containerToFill);
  16. entityItemToFill.setPickupDelay(10);
  17. entityItemToFill.worldObj.spawnEntityInWorld(entityItemToFill);
  18. }
  19. return true;
  20. }
  21. return false;
  22. }

代码示例来源:origin: squeek502/VeganOption

  1. public static boolean tryWash(EntityItem entityItem)
  2. {
  3. if (entityItem == null || entityItem.worldObj.isRemote || entityItem.getEntityItem() == null)
  4. return false;
  5. if (!isReadyToCook(entityItem.getEntityItem()))
  6. {
  7. BlockPos fluidBlockPos = new BlockPos(MathHelper.floor_double(entityItem.posX), MathHelper.floor_double(entityItem.posY), MathHelper.floor_double(entityItem.posZ));
  8. FluidStack consumedFluid = FluidHelper.consumeExactFluid(entityItem.worldObj, fluidBlockPos, FluidRegistry.WATER, Fluid.BUCKET_VOLUME);
  9. if (consumedFluid != null)
  10. {
  11. EntityItem entityItemToWash = entityItem;
  12. ItemStack doughToWash = entityItemToWash.getEntityItem();
  13. if (entityItemToWash.getEntityItem().stackSize > 1)
  14. {
  15. doughToWash = entityItem.getEntityItem().splitStack(1);
  16. entityItemToWash = new EntityItem(entityItemToWash.worldObj, entityItemToWash.posX, entityItemToWash.posY, entityItemToWash.posZ, doughToWash);
  17. entityItemToWash.setPickupDelay(10);
  18. entityItemToWash.worldObj.spawnEntityInWorld(entityItemToWash);
  19. }
  20. ItemStack washedItemStack = wash(doughToWash, 1);
  21. entityItemToWash.setEntityItemStack(washedItemStack);
  22. return true;
  23. }
  24. }
  25. return false;
  26. }

代码示例来源:origin: squeek502/VeganOption

  1. public static boolean tryFillWithRawEnderFromWorld(EntityItem entityItem)
  2. {
  3. if (entityItem == null || entityItem.worldObj.isRemote || entityItem.getEntityItem() == null)
  4. return false;
  5. if (!isFull(entityItem.getEntityItem()))
  6. {
  7. BlockPos fluidBlockPos = new BlockPos(MathHelper.floor_double(entityItem.posX), MathHelper.floor_double(entityItem.posY), MathHelper.floor_double(entityItem.posZ));
  8. FluidStack consumedFluid = FluidHelper.consumeExactFluid(entityItem.worldObj, fluidBlockPos, Ender.fluidRawEnder, FluidHelper.FINITE_FLUID_MB_PER_META);
  9. if (consumedFluid != null)
  10. {
  11. EntityItem entityItemToFill = entityItem;
  12. ItemStack bubbleToFill = entityItemToFill.getEntityItem();
  13. if (entityItemToFill.getEntityItem().stackSize > 1)
  14. {
  15. bubbleToFill = entityItem.getEntityItem().splitStack(1);
  16. entityItemToFill = new EntityItem(entityItemToFill.worldObj, entityItemToFill.posX, entityItemToFill.posY, entityItemToFill.posZ, bubbleToFill);
  17. entityItemToFill.setPickupDelay(10);
  18. entityItemToFill.worldObj.spawnEntityInWorld(entityItemToFill);
  19. }
  20. ItemStack filledItemStack = fill(bubbleToFill, 1);
  21. entityItemToFill.setEntityItemStack(filledItemStack);
  22. return true;
  23. }
  24. }
  25. return false;
  26. }

代码示例来源:origin: ata4/dragon-mounts

  1. world.spawnEntityInWorld(dragon);

相关文章

World类方法