use of thaumcraft.api.IRepairable in project BetterStorage by copygirl.
the class ItemThaumcraftBackpack method repairItems.
/* TODO: Readd flux effects.
private void createFlux(EntityPlayer player, ItemStack backpack) {
// Every 5 seconds.
if (player.ticksExisted % 100 != 0) return;
// Count items over normal backpack capacity.
IInventory inventory = ItemBackpack.getBackpackItems(player);
int count = -(getRows() * 9);
for (int i = 0; i < inventory.getSizeInventory(); i++)
if (inventory.getStackInSlot(i) != null) count++;
// When count <= 0, return.
// When count = 1, chance is ~2%.
// When count = 12, chance is 25%.
if (RandomUtils.getInt(48) > count) return;
int auraId = ThaumcraftApi.getClosestAuraWithinRange(player.worldObj, player.posX, player.posY, player.posZ, 640);
if (auraId == -1) return;
ThaumcraftApi.queueNodeChanges(auraId, 0, 0, false, (new ObjectTags()).add(EnumTag.VOID, 3), 0, 0, 0);
}
private void fluxEffects(EntityPlayer player, ItemStack backpack) {
// Every 10 seconds.
if (player.ticksExisted % 200 != 0) return;
BackpackFluxEffect effect = (BackpackFluxEffect)FluxEffect.pick(
BackpackFluxEffect.effects, player.worldObj, player.posX, player.posY, player.posZ);
if (effect == null) return;
effect.apply(player, backpack);
}
*/
public void repairItems(ItemStack backpack, EntityPlayer player) {
IInventory backpackInventory = ItemBackpack.getBackpackItems(player);
int repair = EnchantmentHelper.getEnchantmentLevel(ThaumcraftApi.enchantRepair, backpack);
int time = ((repair > 0) ? (15 - Math.min(repair, 2) * 5) : 30) * 20;
if ((player.ticksExisted % time) > 0)
return;
for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
ItemStack stack = backpackInventory.getStackInSlot(i);
if ((stack != null) && (stack.isItemDamaged()) && (stack.getItem() instanceof IRepairable) && (EnchantmentHelper.getEnchantmentLevel(ThaumcraftApi.enchantRepair, stack) > 0))
repairItem(stack, player);
}
}
Aggregations