forked from iguanaman/HungerOverhaul
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of configurable blacklists for right click harvesting, plant dr…
…ops, and food value modification
- Loading branch information
Showing
5 changed files
with
212 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/iguanaman/hungeroverhaul/util/IMCHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package iguanaman.hungeroverhaul.util; | ||
|
||
import iguanaman.hungeroverhaul.HungerOverhaul; | ||
import iguanaman.hungeroverhaul.food.FoodModifier; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.Item; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import cpw.mods.fml.common.event.FMLInterModComms; | ||
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; | ||
import cpw.mods.fml.common.registry.GameData; | ||
|
||
public class IMCHandler | ||
{ | ||
public static String BLACKLIST_RIGHT_CLICK = "BlacklistRightClick"; | ||
public static String BLACKLIST_DROPS = "BlacklistDrops"; | ||
public static String BLACKLIST_FOOD = "BlacklistFood"; | ||
|
||
public static void processMessages(ImmutableList<IMCMessage> messages) | ||
{ | ||
for (final FMLInterModComms.IMCMessage message : messages) | ||
{ | ||
ItemAndBlockList blacklist = null; | ||
|
||
if (message.key.equalsIgnoreCase(BLACKLIST_RIGHT_CLICK)) | ||
{ | ||
blacklist = IguanaEventHook.rightClickHarvestBlacklist; | ||
} | ||
else if (message.key.equalsIgnoreCase(BLACKLIST_DROPS)) | ||
{ | ||
blacklist = IguanaEventHook.harvestDropsBlacklist; | ||
} | ||
else if (message.key.equalsIgnoreCase(BLACKLIST_FOOD)) | ||
{ | ||
blacklist = FoodModifier.blacklist; | ||
} | ||
|
||
if (blacklist != null) | ||
{ | ||
if (message.isItemStackMessage()) | ||
{ | ||
blacklist.add(message.getItemStackValue()); | ||
} | ||
else if (message.isStringMessage()) | ||
{ | ||
String msg = message.getStringValue(); | ||
if (msg.contains(":")) | ||
{ | ||
Item item = GameData.getItemRegistry().getObject(msg); | ||
Block block = GameData.getBlockRegistry().getObject(msg); | ||
|
||
if (item != null) | ||
blacklist.add(item); | ||
if (block != null) | ||
blacklist.add(block); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
Class<?> clazz = Class.forName(message.getStringValue()); | ||
blacklist.add(clazz); | ||
} | ||
catch (ClassNotFoundException e) | ||
{ | ||
HungerOverhaul.Log.error("Class to blacklist not found (sent by mod " + message.getSender() + ")"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/iguanaman/hungeroverhaul/util/ItemAndBlockList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package iguanaman.hungeroverhaul.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.oredict.OreDictionary; | ||
|
||
public class ItemAndBlockList | ||
{ | ||
private static LinkedHashSet<Class<?>> classes = new LinkedHashSet<Class<?>>(); | ||
private static HashSet<Item> items = new HashSet<Item>(); | ||
private static HashSet<Block> blocks = new HashSet<Block>(); | ||
private static List<ItemStack> itemStacks = new ArrayList<ItemStack>(); | ||
|
||
public void add(Class<?> clazz) | ||
{ | ||
classes.add(clazz); | ||
} | ||
|
||
public void add(Item item) | ||
{ | ||
items.add(item); | ||
} | ||
|
||
public void add(Block block) | ||
{ | ||
blocks.add(block); | ||
} | ||
|
||
public void add(ItemStack itemStack) | ||
{ | ||
itemStacks.add(itemStack); | ||
} | ||
|
||
public boolean contains(Class<?> clazz) | ||
{ | ||
if (classes.contains(clazz)) | ||
return true; | ||
|
||
Iterator<Class<?>> itr = classes.iterator(); | ||
while (itr.hasNext()) | ||
{ | ||
Class<?> testClass = itr.next(); | ||
if (testClass.isAssignableFrom(clazz)) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public boolean contains(ItemStack itemStack) | ||
{ | ||
for (ItemStack curItemStack : itemStacks) | ||
{ | ||
if (OreDictionary.itemMatches(curItemStack, itemStack, false)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public boolean contains(Item item) | ||
{ | ||
if (items.contains(item)) | ||
return true; | ||
|
||
if (contains(new ItemStack(item))) | ||
return true; | ||
|
||
if (contains(item.getClass())) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
public boolean contains(Block block) | ||
{ | ||
if (blocks.contains(block)) | ||
return true; | ||
|
||
if (contains(new ItemStack(block))) | ||
return true; | ||
|
||
if (contains(block.getClass())) | ||
return true; | ||
|
||
if (contains(Item.getItemFromBlock(block))) | ||
return true; | ||
|
||
return false; | ||
} | ||
} |