Пример #1
0
  public boolean tryFill(
      ItemStack stackBase, World world, EntityLivingBase entity, InventoryPlayer inven) {
    // Stack to use

    if (world.isRemote) {
      return false;
    }

    ItemStack stack = stackBase;

    if (stackBase.stackSize > 1) {
      stack = stackBase.copy();
      stack.stackSize = 1;
    }

    ItemData data = new ItemData(stack);

    if (!data.isDirty() && stack.getItemDamage() == 0) {
      data.fill(entity);

      if (data.getId() != -1) {
        world.playSoundAtEntity(
            entity,
            "clonecraft:needle.extract",
            1.0F,
            1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + 0.5F);

        if (!(entity instanceof EntityPlayer)
            || !((EntityPlayer) entity).capabilities.isCreativeMode) {
          entity.attackEntityFrom(DamageSource.generic, 2.0f);
          entity.addPotionEffect(new PotionEffect(Potion.confusion.getId(), 400));
          entity.addPotionEffect(new PotionEffect(Potion.weakness.getId(), 400));
        }

        data.save(stack);
        stack.setItemDamage(1);

        if (stack != stackBase) {
          stackBase.stackSize--;

          CloneCraftHelper.addToInventory(inven, 0, 36, stack);

          if (stack.stackSize > 0) {
            CloneCraftHelper.dropAtEntity(entity, stack);
          }
        }
        return true;
      }
    }
    return false;
  }
Пример #2
0
  @Override
  public boolean hitEntity(
      ItemStack par1ItemStack, EntityLivingBase hit, EntityLivingBase playerParam) {
    if (playerParam instanceof EntityPlayer) {
      EntityPlayer player = (EntityPlayer) playerParam;
      if (par1ItemStack.getItemDamage() == 3) {
        if (hit instanceof EntityClone) {
          ((EntityClone) hit).injectStemcells(!player.isSneaking());
          player.worldObj.playSoundAtEntity(
              hit,
              "clonecraft:needle.inject",
              1.0F,
              1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + 0.5F);

          if (!hit.worldObj.isRemote) {
            if (par1ItemStack.stackSize == 1 && !player.capabilities.isCreativeMode) {
              new ItemData(par1ItemStack).empty().save(par1ItemStack);
              par1ItemStack.setItemDamage(0);
            } else if (par1ItemStack.stackSize > 1) {
              par1ItemStack.stackSize--;
              ItemStack newStack = par1ItemStack.copy();
              newStack.stackSize = 1;
              new ItemData(newStack).empty().save(newStack);
              newStack.setItemDamage(0);

              CloneCraftHelper.addToInventory(player.inventory, 0, 36, newStack);

              if (newStack.stackSize > 0) {
                CloneCraftHelper.dropAtEntity(player, newStack.copy());
              }
            }
          }

          return false;
        }
      } else {
        return tryFill(par1ItemStack, hit.worldObj, hit, player.inventory);
      }
    }
    return false;
  }
Пример #3
0
  /** returns a list of items with the same ID, but different meta (eg: dye returns 16 items) */
  @SideOnly(Side.CLIENT)
  public void getSubItems(Item item, CreativeTabs tab, List list) {
    if (tab == CloneCraft.INSTANCE.creativeTabAll || tab == null) {
      list.add(new ItemData().setDirty().save(new ItemStack(item, 1, 0)));

      for (Entry<Integer, Class> entry : CCEntityList.idToClass.entrySet()) {
        int id = entry.getKey();

        if (((EntityLiving.class.isAssignableFrom(entry.getValue())
                || CloneCraftHelper.isValid(CCEntityList.classToString, entry.getValue())))
            && !CloneCraftHelper.isInvalid(CCEntityList.classToString, entry.getValue())) {
          list.add(new ItemData().fill(id).save(new ItemStack(item, 1, 1)));
          list.add(new ItemData().fill(id).save(new ItemStack(item, 1, 2)));
        }
      }
    }
    if (tab == CloneCraft.creativeTab || tab == null) {
      list.add(new ItemStack(item, 1, 0));
      list.add(new ItemData().empty().setDirty().save(new ItemStack(item, 1, 3)));
    }
  }