Search in sources :

Example 1 with ISunlightChargeable

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);
                }
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IBaublesItemHandler(baubles.api.cap.IBaublesItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ISunlightChargeable(convenientadditions.api.item.charge.ISunlightChargeable) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IBaublesItemHandler (baubles.api.cap.IBaublesItemHandler)1 ISunlightChargeable (convenientadditions.api.item.charge.ISunlightChargeable)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1