Exemplo n.º 1
0
  private List<ItemStack> dropInventory(EntityPlayer player) {
    List<ItemStack> itemsToDrop = new ArrayList<ItemStack>();

    if (player.inventory.mainInventory.length > 8) {
      /* Array to determine the order the inventory array is processed. */
      int[] placeArray = new int[player.inventory.mainInventory.length - 9];
      for (int i = 0; i < placeArray.length; i++) {
        placeArray[i] = i + 9;
      }
      shuffleArray(placeArray, player.worldObj.rand);

      int countDrops = 0;
      for (int i = 0; i < placeArray.length; ++i) {
        int slot = placeArray[i];
        ItemStack itemStack = player.inventory.mainInventory[slot];
        if (itemStack == null || itemBlacklist.isItemBlacklisted(itemStack)) {
          continue;
        }
        boolean shouldDrop = false;
        if ((inventoryMaxDrop == 0 || countDrops < inventoryMaxDrop)
            && inventoryDropChance - player.worldObj.rand.nextInt(100) >= 1) {
          shouldDrop = true;
        }
        int percentDamage =
            shouldDrop ? inventoryDeathDamage + inventoryDropDamage : inventoryDeathDamage;
        percentDamage = percentDamage > 100 ? 100 : percentDamage;
        itemStack.attemptDamageItem(
            itemStack.getMaxDamage() * percentDamage / 100, player.worldObj.rand);

        boolean itemDestroyed =
            itemStack.isItemStackDamageable()
                && itemStack.getItemDamage() > itemStack.getMaxDamage();
        if (itemDestroyed) {
          player.inventory.mainInventory[slot] = null;
        }

        if (shouldDrop) {
          if (!itemDestroyed) {
            itemsToDrop.add(itemStack);
          }
          player.inventory.mainInventory[slot] = null;
          countDrops++;
        }
      }
    }
    return itemsToDrop;
  }
Exemplo n.º 2
0
  public DeathGamerules loadConfiguration(File modConfigDirectory) {
    itemBlacklist = new ItemBlacklist();
    Configuration config =
        new Configuration(
            new File(
                modConfigDirectory, DefaultProps.configDirectory + DefaultProps.defaultConfigFile));
    config.load();
    itemBlacklist.loadFromConfig(config);
    tombstoneOnDeath =
        config
            .get("General Controls", "Drop Tombstone On Death", tombstoneOnDeath)
            .getBoolean(tombstoneOnDeath);
    tombstoneAbsorbDrops =
        config
            .get("General Controls", "Tombstone Absorb Drops", tombstoneAbsorbDrops)
            .getBoolean(tombstoneAbsorbDrops);
    doDropEvent =
        config.get("General Controls", "doDropEvent", doDropEvent).getBoolean(doDropEvent);

    String category = "General Controls.gamerule_settings";
    maxDropXP =
        config
            .get(
                category + ".Experience",
                "maxDropXP",
                100,
                "Maximum amount XP dropped on Death. The rest is lost if not kept via percKeptXp. 100 is vanilla default")
            .getInt(100);
    keepInventoryDefault =
        config
            .get(
                category,
                "keepInventoryDefault",
                false,
                "The Default settings for the keepInventory gamerule")
            .getBoolean(false);
    Property keptXpProperty =
        config.get(
            category + ".Experience",
            "percKeptXp",
            0,
            "Percentage of XP (minus dropped amount) kept with the player on respawn.");
    percKeptXp = keptXpProperty.getInt();
    if (percKeptXp < 0 || percKeptXp > 100) {
      percKeptXp = percKeptXp < 0 ? 0 : percKeptXp > 100 ? 100 : percKeptXp;
      keptXpProperty.set(percKeptXp);
    }
    dropArmorDefault =
        config
            .get(
                category + ".Armor",
                "isEnabledDefault",
                false,
                "The Default settings for the dropArmor gamerule")
            .getBoolean(false);
    dropInventoryDefault =
        config
            .get(
                category + ".Inventory",
                "isEnabledDefault",
                false,
                "The Default settings for the dropInventory gamerule")
            .getBoolean(false);
    dropHotbarDefault =
        config
            .get(
                category + ".Hotbar",
                "isEnabledDefault",
                false,
                "The Default settings for the dropHotbar gamerule")
            .getBoolean(false);
    dropXPDefault =
        config
            .get(
                category + ".Experience",
                "isEnabledDefault",
                false,
                "The Default settings for the dropXP gamerule")
            .getBoolean(false);

    armorDeathDamage =
        handlePropMinMax(
            config.get(
                category + ".Armor",
                "armorDeathDamage",
                0,
                "Percentage of Max durability dealth on Death to armor slot items"),
            0,
            0,
            100);
    inventoryDeathDamage =
        handlePropMinMax(
            config.get(
                category + ".Inventory",
                "inventoryDeathDamage",
                0,
                "Percentage of Max durability dealth on Death to inventory slot items"),
            0,
            0,
            100);
    hotbarDeathDamage =
        handlePropMinMax(
            config.get(
                category + ".Hotbar",
                "hotbarDeathDamage",
                0,
                "Percentage of Max durability dealth on Death to hotbar slot items"),
            0,
            0,
            100);

    armorDropDamage =
        handlePropMinMax(
            config.get(
                category + ".Armor",
                "armorDropDamage",
                0,
                "Percentage of Max durability dealth on Drop to armor slot items"),
            0,
            0,
            100);
    inventoryDropDamage =
        handlePropMinMax(
            config.get(
                category + ".Inventory",
                "inventoryDropDamage",
                0,
                "Percentage of Max durability dealth on Drop to inventory slot items"),
            0,
            0,
            100);
    hotbarDropDamage =
        handlePropMinMax(
            config.get(
                category + ".Hotbar",
                "hotbarDropDamage",
                0,
                "Percentage of Max durability dealth on Drop to hotbar slot items"),
            0,
            0,
            100);

    armorDropChance =
        handlePropMinMax(
            config.get(
                category + ".Armor",
                "armorDropChance",
                100,
                "Chance that each armor slot item will drop on death"),
            100,
            0,
            100);
    inventoryDropChance =
        handlePropMinMax(
            config.get(
                category + ".Inventory",
                "inventoryDropChance",
                100,
                "Chance that each inventory slot item will drop on death"),
            100,
            0,
            100);
    hotbarDropChance =
        handlePropMinMax(
            config.get(
                category + ".Hotbar",
                "hotbarDropChance",
                100,
                "Chance that each hotbar slot item will drop on death"),
            100,
            0,
            100);

    armorMaxDrop =
        handlePropMinMax(
            config.get(
                category + ".Armor",
                "armorMaxDrop",
                0,
                "Max number of armor slot items that can drop on death."),
            0,
            0,
            null);
    inventoryMaxDrop =
        handlePropMinMax(
            config.get(
                category + ".Inventory",
                "inventoryMaxDrop",
                0,
                "Max number of inventory slot items that can drop on death"),
            0,
            0,
            null);
    hotbarMaxDrop =
        handlePropMinMax(
            config.get(
                category + ".Hotbar",
                "hotbarMaxDrop",
                0,
                "Max number of hotbar slot items that can drop on death"),
            0,
            0,
            null);
    config.save();
    return this;
  }