mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-18 19:39:15 +00:00
Add ore dictionary blacklisting (mainly for HarvestCraft)
This commit is contained in:
1 parent
228302e05b
commit
88dcd98c27
3 files changed
+67
-2
No files matched your search
@@ -2,6 +2,7 @@ package com.jaquadro.minecraft.storagedrawers;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.config.CompTierRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.OreDictRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
import cpw.mods.fml.client.event.ConfigChangedEvent;
|
||||
@@ -36,6 +37,7 @@ public class StorageDrawers
|
||||
public static SimpleNetworkWrapper network;
|
||||
public static ConfigManager config;
|
||||
public static CompTierRegistry compRegistry;
|
||||
public static OreDictRegistry oreDictRegistry;
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static StorageDrawers instance;
|
||||
@@ -51,6 +53,7 @@ public class StorageDrawers
|
||||
network.registerMessage(BlockClickMessage.Handler.class, BlockClickMessage.class, 0, Side.SERVER);
|
||||
|
||||
compRegistry = new CompTierRegistry();
|
||||
oreDictRegistry = new OreDictRegistry();
|
||||
|
||||
blocks.init();
|
||||
items.init();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block.tile;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -59,15 +60,19 @@ public class DrawerData
|
||||
int[] oreIDs = OreDictionary.getOreIDs(protoStack);
|
||||
if (oreIDs.length == 0)
|
||||
oreDictMatches = null;
|
||||
else if (oreIDs.length == 1)
|
||||
oreDictMatches = OreDictionary.getOres(OreDictionary.getOreName(oreIDs[0]));
|
||||
else {
|
||||
oreDictMatches = new ArrayList<ItemStack>();
|
||||
for (int id : oreIDs) {
|
||||
if (StorageDrawers.oreDictRegistry.isEntryBlacklisted(OreDictionary.getOreName(id)))
|
||||
continue;
|
||||
|
||||
List<ItemStack> list = OreDictionary.getOres(OreDictionary.getOreName(id));
|
||||
for (ItemStack oreItem : list)
|
||||
oreDictMatches.add(oreItem);
|
||||
}
|
||||
|
||||
if (oreDictMatches.size() == 0)
|
||||
oreDictMatches = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +159,10 @@ public class DrawerData
|
||||
|
||||
boolean oreMatch = false;
|
||||
for (int i = 0; i < oreDictMatches.size(); i++) {
|
||||
ItemStack candidate = oreDictMatches.get(i);
|
||||
if (candidate == null || candidate.getItemDamage() == OreDictionary.WILDCARD_VALUE)
|
||||
continue;
|
||||
|
||||
oreMatch |= stack.isItemEqual(oreDictMatches.get(i));
|
||||
if (oreMatch)
|
||||
break;
|
||||
@@ -182,7 +191,13 @@ public class DrawerData
|
||||
|
||||
BRK_ORE_MATCH:
|
||||
for (int i = 0; i < ids1.length; i++) {
|
||||
if (StorageDrawers.oreDictRegistry.isEntryBlacklisted(OreDictionary.getOreName(ids1[i])))
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < ids2.length; j++) {
|
||||
if (StorageDrawers.oreDictRegistry.isEntryBlacklisted(OreDictionary.getOreName(ids2[i])))
|
||||
continue;
|
||||
|
||||
if (ids1[i] == ids2[j]) {
|
||||
oreMatch = true;
|
||||
break BRK_ORE_MATCH;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class OreDictRegistry
|
||||
{
|
||||
private Set<String> blacklist = new HashSet<String>();
|
||||
private List<String> blacklistPrefix = new ArrayList<String>();
|
||||
|
||||
public OreDictRegistry () {
|
||||
register("logWood");
|
||||
register("plankWood");
|
||||
register("slabWood");
|
||||
register("stairWood");
|
||||
register("treeSapling");
|
||||
register("treeLeaves");
|
||||
register("blockGlass");
|
||||
register("paneGlass");
|
||||
register("record");
|
||||
|
||||
registerPrefix("list");
|
||||
}
|
||||
|
||||
public void register (String entry) {
|
||||
if (!blacklist.contains(entry))
|
||||
blacklist.add(entry);
|
||||
}
|
||||
|
||||
public void registerPrefix (String entry) {
|
||||
blacklistPrefix.add(entry);
|
||||
}
|
||||
|
||||
public boolean isEntryBlacklisted (String entry) {
|
||||
if (blacklist.contains(entry))
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < blacklistPrefix.size(); i++) {
|
||||
if (entry.startsWith(blacklistPrefix.get(i)))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user