Skip to content

Commit

Permalink
Rewritten most parts of the HazardousItems module. Most important par…
Browse files Browse the repository at this point in the history
…t: Name lookup is now default mc notation. Also included: An example config file with comments
  • Loading branch information
Namikon committed Sep 29, 2015
1 parent cbdb163 commit 2b1b20a
Show file tree
Hide file tree
Showing 9 changed files with 896 additions and 501 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

apply plugin: 'forge'

version = "1.7.10-0.9.26"
version = "1.7.10-0.9.27"
group= "com.dreammaster" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "GTNewHorizonsCoreMod"

Expand Down
26 changes: 26 additions & 0 deletions exampleconfigs/HazardousItems.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<HazardousItemList>
<!-- for normal items (no fluid containers) use the default minecraft notation
For *Item* elements, the "OnContactCheck" will check the block that is directly UNDER the player (The block
he currently stands on -->
<Item ItemName="minecraft:lava_bucket" ExactNameMatch="true" OnContactCheck="false" InventoryCheck="true">
<DamageEffect Source="inFire" Amount="0.5"/>
<PotionEffect PotionID="19" TickDuration="100" Level="1"/>
</Item>

<!-- For fluid containers, use the /iih command to get the fluid's name.
For *Fluid* elements, the "OnContactCheck" will check the block that is directly at the players coordinates.
This is used to check if the player is currently swimming in this fluid -->
<Fluid FluidName="lava" ExactNameMatch="true" OnContactCheck="false" InventoryCheck="true">
<DamageEffect Source="inFire" Amount="0.5"/>
<PotionEffect PotionID="19" TickDuration="100" Level="1"/>
</Fluid>

<!-- Regeneration effect on contact with water. Since the fluid is now a block, it requires a different Name
In most cases it is sufficient to just add the modID. Like water becomes minecraft:water, lava becomes minecraft:lava, and so on
Be careful with "ExactNameMatch". It will safe you some lines here if you set it to true, but then *any* item containing *water*
will match, obviously. So itemWaterTank, blockWaterSource, .. all those will match if ExactNameMatch is true -->
<Fluid FluidName="minecraft:water" ExactNameMatch="true" OnContactCheck="true" InventoryCheck="false">
<PotionEffect PotionID="10" TickDuration="100" Level="1"/>
</Fluid>
</HazardousItemList>
81 changes: 81 additions & 0 deletions src/main/java/com/dreammaster/auxiliary/ItemHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.dreammaster.auxiliary;

import com.dreammaster.modhazardousitems.HazardousItems.HazardousItem;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;

public class ItemHelper
{
/** Try to find the fluid that is in the fluidcontainer. Returns null if none could be found
*
* @param pItemStack
* @return
*/
public static Fluid getFluidFromContainer(ItemStack pItemStack)
{
Fluid tReturnVal = null;

if ((Object)pItemStack.getItem() instanceof IFluidContainerItem)
{
IFluidContainerItem tFluidContainer = IFluidContainerItem.class.cast(pItemStack.getItem());
FluidStack tContents = tFluidContainer.getFluid(pItemStack);
if (tContents != null)
{
tReturnVal = tContents.getFluid();
}
}

return tReturnVal;
}

/** Convert Minecraft <modID>:<itemID>:<metaID> notation into an actual Item-class
*
* @param pItemIdentifier
* @return
*/
public static Item ConvertStringToItem(String pItemIdentifier)
{
String[] args = pItemIdentifier.split(":");
String tMod;
String tName;
int tMeta;

if (args.length >= 2)
{
tMod = args[0];
tName = args[1];
if (args.length == 3)
tMeta = Integer.parseInt(args[2]);
else
tMeta = 0;

Item tItem = GameRegistry.findItem(tMod, tName);
if (tItem != null)
return tItem;
else
return null;
}
return null;
}

/** Convert item instance to string notation (UNTESTED!)
*
* @param pItem
* @return
*/
public static String ConvertItemToString(Item pItem)
{
String tRet = "";
UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(pItem);
if (uid != null)
tRet = uid.toString();

return tRet;
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/dreammaster/command/HazardousItemsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ else if (pArgs[0].equalsIgnoreCase("reload"))
// Commands for ingame only >>
else
{
String tCmd = pArgs[0];
/* String tCmd = pArgs[0];
if (tCmd.equalsIgnoreCase("addpotion") || tCmd.equalsIgnoreCase("adddamage") || tCmd.equalsIgnoreCase("removeitem"))
{
if (!InGame(pCmdSender))
Expand Down Expand Up @@ -215,7 +215,7 @@ else if (pArgs[0].equalsIgnoreCase("reload"))
}
}
}
else
else*/
SendHelpToPlayer(pCmdSender);
}
}
Expand Down Expand Up @@ -270,15 +270,15 @@ private void SendHelpToPlayer(ICommandSender pCmdSender)
}
else
{
PlayerChatHelper.SendInfo(pCmdSender, " /hazarditems addpotion <potionID> <tickDuration> <level>");
/* PlayerChatHelper.SendInfo(pCmdSender, " /hazarditems addpotion <potionID> <tickDuration> <level>");
PlayerChatHelper.SendInfo(pCmdSender, " /hazarditems adddamage <damageSource> <damageAmount>");
PlayerChatHelper.SendInfo(pCmdSender, " /hazarditems removeitem [all]");
PlayerChatHelper.SendInfo(pCmdSender, "* tickDuration is [seconds*20]");
PlayerChatHelper.SendInfo(pCmdSender, "* damageAmount is a float, where 1.0 equals 1 heart");
PlayerChatHelper.SendInfo(pCmdSender, "* damageAmount is a float, where 1.0 equals 1 heart");*/
PlayerChatHelper.SendInfo(pCmdSender, "/hazarditems reload|save|listdamagesources|listpotions");
}
}

/*
private void ProcessRemoveItemCommand(EntityPlayer pPlayer, ItemStack pInHand, String[] pArgs)
{
boolean bFlag = false;
Expand Down Expand Up @@ -341,7 +341,7 @@ private void ProcessAddPotionEffectCommand(EntityPlayer pPlayer, ItemStack pInHa
PlayerChatHelper.SendError(pPlayer, "Error in your command. Check your syntax");
}
}

*/
/*
* Make sure only an op/admin can execute this command
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.util.DamageSource;
import net.minecraftforge.event.entity.living.LivingDropsEvent;

import com.dreammaster.auxiliary.ItemHelper;
import com.dreammaster.lib.Refstrings;
import com.dreammaster.main.MainRegistry;
import com.dreammaster.modcustomdrops.CustomDrops.CustomDrop;
Expand Down Expand Up @@ -117,7 +118,7 @@ private boolean VerifyConfig(CustomDrops pDropListToCheck)
{
for (Drop Y : X.getDrops())
{
if (ConvertStringToItem(Y.getItemName()) == null)
if (ItemHelper.ConvertStringToItem(Y.getItemName()) == null)
{
_mLogger.error(String.format("In ItemDropID: [%s], can't find item [%s]", Y.getIdentifier(), Y.getItemName()));
tSuccess = false;
Expand All @@ -141,31 +142,7 @@ private boolean VerifyConfig(CustomDrops pDropListToCheck)
}
return tSuccess;
}

private Item ConvertStringToItem(String pItemIdentifier)
{
String[] args = pItemIdentifier.split(":");
String tMod;
String tName;
int tMeta;

if (args.length >= 2)
{
tMod = args[0];
tName = args[1];
if (args.length == 3)
tMeta = Integer.parseInt(args[2]);
else
tMeta = 0;

Item tItem = GameRegistry.findItem(tMod, tName);
if (tItem != null)
return tItem;
else
return null;
}
return null;
}


public boolean ReloadCustomDrops()
{
Expand Down Expand Up @@ -304,7 +281,7 @@ private void HandleCustomDrops(CustomDrop tCustomDrop, EntityLivingBase tEntity,
if (dr.getIsRandomAmount())
tFinalAmount = 1 + MainRegistry.Rnd.nextInt(dr.getAmount() -1 );

Item tITD = ConvertStringToItem(dr.getItemName());
Item tITD = ItemHelper.ConvertStringToItem(dr.getItemName());
ItemStack tDropStack = new ItemStack(tITD);

try
Expand Down
Loading

0 comments on commit 2b1b20a

Please sign in to comment.