Search in sources :

Example 1 with HazardousFluid

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

the class HazardousItemsHandler method InitSampleConfig.

public void InitSampleConfig() {
    // Create new DamageEffect
    ItmDamageEffect tFireEffect = _mHazFactory.createDamageEffect(0.5F, "inFire");
    // Create new Potioneffect
    ItmPotionEffect tPoisonPotion = _mHazFactory.createPotionEffect(100, Potion.poison.id, 1);
    // Define a testitem to hold these effects
    HazardousItem tHazItem = _mHazFactory.createHazardousItemsHazardousItem("tfarcenim:stone", true, true, true);
    HazardousFluid tHazFluid = _mHazFactory.createHazardousFluid("tfarcenim:water", true, true, true);
    // Add both effects to our defined testItem
    tHazItem.getDamageEffects().add(tFireEffect);
    tHazItem.getPotionEffects().add(tPoisonPotion);
    tHazFluid.getDamageEffects().add(tFireEffect);
    tHazFluid.getPotionEffects().add(tPoisonPotion);
    _mHazardItemsCollection = new HazardousItems();
    _mHazardItemsCollection.getHazardousItems().add(tHazItem);
    _mHazardItemsCollection.getHazardousFluids().add(tHazFluid);
}
Also used : HazardousFluid(com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid) HazardousItem(com.dreammaster.modhazardousitems.HazardousItems.HazardousItem) ItmDamageEffect(com.dreammaster.modhazardousitems.HazardousItems.ItmDamageEffect) ItmPotionEffect(com.dreammaster.modhazardousitems.HazardousItems.ItmPotionEffect)

Example 2 with HazardousFluid

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

the class HazardousItemsHandler method VerifyConfiguredDamageEffects.

/**
   * Verify defined DamageEffects in configfile
   * 
   * @param pCollection
   * @return true if everything is ok
   */
public boolean VerifyConfiguredDamageEffects(HazardousItems pItemCollection) {
    boolean tResult = true;
    for (HazardousItem hi : pItemCollection.getHazardousItems()) {
        for (ItmDamageEffect ide : hi.getDamageEffects()) {
            if (!DamageTypeHelper.IsValidDamageSource(ide.getDamageSource())) {
                _mLogger.warn(String.format("HazardousItem [%s] has invalid DamageSource entry: [%s]", hi.getItemName(), ide.getDamageSource()));
                tResult = false;
            }
        }
    }
    for (HazardousFluid hf : pItemCollection.getHazardousFluids()) {
        for (ItmDamageEffect ide : hf.getDamageEffects()) {
            if (!DamageTypeHelper.IsValidDamageSource(ide.getDamageSource())) {
                _mLogger.warn(String.format("HazardousFluid [%s] has invalid DamageSource entry: [%s]", hf.getFluidName(), ide.getDamageSource()));
                tResult = false;
            }
        }
    }
    return tResult;
}
Also used : HazardousFluid(com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid) HazardousItem(com.dreammaster.modhazardousitems.HazardousItems.HazardousItem) ItmDamageEffect(com.dreammaster.modhazardousitems.HazardousItems.ItmDamageEffect)

Example 3 with HazardousFluid

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

the class HazardousItemsHandler method VerifyConfiguredPotionEffects.

/**
   * Verify defined potioneffects in configfile
   * 
   * @param pCollection
   * @return true if everything is ok
   */
public boolean VerifyConfiguredPotionEffects(HazardousItems pItemCollection) {
    boolean tResult = true;
    for (HazardousItem hi : pItemCollection.getHazardousItems()) {
        for (ItmPotionEffect ipe : hi.getPotionEffects()) {
            if (!PotionHelper.IsValidPotionID(ipe.getId())) {
                _mLogger.warn(String.format("HazardousItem [%s] has invalid PotionID: [%s] (There is no such potion)", hi.getItemName(), ipe.getId()));
                tResult = false;
            }
        }
    }
    for (HazardousFluid hf : pItemCollection.getHazardousFluids()) {
        for (ItmPotionEffect ipe : hf.getPotionEffects()) {
            if (!PotionHelper.IsValidPotionID(ipe.getId())) {
                _mLogger.warn(String.format("HazardousFluid [%s] has invalid PotionID: [%s] (There is no such potion)", hf.getFluidName(), ipe.getId()));
                tResult = false;
            }
        }
    }
    return tResult;
}
Also used : HazardousFluid(com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid) HazardousItem(com.dreammaster.modhazardousitems.HazardousItems.HazardousItem) ItmPotionEffect(com.dreammaster.modhazardousitems.HazardousItems.ItmPotionEffect)

Example 4 with HazardousFluid

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

the class HazardousItemsHandler method CheckPlayerTouchesBlock.

/**
   * Check if player actually swims in a fluid
   * 
   * @param pPlayer
   */
private void CheckPlayerTouchesBlock(EntityPlayer pPlayer) {
    if (_mRnd.nextInt(_mExecuteChance) != 0)
        return;
    try {
        int blockX = MathHelper.floor_double(pPlayer.posX);
        int blockY = MathHelper.floor_double(pPlayer.boundingBox.minY);
        int blockZ = MathHelper.floor_double(pPlayer.posZ);
        Block pBlockContact = pPlayer.worldObj.getBlock(blockX, blockY, blockZ);
        Block pBlockUnderFeet = pPlayer.worldObj.getBlock(blockX, blockY - 1, blockZ);
        UniqueIdentifier tUidContact = GameRegistry.findUniqueIdentifierFor(pBlockContact);
        UniqueIdentifier tUidFeet = GameRegistry.findUniqueIdentifierFor(pBlockUnderFeet);
        // Skip air block and null results
        if (tUidContact != null && tUidContact.toString() != "minecraft:air") {
            HazardousFluid hf = _mHazardItemsCollection.FindHazardousFluidExact(tUidContact.toString());
            if (hf != null && hf.getCheckContact())
                DoHIEffects(hf, pPlayer);
        }
        if (tUidFeet != null && tUidFeet.toString() != "minecraft:air") {
            HazardousItem hi = _mHazardItemsCollection.FindHazardousItemExact(tUidFeet.toString());
            if (hi != null && hi.getCheckContact())
                DoHIEffects(hi, pPlayer);
        }
    } catch (Exception e) {
        _mLogger.error("HazardousItemsHandler.CheckPlayerTouchesBlock.error", "Something bad happend while processing the onPlayerTick event");
        e.printStackTrace();
    }
}
Also used : UniqueIdentifier(cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier) HazardousFluid(com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid) HazardousItem(com.dreammaster.modhazardousitems.HazardousItems.HazardousItem) Block(net.minecraft.block.Block)

Example 5 with HazardousFluid

use of com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid 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

HazardousFluid (com.dreammaster.modhazardousitems.HazardousItems.HazardousFluid)6 HazardousItem (com.dreammaster.modhazardousitems.HazardousItems.HazardousItem)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