private int getLightFromItemStack(ItemStack stack) { if (stack != null) { int r = itemsMap.retrieveValue(stack.itemID, stack.getItemDamage()); return r < 0 ? 0 : r; } return 0; }
@SubscribeEvent public void onTick(TickEvent.ClientTickEvent tick) { if (lastWorld != FMLClientHandler.instance().getClient().theWorld || thePlayer != FMLClientHandler.instance().getClient().thePlayer) { thePlayer = FMLClientHandler.instance().getClient().thePlayer; if (thePlayer != null) { lastWorld = thePlayer.worldObj; } else { lastWorld = null; } } if (thePlayer != null && thePlayer.isEntityAlive() && !DynamicLights.globalLightsOff()) { List<IMCMessage> messages = FMLInterModComms.fetchRuntimeMessages(this); if (messages.size() > 0) { // just get the last one IMCMessage imcMessage = messages.get(messages.size() - 1); if (imcMessage.key.equalsIgnoreCase("forceplayerlighton")) { if (!fmlOverrideEnable) { fmlOverrideEnable = true; if (!enabled) { lightLevel = 15; enableLight(); } } } else if (imcMessage.key.equalsIgnoreCase("forceplayerlightoff")) { if (fmlOverrideEnable) { fmlOverrideEnable = false; if (enabled) { disableLight(); } } } } if (!fmlOverrideEnable) { int prevLight = lightLevel; ItemStack item = thePlayer.getCurrentEquippedItem(); lightLevel = itemsMap.getLightFromItemStack(item); for (ItemStack armor : thePlayer.inventory.armorInventory) { lightLevel = DynamicLights.maxLight(lightLevel, itemsMap.getLightFromItemStack(armor)); } if (prevLight != 0 && lightLevel != prevLight) { lightLevel = 0; } else { if (thePlayer.isBurning()) { lightLevel = 15; } else { if (checkPlayerWater(thePlayer) && item != null && notWaterProofItems.retrieveValue( GameData.getItemRegistry().getNameForObject(item.getItem()), item.getItemDamage()) == 1) { lightLevel = 0; for (ItemStack armor : thePlayer.inventory.armorInventory) { if (armor != null && notWaterProofItems.retrieveValue( GameData.getItemRegistry().getNameForObject(armor.getItem()), item.getItemDamage()) == 0) { lightLevel = DynamicLights.maxLight(lightLevel, itemsMap.getLightFromItemStack(armor)); } } } } } if (!enabled && lightLevel > 0) { enableLight(); } else if (enabled && lightLevel < 1) { disableLight(); } } } }