use of convenientadditions.api.item.charge.ISunlightChargeable in project ConvenientAdditions by Necr0.
the class ChargeTickHandler method onPlayerSunlightChargeTick.
@SubscribeEvent
public void onPlayerSunlightChargeTick(TickEvent.PlayerTickEvent e) {
time++;
if (time < 20 || e.side != Side.SERVER)
return;
time = 0;
EntityPlayer player = e.player;
InventoryPlayer playerInv = player.inventory;
if (player.worldObj.isDaytime() && !player.worldObj.isRaining() && Helper.canEntitySeeSky(player)) {
// BAUBLES SUNLIGHT
IBaublesItemHandler baublesInv = player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null);
for (int i = 0; i < baublesInv.getSlots(); i++) {
ItemStack stack = baublesInv.getStackInSlot(i);
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, BAUBLES_SLOTS[i])) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, BAUBLES_SLOTS[i]) * 20);
}
}
}
// MAIN
for (int i = 0; i < playerInv.mainInventory.length; i++) {
ItemStack stack = playerInv.mainInventory[i];
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, i)) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, i) * 20);
}
}
}
// ARMOR
for (int i = 0; i < playerInv.armorInventory.length; i++) {
ItemStack stack = playerInv.armorInventory[i];
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, ARMOR_SLOTS[i])) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, ARMOR_SLOTS[i]) * 20);
}
}
}
// OFFHAND
for (ItemStack stack : playerInv.offHandInventory) {
if (stack != null && stack.getItem() instanceof ISunlightChargeable) {
ISunlightChargeable sitem = (ISunlightChargeable) (stack.getItem());
if (sitem.isSunlightChargeable(stack, OFFHAND_SLOTS[0])) {
sitem.chargeItem(stack, sitem.getSunlightChargeRate(stack, OFFHAND_SLOTS[0]) * 20);
}
}
}
}
}
Aggregations