Skip to content

Commit

Permalink
Add ore dictionary blacklisting (mainly for HarvestCraft)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaquadro committed Sep 22, 2014
1 parent 228302e commit 88dcd98
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -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;
Expand All @@ -51,6 +53,7 @@ public void preInit (FMLPreInitializationEvent event) {
network.registerMessage(BlockClickMessage.Handler.class, BlockClickMessage.class, 0, Side.SERVER);

compRegistry = new CompTierRegistry();
oreDictRegistry = new OreDictRegistry();

blocks.init();
items.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,15 +60,19 @@ public void setItem (Item item, int meta, NBTTagCompound attrs) {
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;
}
}

Expand Down Expand Up @@ -154,6 +159,10 @@ public boolean areItemsEqual (ItemStack stack) {

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;
Expand Down Expand Up @@ -182,7 +191,13 @@ public static boolean areItemsEqual (ItemStack stack1, ItemStack stack2) {

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 88dcd98

Please sign in to comment.