Search in sources :

Example 6 with HazardousItem

use of com.dreammaster.modhazardousitems.HazardousItems.HazardousItem in project NewHorizonsCoreMod by GTNewHorizons.

the class HazardousItemsHandler method CheckInventoryForItems.

private void CheckInventoryForItems(EntityPlayer pPlayer) {
    if (_mRnd.nextInt(_mExecuteChance) != 0)
        return;
    try {
        ItemStack[] tPlayerInventory = pPlayer.inventory.mainInventory;
        String tCurrIS = "";
        for (ItemStack is : tPlayerInventory) {
            try // Safe-loop to enforce dangerous items even if something bad
            // happens here
            {
                if (is == null)
                    continue;
                tCurrIS = ItemDescriptor.fromStack(is).toString();
                // Check if item is a fluid container
                if ((Object) is.getItem() instanceof IFluidContainerItem) {
                    HazardousFluid hf = _mHazardItemsCollection.FindHazardousFluid(is);
                    if (hf != null && hf.getCheckInventory())
                        DoHIEffects(hf, pPlayer);
                } else // Tinkers' construct smeltery tank
                if (is.getItem().getClass().getName().equals("tconstruct.smeltery.itemblocks.LavaTankItemBlock")) {
                    // _mLogger.info("Found lavatank");
                    NBTTagCompound tNBT = is.getTagCompound();
                    if (tNBT != null && tNBT.hasKey("Fluid")) {
                        // _mLogger.info("...Has NBT 'Fluid'...");
                        NBTTagCompound tFluidCompound = tNBT.getCompoundTag("Fluid");
                        if (tFluidCompound != null && tFluidCompound.hasKey("FluidName")) {
                            // _mLogger.info("...Has NBT 'FluidName'...");
                            String tFluidName = tFluidCompound.getString("FluidName");
                            if (tFluidName != null && tFluidName.length() > 0) {
                                // _mLogger.info("...Finding Hazardous Fluids...");
                                HazardousFluid hf = _mHazardItemsCollection.FindHazardousFluidExact(tFluidName);
                                if (hf != null && hf.getCheckInventory()) {
                                    // _mLogger.info("...Found Hazardous Fluids");
                                    DoHIEffects(hf, pPlayer);
                                }
                            // else
                            // _mLogger.info("...Not found Hazardous Fluids");
                            }
                        }
                    // else
                    // _mLogger.info("...Has no NBT 'FluidName'");
                    }
                // else
                // _mLogger.info("...Has no NBT 'Fluid'");
                } else {
                    HazardousItem hi = _mHazardItemsCollection.FindHazardousItem(is);
                    if (hi != null && hi.getCheckInventory())
                        DoHIEffects(hi, pPlayer);
                }
            } catch (Exception e) {
                _mLogger.debug(String.format("Something weird happend with item %s", tCurrIS));
                // Silently catching exception and continue
                continue;
            }
        }
    } catch (Exception e) {
        _mLogger.error("HazardousItemsHandler.CheckInventoryForItems.error", "Something bad happend while processing the onPlayerTick event");
        e.printStackTrace();
    }
}
Also used : HazardousFluid(com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid) IFluidContainerItem(net.minecraftforge.fluids.IFluidContainerItem) HazardousItem(com.dreammaster.modhazardousitems.HazardousItems.HazardousItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Aggregations

HazardousItem (com.dreammaster.modhazardousitems.HazardousItems.HazardousItem)6 HazardousFluid (com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid)5 ItmDamageEffect (com.dreammaster.modhazardousitems.HazardousItems.ItmDamageEffect)2 ItmPotionEffect (com.dreammaster.modhazardousitems.HazardousItems.ItmPotionEffect)2 UniqueIdentifier (cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier)1 Block (net.minecraft.block.Block)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 IFluidContainerItem (net.minecraftforge.fluids.IFluidContainerItem)1