@Override
 public void onBlockDestroyed(
     ItemStack itemStack,
     World world,
     Block block,
     int x,
     int y,
     int z,
     EntityLivingBase entityLiving) {
   if (!world.isRemote) {
     int bonus = (int) (rand.nextDouble() * Math.log(this.power));
     if (block == Blocks.coal_ore) {
       world.spawnEntityInWorld(
           new EntityItem(
               world,
               x + rand.nextDouble(),
               y + rand.nextDouble(),
               z + rand.nextDouble(),
               new ItemStack(Items.coal, bonus, 0)));
     }
     if (block == Blocks.diamond_ore) {
       world.spawnEntityInWorld(
           new EntityItem(
               world,
               x + rand.nextDouble(),
               y + rand.nextDouble(),
               z + rand.nextDouble(),
               new ItemStack(Items.diamond, bonus, 0)));
     }
   }
 }
  public boolean onBlockActivated(
      World world, int x, int y, int z, EntityPlayer player, int i, float a, float b, float c) {

    if (player.getHeldItem() != null) {

      if (player.getHeldItem().itemID == CheapSkateItems.oneCoin.itemID) {
        if (player.getHeldItem().stackSize == 64) {
          player.getHeldItem().stackSize = 0;

          if (!world.isRemote) {

            ItemStack ironIngot = new ItemStack(Item.ingotIron, 1);
            EntityItem entityitem = new EntityItem(world, x, y + (double) 3, z, ironIngot);
            entityitem.delayBeforeCanPickup = 10;
            world.spawnEntityInWorld(entityitem);
          }
        }
      }
      if (player.getHeldItem().itemID == CheapSkateItems.twoCoin.itemID) {
        if (player.getHeldItem().stackSize >= 32) {
          player.getHeldItem().stackSize = player.getHeldItem().stackSize - 32;

          if (!world.isRemote) {

            ItemStack ironIngot = new ItemStack(Item.ingotIron, 1);
            EntityItem entityitem = new EntityItem(world, x, y + (double) 3, z, ironIngot);
            entityitem.delayBeforeCanPickup = 10;
            world.spawnEntityInWorld(entityitem);
          }
        }
      }
    }

    return true;
  }
  protected boolean spawnMob(IBeeGenome genome, IBeeHousing housing) {
    boolean flag = false;

    World w = housing.getWorld();
    int roll = 0;

    for (int i = 0; i < this.spawnChance.length && !flag; ++i) {
      roll = 100 - w.rand.nextInt(100) + 1;
      if (roll < this.spawnChance[i]) {
        flag = true;
        Entity mob = EntityList.createEntityByName(this.entityNames[i], w);
        // .createEntityByName method returns null when spawning a ghast in the overworld
        if (mob == null) return false;
        double[] coords = this.randomMobSpawnCoords(w, genome, housing);

        mob.setPositionAndRotation(coords[0], coords[1], coords[2], w.rand.nextFloat() * 360f, 0f);
        if (mob instanceof EntityLiving) {
          if (((EntityLiving) mob).getCanSpawnHere()) {
            w.spawnEntityInWorld(mob);
          }
        } else {
          w.spawnEntityInWorld(mob);
        }
      }
    }

    return flag;
  }
  // result
  private void getRecipeFood(
      World world, int x, int y, int z, EntityPlayer player, ItemStack input, ItemStack result) {
    if (input == null || input.getItem() == null) return;
    ItemStack container = null;
    if (FluidContainerRegistry.isFilledContainer(input)) {
      container = FluidContainerRegistry.drainFluidContainer(input);
    } else {
      container = input.getItem().getContainerItem(input);
    }

    if (!player.capabilities.isCreativeMode && --input.stackSize <= 0) {
      player.inventory.setInventorySlotContents(player.inventory.currentItem, (ItemStack) null);
    }

    if (!world.isRemote) {
      EntityItem entity = new EntityItem(world, player.posX, player.posY, player.posZ, result);
      world.spawnEntityInWorld(entity);
    }

    if (container != null) {
      if (!world.isRemote) {
        EntityItem entity = new EntityItem(world, player.posX, player.posY, player.posZ, container);
        world.spawnEntityInWorld(entity);
      }
    }

    world.playSoundAtEntity(player, "random.pop", 0.4F, 1.8F);
  }
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (world.isRemote) {
      return true;
    }

    ItemStack held = player.getHeldItem();
    FluidStack fluidHeld = FluidContainerRegistry.getFluidForFilledItem(held);
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (fluidHeld != null
        && fluidHeld.getFluid() == FluidRegistry.getFluid("water")
        && tileEntity instanceof TileSolarCollector) {
      TileSolarCollector tank = (TileSolarCollector) tileEntity;
      if (tank.canReceiveWaterBucket()) {
        tank.addBucketOfWater();
        if (FluidContainerRegistry.isBucket(held)
            && !(((EntityPlayerMP) player).theItemInWorldManager.isCreative())) {
          int heldLocation = player.inventory.currentItem;
          player.inventory.decrStackSize(heldLocation, 1);
          world.spawnEntityInWorld(
              new EntityItem(
                  world, player.posX, player.posY, player.posZ, new ItemStack(Items.bucket, 1)));
          //                    player.inventory.setInventorySlotContents(heldLocation, new
          // ItemStack(Items.bucket, 1));
        }
      }
      return true;
    }
    if (held != null
        && held.getItem() == Items.bucket
        && tileEntity instanceof TileSolarCollector) {
      TileSolarCollector tank = (TileSolarCollector) tileEntity;
      if (tank.canGiveSolarWater()) {
        ItemStack filledBucket =
            FluidContainerRegistry.fillFluidContainer(
                new FluidStack(ModFluids.fluidSolarWater, 1000), new ItemStack(Items.bucket, 1));
        tank.removeBucketOfSolarWater();
        if (!(((EntityPlayerMP) player).theItemInWorldManager.isCreative())) {
          player.inventory.decrStackSize(player.inventory.currentItem, 1);
          // player.inventory.setInventorySlotContents(player.inventory.getFirstEmptyStack(),
          // filledBucket);
          world.spawnEntityInWorld(
              new EntityItem(world, player.posX, player.posY, player.posZ, filledBucket));
        }
        return true;
      }
    }

    return false;
  }
  @Override
  public void onPlayerStoppedUsing(
      ItemStack stack, World world, EntityPlayer player, int p_77615_4_) {

    int j = this.getMaxItemUseDuration(stack) - p_77615_4_;

    stack.stackTagCompound = new NBTTagCompound();
    stack.stackTagCompound.setInteger("D", 0);
    stack.damageItem(1, player);
    player.worldObj.playSoundAtEntity(player, (Main.MODID + ":longbowRelease"), 0.8F, 1.0F);

    if ((player.inventory.getStackInSlot(player.inventory.currentItem - 1) != null)) {
      if ((player.inventory.getStackInSlot(player.inventory.currentItem - 1).getItem()
          == (ModItems.itemModelArrow))) {
        float f = j / 20.0F;
        f = (f * f + f * 2.0F) / 3.0F;

        if (f < 0.1D) {
          return;
        }

        if (f > 1.0F) {
          f = 1.0F;
        }

        player.inventory.consumeInventoryItem(ModItems.itemModelArrow);

        // EntityArrow arrow = new EntityArrow(world, player, f * 2.0F);

        if (!world.isRemote) {
          EntityModelArrow arrow = new EntityModelArrow(world, player, f * 2.0F);
          world.spawnEntityInWorld(arrow);
        }
      }
      if ((player.inventory.getStackInSlot(player.inventory.currentItem - 1).getItem()
          == (ModItems.itemIronTippedModelArrow))) {
        float f = j / 20.0F;
        f = (f * f + f * 2.0F) / 3.0F;

        if (f < 0.1D) {
          return;
        }

        if (f > 1.0F) {
          f = 1.0F;
        }

        player.inventory.consumeInventoryItem(ModItems.itemIronTippedModelArrow);

        // EntityArrow arrow = new EntityArrow(world, player, f * 2.0F);

        if (!world.isRemote) {
          EntityModelITArrow arrow = new EntityModelITArrow(world, player, f * 2.0F);
          world.spawnEntityInWorld(arrow);
        }
      }
    }
    bowUse = false;
  }
  // ブロックのドロップ時に中身を落とす
  @Override
  public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
    TileIncenseBase tile = (TileIncenseBase) world.getTileEntity(x, y, z);
    if (tile != null) {
      ItemStack drop = tile.getItemstack();
      ItemStack ash = tile.getAsh();
      if (drop != null) {
        float f = world.rand.nextFloat() * 0.8F + 0.1F;
        float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
        float f2 = world.rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityitem =
            new EntityItem(
                world,
                (double) ((float) x + f),
                (double) ((float) y + f1),
                (double) ((float) z + f2),
                drop.copy());

        if (drop.hasTagCompound()) {
          entityitem.getEntityItem().setTagCompound((NBTTagCompound) drop.getTagCompound().copy());
        }

        float f3 = 0.05F;
        entityitem.motionX = (double) ((float) world.rand.nextGaussian() * f3);
        entityitem.motionY = (double) ((float) world.rand.nextGaussian() * f3 + 0.2F);
        entityitem.motionZ = (double) ((float) world.rand.nextGaussian() * f3);
        world.spawnEntityInWorld(entityitem);
      }
      if (ash != null) {
        float f = world.rand.nextFloat() * 0.8F + 0.1F;
        float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
        float f2 = world.rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityitem2 =
            new EntityItem(
                world,
                (double) ((float) x + f),
                (double) ((float) y + f1),
                (double) ((float) z + f2),
                ash.copy());

        if (ash.hasTagCompound()) {
          entityitem2.getEntityItem().setTagCompound((NBTTagCompound) ash.getTagCompound().copy());
        }

        float f3 = 0.05F;
        entityitem2.motionX = (double) ((float) world.rand.nextGaussian() * f3);
        entityitem2.motionY = (double) ((float) world.rand.nextGaussian() * f3 + 0.2F);
        entityitem2.motionZ = (double) ((float) world.rand.nextGaussian() * f3);
        world.spawnEntityInWorld(entityitem2);
      }
    }

    super.breakBlock(world, x, y, z, block, meta);
  }
 @Override
 public boolean onBlockActivated(
     World w, int x, int y, int z, EntityPlayer player, int i, float f1, float f2, float f3) {
   if (w.getTileEntity(x, y, z) instanceof TileEntityAlchemicChemistryKit) {
     TileEntityAlchemicChemistryKit te = (TileEntityAlchemicChemistryKit) w.getTileEntity(x, y, z);
     ItemStack item = player.getCurrentEquippedItem();
     if (player.isSneaking()) {
       if (te.getStackInSlot(0) != null && te.getStackInSlot(1) != null) {
         ItemStack stack =
             FMAlchemyAPI.instance.getAlchemicChemistryOutput(
                 te.getStackInSlot(0).getItem(), te.getStackInSlot(1).getItem());
         if (stack != null) {
           te.setInventorySlotContents(0, null);
           te.setInventorySlotContents(1, null);
           te.setInventorySlotContents(0, stack);
         }
       }
     } else {
       if (i == ForgeDirection.UP.ordinal()) {
         if (item != null) {
           if (te.getStackInSlot(0) != null) {
             if (!w.isRemote) {
               w.spawnEntityInWorld(new EntityItem(w, x, y + 1, z, te.getStackInSlot(0)));
             }
             te.setInventorySlotContents(0, null);
           } else {
             ItemStack toput = new ItemStack(item.getItem(), 1, item.getItemDamage());
             toput.stackTagCompound = item.stackTagCompound;
             te.setInventorySlotContents(0, toput);
             item.stackSize--;
           }
           return true;
         }
       } else {
         if (item != null) {
           if (te.getStackInSlot(1) != null) {
             if (!w.isRemote) {
               w.spawnEntityInWorld(new EntityItem(w, x, y + 1, z, te.getStackInSlot(1)));
             }
             te.setInventorySlotContents(1, null);
           } else {
             ItemStack toput = new ItemStack(item.getItem(), 1, item.getItemDamage());
             toput.stackTagCompound = item.stackTagCompound;
             te.setInventorySlotContents(1, toput);
             item.stackSize--;
           }
           return true;
         }
       }
       return false;
     }
   }
   return false;
 }
 @Override
 public void breakBlock(World w, int x, int y, int z, Block b, int i) {
   if (w.getTileEntity(x, y, z) instanceof TileEntityPedestal) {
     TileEntityPedestal te = (TileEntityPedestal) w.getTileEntity(x, y, z);
     if (!w.isRemote) {
       if (te.getStackInSlot(0) != null) {
         w.spawnEntityInWorld(new EntityItem(w, x, y + 1, z, te.getStackInSlot(0)));
       }
       if (te.getStackInSlot(1) != null) {
         w.spawnEntityInWorld(new EntityItem(w, x, y + 1, z, te.getStackInSlot(1)));
       }
     }
   }
   super.breakBlock(w, x, y, z, b, i);
 }
  public void onPlayerStoppedUsing(ItemStack var1, World var2, EntityPlayer var3, int var4) {
    int var5 = var3.getFoodStats().getFoodLevel();

    if (var5 > 6) {
      int var6 = this.getMaxItemUseDuration(var1) - var4;
      float var7 = (float) var6 / 20.0F;
      var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;

      if (var7 >= 1.0F && var5 > 7) {
        for (int var18 = 0; var18 < 8; ++var18) {
          double var9 = Math.PI * (double) var18 / 4.0D;
          double var11 = var3.posX + 5.5D * Math.sin(var9);
          double var13 = var3.posZ + 5.5D * Math.cos(var9);
          double var15 = (double) var2.getHeightValue((int) (var11 - 0.5D), (int) (var13 - 0.5D));
          EntityLightningBolt var17 = new EntityLightningBolt(var2, var11, var15, var13);

          //					if (!var2.isRemote)
          //					{
          var2.spawnEntityInWorld(var17);
          //					}
        }

        if (!var3.capabilities.isCreativeMode) {
          var3.getFoodStats().addStats(-1, 1.0f);
        }
      } else {
        double var8 = var3.posX;
        double var10 = var3.posZ;
        var8 -= 6.0D * Math.sin((double) (var3.rotationYaw / 180.0F) * Math.PI);
        var10 += 6.0D * Math.cos((double) (var3.rotationYaw / 180.0F) * Math.PI);
        double var12 = (double) var2.getHeightValue((int) (var8 - 0.5D), (int) (var10 - 0.5D));
        EntityLightningBolt var14 = new EntityLightningBolt(var2, var8, var12, var10);

        //				if (!var2.isRemote)
        //				{
        var2.spawnEntityInWorld(var14);
        //				}

        if (!var3.capabilities.isCreativeMode) {
          var3.getFoodStats().addStats(-1, 1.0f);
        }
      }

      var1.damageItem(1, var3);
      var3.swingItem();
      var2.playSoundAtEntity(var3, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F));
    }
  }
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer entityplayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    if (!canBlockStay(world, x, y, z)) {
      world.setBlockToAir(x, y, z);
      world.spawnEntityInWorld(new EntityItem(world, x, y, z, new ItemStack(this, 1)));
    } else if ((TEBloomery) world.getTileEntity(x, y, z) != null) {
      TEBloomery te = (TEBloomery) world.getTileEntity(x, y, z);
      ItemStack is = entityplayer.getCurrentEquippedItem();

      if (is != null
          && (is.getItem() == TFCItems.FireStarter || is.getItem() == TFCItems.FlintSteel)) {
        if (te.canLight()) entityplayer.getCurrentEquippedItem().damageItem(1, entityplayer);
      } else {
        world.playAuxSFXAtEntity(entityplayer, 1003, x, y, z, 0);
        if (isOpen(world.getBlockMetadata(x, y, z)))
          world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 8, 3);
        else world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) + 8, 3);
      }
    }
    return true;
  }
Exemple #12
0
  @Override
  public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
    // Remove the ghost block.
    world.setBlockToAir(x, y + 1, z);

    // Spawn the required number of extra sudes.
    TileEntitySudis tileEntitySudis = (TileEntitySudis) world.getBlockTileEntity(x, y, z);
    if (tileEntitySudis != null && tileEntitySudis.getHasMultipleSudes()) {
      for (int i = 0; i < tileEntitySudis.getNumberOfSudes() - 1; i++) {
        float spawnX = x + world.rand.nextFloat();
        float spawnY = y + world.rand.nextFloat();
        float spawnZ = z + world.rand.nextFloat();

        EntityItem droppedItem =
            new EntityItem(
                world, spawnX, spawnY, spawnZ, new ItemStack(BlockManager.blockSudis, 1));

        float mult = 0.05F;

        droppedItem.motionX = (-0.5F + world.rand.nextFloat()) * mult;
        droppedItem.motionY = (4 + world.rand.nextFloat()) * mult;
        droppedItem.motionZ = (-0.5F + world.rand.nextFloat()) * mult;

        world.spawnEntityInWorld(droppedItem);
      }
    }

    super.breakBlock(world, x, y, z, par5, par6);
  }
  public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    if (playerIn.isSneaking()) {
      if (!playerIn.capabilities.isCreativeMode) {
        --itemStackIn.stackSize;
      }

      worldIn.playSoundAtEntity(
          playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

      if (!worldIn.isRemote) {
        // EntityEnchantedEbonheart

        worldIn.spawnEntityInWorld(new EntityEnchantedEbonheart(worldIn, playerIn));

        // EntityEnchantedEbonheart entityenchantedebonheart = new EntityEnchantedEbonheart(worldIn,
        // playerIn);
        // entityenchantedebonheart.setHeadingFromThrower(playerIn, playerIn.rotationPitch,
        // playerIn.rotationYaw, -20.0F, 0.7F, 1.0F);
        // worldIn.spawnEntityInWorld(entityenchantedebonheart);

        // EntityExpBottle entityexpbottle = new EntityExpBottle(worldIn, playerIn);
        // entityexpbottle.func_184538_a(playerIn, playerIn.rotationPitch, playerIn.rotationYaw,
        // -20.0F, 0.7F, 1.0F);
        // worldIn.spawnEntityInWorld(entityexpbottle);
      }

      playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
      return itemStackIn;
    }
    return itemStackIn;
  }
  /** Checks if the dragon egg can fall down, and if so, makes it fall. */
  private void fallIfPossible(World par1World, int par2, int par3, int par4) {
    if (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 >= 0) {
      byte b0 = 32;

      if (!BlockSand.fallInstantly
          && par1World.checkChunksExist(
              par2 - b0, par3 - b0, par4 - b0, par2 + b0, par3 + b0, par4 + b0)) {
        EntityFallingSand entityfallingsand =
            new EntityFallingSand(
                par1World,
                (double) ((float) par2 + 0.5F),
                (double) ((float) par3 + 0.5F),
                (double) ((float) par4 + 0.5F),
                this.blockID);
        par1World.spawnEntityInWorld(entityfallingsand);
      } else {
        par1World.func_94571_i(par2, par3, par4);

        while (BlockSand.canFallBelow(par1World, par2, par3 - 1, par4) && par3 > 0) {
          --par3;
        }

        if (par3 > 0) {
          par1World.setBlockAndMetadataWithNotify(par2, par3, par4, this.blockID, 0, 2);
        }
      }
    }
  }
 public void spawn(Vector3f pos, String name) throws ScriptErrorException {
   EntityLiving ent = null;
   if (name.equals("creeper")) {
     ent = new EntityCreeper(_world);
   } else if (name.equals("zombie")) {
     ent = new EntityZombie(_world);
   } else if (name.equals("spider")) {
     ent = new EntitySpider(_world);
   } else if (name.equals("skeleton")) {
     ent = new EntitySkeleton(_world);
   } else if (name.equals("pig")) {
     ent = new EntityPig(_world);
   } else if (name.equals("cow")) {
     ent = new EntityCow(_world);
   } else if (name.equals("chicken")) {
     ent = new EntityChicken(_world);
   } else if (name.equals("pigzombie")) {
     ent = new EntityPigZombie(_world);
   } else if (name.equals("enderman")) {
     ent = new EntityEnderman(_world);
   } else if (name.equals("enderdragon")) {
     ent = new EntityDragon(_world);
   } else if (name.equals("bat")) {
     ent = new EntityBat(_world);
   } else if (name.equals("villager")) {
     ent = new EntityVillager(_world);
   } else {
     throw new ScriptErrorException("Ent not found");
   }
   ent.initCreature();
   ent.setPosition(pos.getX(), pos.getY(), pos.getZ());
   _world.spawnEntityInWorld(ent);
 }
Exemple #16
0
 private void dropItems(World world, int x, int y, int z) {
   Random rand = new Random();
   TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
   if (!(tileEntity instanceof IInventory)) {
     return;
   }
   IInventory inventory = (IInventory) tileEntity;
   for (int i = 0; i < inventory.getSizeInventory(); i++) {
     ItemStack item = inventory.getStackInSlot(i);
     if (item != null && item.stackSize > 0) {
       float rx = rand.nextFloat() * 0.8F + 0.1F;
       float ry = rand.nextFloat() * 0.8F + 0.1F;
       float rz = rand.nextFloat() * 0.8F + 0.1F;
       EntityItem entityItem =
           new EntityItem(
               world,
               x + rx,
               y + ry,
               z + rz,
               new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));
       if (item.hasTagCompound()) {
         entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
       }
       float factor = 0.05F;
       entityItem.motionX = rand.nextGaussian() * factor;
       entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
       entityItem.motionZ = rand.nextGaussian() * factor;
       world.spawnEntityInWorld(entityItem);
       item.stackSize = 0;
     }
   }
 }
  private void cleanTeamLoop(World w, int x, int y, int z, int team) {
    ArenaCellEntity ace;

    if (!(w.getBlock(x, y, z) instanceof ArenaCellBlock) || w.getTileEntity(x, y, z) == null)
      return;
    ace = (ArenaCellEntity) w.getTileEntity(x, y, z);

    if (ace.passed) return;

    if (ace.ownership == team) {
      w.spawnEntityInWorld(new EntityItem(w, x, y, z, ace.getStack()));
      ace.stackIn = null;
      ace.ownership = 0;
      ace.XOwnership = 0;
    }

    ace.gameUsable = false;
    ace.passed = true;

    w.markBlockForUpdate(x, y, z);

    cleanTeamLoop(w, x, y, z + 1, team);
    cleanTeamLoop(w, x, y, z - 1, team);

    cleanTeamLoop(w, x + 1, y, z, team);
    cleanTeamLoop(w, x - 1, y, z, team);
  }
  @Override
  public void onPlayerStoppedUsing(
      ItemStack itemstack, World world, EntityPlayer entityplayer, int itemInUseCount) {
    if (entityplayer.inventory.hasItemStack(new ItemStack(AliensVsPredator.items().itemDisc))) {
      int remainingCount = this.getMaxItemUseDuration(itemstack) - itemInUseCount;
      float charge = remainingCount / 20.0F;
      charge = (charge * charge + charge * 2.0F) / 3.0F;

      if (charge >= 0.1F) {
        boolean crit = charge > 1.5F ? true : false;
        charge = charge > 1.5F ? 1.5F : charge;
        charge *= 1.5F;

        if (!world.isRemote) {
          EntitySmartDisc entity = new EntitySmartDisc(world, entityplayer, itemstack, charge);
          entity.setIsCritical(crit);
          world.spawnEntityInWorld(entity);
        }

        world.playSoundAtEntity(
            entityplayer, "random.bow", 0.6F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.0F));
        WorldUtil.Entities.Players.Inventories.consumeItem(entityplayer, this);
      }
    }
  }
Exemple #19
0
 @Override
 public boolean onItemUse(
     ItemStack itemStack,
     EntityPlayer player,
     World world,
     int x,
     int y,
     int z,
     int side,
     float hitX,
     float hitY,
     float hitZ) {
   if (!world.isRemote) {
     if (world.getBlock(x, y, z).equals(Blocks.iron_block)) {
       world.setBlock(x, y, z, Blocks.air);
       for (int i = 0; i < 3; i++) {
         world.spawnEntityInWorld(
             new EntityItem(world, x, y, z, new ItemStack(ItemHandler.ironHard)));
       }
       int itemDamage = itemStack.getItemDamage();
       itemStack.setItemDamage(itemDamage + 1);
       int itemDamageAfter = itemStack.getItemDamage();
       if (itemDamageAfter >= Info.Items.HAMMER_MAX_DAMAGE) {
         itemStack.stackSize = 0;
       }
       return true;
     }
   }
   return false;
 }
  @Override
  public boolean onBlockActivated(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {

    if (!world.isRemote) {
      BlockPos blockpos = world.getStrongholdPos("Stronghold", new BlockPos(player));

      if (blockpos != null) {
        EntityEnderEye entityendereye =
            new EntityEnderEye(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5);
        entityendereye.moveTowards(blockpos);
        world.spawnEntityInWorld(entityendereye);
        world.playAuxSFXAtEntity((EntityPlayer) null, 1002, new BlockPos(player), 0);
      }
    }

    return true;
  }
  @Override
  public void onPlayerStoppedUsing(
      ItemStack itemstack, World world, EntityPlayer entityplayer, int i) {
    if (!entityplayer.inventory.hasItem(this)) {
      return;
    }

    int j = getMaxItemUseDuration(itemstack) - i;
    float f = j / 20F;
    f = (f * f + f * 2.0F) / 3F;
    if (f < 0.1F) {
      return;
    }
    if (f > 1.0F) {
      f = 1.0F;
    }

    if (entityplayer.capabilities.isCreativeMode
        || entityplayer.inventory.consumeInventoryItem(this)) {
      world.playSoundAtEntity(
          entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
      if (!world.isRemote) {
        EntityGrenade entiyGrenade = new EntityGrenade(world, entityplayer);
        world.spawnEntityInWorld(entiyGrenade);
      }
    }
  }
 public void spawnFirecode(Vector3f pos, int flightTime, Object func) {
   final IFunction explodeFunc = JSScriptingManager.getInstance().getFunction(func);
   final EntityPlayer owner = _player;
   ItemStack stk = new ItemStack(Item.firework);
   NBTTagCompound baseComp = new NBTTagCompound();
   baseComp.setCompoundTag("Fireworks", new NBTTagCompound("Fireworks"));
   baseComp.getCompoundTag("Fireworks").setByte("Flight", (byte) flightTime);
   stk.setTagCompound(baseComp);
   EntityFireworkRocket fireWork =
       new EntityFireworkRocket(
           _world, (int) pos.getX(), (int) pos.getY(), (int) pos.getZ(), stk) {
         @Override
         public void onUpdate() {
           super.onUpdate();
           if (this.isDead) {
             if (explodeFunc != null && !worldObj.isRemote) {
               try {
                 JSScriptingManager.getInstance()
                     .runFunction(
                         new ScriptRunnerPlayer(owner),
                         explodeFunc,
                         new Vector3f(this.posX, this.posY, this.posZ));
               } catch (InternalScriptingException e) {
                 owner.sendChatToPlayer("Error in firecode: " + e.getMessage());
               }
             }
           }
         }
       };
   _world.spawnEntityInWorld(fireWork);
 }
  public static void spawnEntityItem(World world, ItemStack stack, double x, double y, double z) {
    float f = world.rand.nextFloat() * 0.8F + 0.1F;
    float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
    EntityItem entityitem;

    for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
        stack.stackSize > 0;
        world.spawnEntityInWorld(entityitem)) {
      int j1 = world.rand.nextInt(21) + 10;

      if (j1 > stack.stackSize) j1 = stack.stackSize;

      stack.stackSize -= j1;
      entityitem =
          new EntityItem(
              world,
              (double) ((float) x + f),
              (double) ((float) y + f1),
              (double) ((float) z + f2),
              new ItemStack(stack.getItem(), j1, stack.getItemDamage()));
      float f3 = 0.05F;
      entityitem.motionX = (double) ((float) world.rand.nextGaussian() * f3);
      entityitem.motionY = (double) ((float) world.rand.nextGaussian() * f3 + 0.2F);
      entityitem.motionZ = (double) ((float) world.rand.nextGaussian() * f3);

      if (stack.hasTagCompound()) {
        entityitem.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
      }
    }
  }
  public void ejectFood(World par1World, int par2, int par3, int par4) {
    if (!par1World.isRemote) {
      TileTeppann tile = (TileTeppann) par1World.getTileEntity(par2, par3, par4);

      if (tile != null) {
        ItemStack itemstack = this.getEjectFoods(tile.getBlockMetadata());

        if (itemstack != null) {
          tile.getItemstack((ItemStack) null);
          par1World.setBlockMetadataWithNotify(par2, par3, par4, 0, 2);
          float f = 0.7F;
          double d0 = (double) (par1World.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
          double d1 = (double) (par1World.rand.nextFloat() * f) + (double) (1.0F - f) * 0.2D + 0.6D;
          double d2 = (double) (par1World.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
          ItemStack itemstack1 = itemstack.copy();
          EntityItem entityitem =
              new EntityItem(
                  par1World,
                  (double) par2 + d0,
                  (double) par3 + d1,
                  (double) par4 + d2,
                  itemstack1);
          entityitem.delayBeforeCanPickup = 10;
          par1World.spawnEntityInWorld(entityitem);
        }
      }
    }
  }
  protected void spawnVillagers(
      World par1World,
      StructureBoundingBox par2StructureBoundingBox,
      int par3,
      int par4,
      int par5,
      int par6) {
    if (this.villagersSpawned < par6) {
      for (int var7 = this.villagersSpawned; var7 < par6; ++var7) {
        int var8 = this.getXWithOffset(par3 + var7, par5);
        final int var9 = this.getYWithOffset(par4);
        int var10 = this.getZWithOffset(par3 + var7, par5);

        var8 += par1World.rand.nextInt(3) - 1;
        var10 += par1World.rand.nextInt(3) - 1;

        if (!par2StructureBoundingBox.isVecInside(var8, var9, var10)) {
          break;
        }

        ++this.villagersSpawned;
        final EntityAlienVillager var11 = new EntityAlienVillager(par1World);
        var11.setLocationAndAngles(var8 + 0.5D, var9, var10 + 0.5D, 0.0F, 0.0F);
        par1World.spawnEntityInWorld(var11);
      }
    }
  }
Exemple #26
0
  /* Straight from InventoryHelper in vanilla code */
  public static void spawnInWorld(World world, BlockPos pos, ItemStack itemStack) {

    float f = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;

    while (itemStack.stackSize > 0) {
      int i = RANDOM.nextInt(21) + 10;

      if (i > itemStack.stackSize) i = itemStack.stackSize;

      itemStack.stackSize -= i;
      EntityItem entityitem =
          new EntityItem(
              world,
              pos.getX() + (double) f,
              pos.getY() + (double) f1,
              pos.getZ() + (double) f2,
              new ItemStack(itemStack.getItem(), i, itemStack.getMetadata()));

      if (itemStack.hasTagCompound())
        entityitem
            .getEntityItem()
            .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());

      float f3 = 0.05F;
      entityitem.motionX = RANDOM.nextGaussian() * (double) f3;
      entityitem.motionY = RANDOM.nextGaussian() * (double) f3 + 0.20000000298023224D;
      entityitem.motionZ = RANDOM.nextGaussian() * (double) f3;
      world.spawnEntityInWorld(entityitem);
    }
  }
  @Override
  public ActionResult<ItemStack> onItemRightClick(
      ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {

    if (!playerIn.capabilities.isCreativeMode) {
      itemStackIn.damageItem(1, playerIn);
      if (itemStackIn.getItemDamage() == 0) {
        itemStackIn = new ItemStack(ModItems.staff);
      }
    }

    worldIn.playSound(
        (EntityPlayer) null,
        playerIn.posX,
        playerIn.posY,
        playerIn.posZ,
        SoundEvents.ENTITY_SNOWBALL_THROW,
        SoundCategory.NEUTRAL,
        0.5F,
        0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

    if (!worldIn.isRemote) {
      EntityLargeSnowBall snowball = new EntityLargeSnowBall(worldIn, playerIn);
      snowball.setHeadingFromThrower(
          playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
      worldIn.spawnEntityInWorld(snowball);
    }

    return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
  }
Exemple #28
0
 @Override
 public boolean onItemUseFirst(
     ItemStack stack,
     EntityPlayer player,
     World world,
     int x,
     int y,
     int z,
     int side,
     float hitX,
     float hitY,
     float hitZ) {
   if (!player.isSneaking()) {
     DebugHelper.debug(player, world, x, y, z);
   } else if (world.getBlock(x, y, z) instanceof BlockBush) {
     if (player.isSneaking()) {
       world.getBlock(x, y, z).updateTick(world, x, y, z, world.rand);
     }
   } else {
     if (!world.isRemote) {
       EntityVillager entityvillager = new EntityVillagerFarmer(world, WorldGen.getVillagerId());
       entityvillager.setLocationAndAngles(
           (double) x + 0.5D, (double) y + 1, (double) z + 0.5D, 0.0F, 0.0F);
       world.spawnEntityInWorld(entityvillager);
     }
   }
   return false;
 }
  private void dropRecord(World worldIn, BlockPos pos, IBlockState state) {
    if (!worldIn.isRemote) {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof BlockJukebox.TileEntityJukebox) {
        BlockJukebox.TileEntityJukebox blockjukebox$tileentityjukebox =
            (BlockJukebox.TileEntityJukebox) tileentity;
        ItemStack itemstack = blockjukebox$tileentityjukebox.getRecord();

        if (itemstack != null) {
          worldIn.playEvent(1010, pos, 0);
          worldIn.playRecord(pos, (SoundEvent) null);
          blockjukebox$tileentityjukebox.setRecord((ItemStack) null);
          float f = 0.7F;
          double d0 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
          double d1 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.06000000238418579D + 0.6D;
          double d2 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
          ItemStack itemstack1 = itemstack.copy();
          EntityItem entityitem =
              new EntityItem(
                  worldIn,
                  (double) pos.getX() + d0,
                  (double) pos.getY() + d1,
                  (double) pos.getZ() + d2,
                  itemstack1);
          entityitem.setDefaultPickupDelay();
          worldIn.spawnEntityInWorld(entityitem);
        }
      }
    }
  }
  @Override
  public boolean onItemUse(
      ItemStack stack,
      EntityPlayer player,
      World world,
      BlockPos pos,
      EnumFacing side,
      float xOff,
      float yOff,
      float zOff) {
    boolean result = false;

    if (!world.isRemote) // / only run on server
    {
      // LogHelper.info("Item used on dumptruck!");
      int x = pos.getX();
      int y = pos.getY();
      int z = pos.getZ();

      EntityWideBedTruck entityWideBedTruck = new EntityWideBedTruck(world);
      entityWideBedTruck.setPosition(x + .5d, y + 1.0d, z + .5d);
      entityWideBedTruck.prevPosX = x + .5d;
      entityWideBedTruck.prevPosY = y + 1.0d;
      entityWideBedTruck.prevPosZ = z + .5d;
      result = world.spawnEntityInWorld(entityWideBedTruck);
      // LogHelper.info("Spawn entity resutl:" + result );
      if (result && !player.capabilities.isCreativeMode) {
        stack.stackSize--;
      }
    }
    return result;
  }