Some work on a blacklist to prevent items from receiving EMC values
This commit is contained in:
parent
521982bed9
commit
163083bc89
7 changed files with 197 additions and 157 deletions
|
@ -7,6 +7,7 @@ import net.minecraft.entity.EntityLiving;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.pahimar.ee3.item.ModItems;
|
||||
import com.pahimar.ee3.lib.Colours;
|
||||
|
@ -51,6 +52,11 @@ public class ItemUtil {
|
|||
// Check the item IDs
|
||||
if (first.itemID == second.itemID) {
|
||||
// Check the meta data
|
||||
|
||||
if ((first.getItemDamage() == OreDictionary.WILDCARD_VALUE) || (second.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (first.getItemDamage() == second.getItemDamage()) {
|
||||
// Check the stack size
|
||||
if (first.stackSize == second.stackSize) {
|
||||
|
|
|
@ -6,20 +6,22 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.pahimar.ee3.core.util.ItemUtil;
|
||||
import com.pahimar.ee3.core.util.LogHelper;
|
||||
import com.pahimar.ee3.core.util.RecipeHelper;
|
||||
import com.pahimar.ee3.item.CustomStackWrapper;
|
||||
|
||||
public class DynEMC {
|
||||
|
||||
private static final DynEMC dynEMC = new DynEMC();
|
||||
private static final ArrayList<Integer> idBlackList = new ArrayList<Integer>();
|
||||
private static final ArrayList<ItemStack> itemStackBlackList = new ArrayList<ItemStack>();
|
||||
private static final HashMap<List<Integer>, ItemStack> discoveredItems = new HashMap<List<Integer>, ItemStack>();
|
||||
|
||||
private static final ArrayList<CustomStackWrapper> discoveredItems = new ArrayList<CustomStackWrapper>();
|
||||
|
||||
private DynEMC() {
|
||||
|
||||
|
@ -30,24 +32,12 @@ public class DynEMC {
|
|||
return dynEMC;
|
||||
}
|
||||
|
||||
public void populateBlackList() {
|
||||
|
||||
// List of ids to blacklist, more to clean up here
|
||||
int[] blackints = { 7, 8, 9, 10, 11, 14, 15, 16, 21, 26, 34, 36, 43, 51, 52, 55, 56, 59, 60, 62, 63, 64, 68, 71, 73, 74, 75, 83, 90, 92, 93, 94, 95, 97, 104, 105, 115, 117, 118, 119, 120, 124, 125, 127, 129, 132, 137, 140, 141, 142, 144, 149, 150, 153 };
|
||||
|
||||
for (int i : blackints) {
|
||||
idBlackList.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
populateBlackList();
|
||||
|
||||
ArrayList<ItemStack> subItems = new ArrayList<ItemStack>();
|
||||
|
||||
for (int i = 0; i < Item.itemsList.length; i++) {
|
||||
if ((Item.itemsList[i] != null) && (!idBlackList.contains(i))) {
|
||||
if (Item.itemsList[i] != null) {
|
||||
if (Item.itemsList[i].getHasSubtypes()) {
|
||||
|
||||
subItems.clear();
|
||||
|
@ -55,9 +45,10 @@ public class DynEMC {
|
|||
|
||||
for (ItemStack itemStack : subItems) {
|
||||
if (itemStack != null) {
|
||||
List<Integer> idMeta = Arrays.asList(itemStack.itemID, itemStack.getItemDamage());
|
||||
if (!discoveredItems.containsKey(idMeta)) {
|
||||
discoveredItems.put(idMeta, itemStack);
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
if (!discoveredItems.contains(customStackWrapper)) {
|
||||
discoveredItems.add(customStackWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,32 +56,31 @@ public class DynEMC {
|
|||
else {
|
||||
|
||||
ItemStack itemStack = new ItemStack(Item.itemsList[i]);
|
||||
List<Integer> idMeta = Arrays.asList(itemStack.itemID, itemStack.getItemDamage());
|
||||
|
||||
if (!discoveredItems.containsKey(idMeta)) {
|
||||
discoveredItems.put(idMeta, itemStack);
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
if (!discoveredItems.contains(customStackWrapper)) {
|
||||
discoveredItems.add(customStackWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : itemStackBlackList) {
|
||||
List<Integer> idMeta = Arrays.asList(itemStack.itemID, itemStack.getItemDamage());
|
||||
for (CustomStackWrapper customStackWrapper : EMCBlackList.getInstance().getBlackListStacks()) {
|
||||
|
||||
if (discoveredItems.containsKey(idMeta)) {
|
||||
discoveredItems.remove(idMeta);
|
||||
while (discoveredItems.contains(customStackWrapper)) {
|
||||
discoveredItems.remove(customStackWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : discoveredItems.values()) {
|
||||
ArrayList<IRecipe> recipes = RecipeHelper.getReverseRecipes(itemStack);
|
||||
for (CustomStackWrapper customStackWrapper : discoveredItems) {
|
||||
ArrayList<IRecipe> recipes = RecipeHelper.getReverseRecipes(customStackWrapper.itemStack);
|
||||
if (recipes.size() > 0) {
|
||||
for (IRecipe recipe : recipes) {
|
||||
LogHelper.log(Level.INFO, ItemUtil.toString(itemStack) + " <-- " + RecipeHelper.getRecipeInputs(recipe));
|
||||
LogHelper.log(Level.INFO, ItemUtil.toString(customStackWrapper.itemStack) + " <-- " + RecipeHelper.getRecipeInputs(recipe));
|
||||
}
|
||||
}
|
||||
else {
|
||||
LogHelper.log(Level.INFO, ItemUtil.toString(itemStack));
|
||||
LogHelper.log(Level.INFO, ItemUtil.toString(customStackWrapper.itemStack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
162
ee3_common/com/pahimar/ee3/emc/EMCBlackList.java
Normal file
162
ee3_common/com/pahimar/ee3/emc/EMCBlackList.java
Normal file
|
@ -0,0 +1,162 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.pahimar.ee3.item.CustomStackWrapper;
|
||||
|
||||
public class EMCBlackList {
|
||||
|
||||
private static final EMCBlackList emcBlackList = new EMCBlackList();
|
||||
|
||||
private static final ArrayList<CustomStackWrapper> stackBlackList = new ArrayList<CustomStackWrapper>();
|
||||
|
||||
private EMCBlackList() {
|
||||
|
||||
}
|
||||
|
||||
public static EMCBlackList getInstance() {
|
||||
|
||||
return emcBlackList;
|
||||
}
|
||||
|
||||
public List<CustomStackWrapper> getBlackListStacks() {
|
||||
|
||||
return stackBlackList;
|
||||
}
|
||||
|
||||
public void add(ItemStack itemStack) {
|
||||
|
||||
if (itemStack != null) {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
|
||||
if (!stackBlackList.contains(customStackWrapper)) {
|
||||
stackBlackList.add(customStackWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
public void add(Item item) {
|
||||
|
||||
this.add(new ItemStack(item.itemID, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public void add(Block block) {
|
||||
|
||||
this.add(new ItemStack(block.blockID, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public void add(int id, int meta) {
|
||||
|
||||
this.add(new ItemStack(id, 1, meta));
|
||||
}
|
||||
|
||||
public void add(int id) {
|
||||
|
||||
this.add(id, OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
|
||||
|
||||
public boolean contains(ItemStack itemStack) {
|
||||
|
||||
if (itemStack != null) {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
|
||||
return stackBlackList.contains(new CustomStackWrapper(itemStack));
|
||||
}
|
||||
|
||||
public boolean contains(Item item) {
|
||||
|
||||
return this.contains(new ItemStack(item.itemID, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public boolean contains(Block block) {
|
||||
|
||||
return this.contains(new ItemStack(block.blockID, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public boolean contains(int id, int meta) {
|
||||
|
||||
return this.contains(new ItemStack(id, 1, meta));
|
||||
}
|
||||
|
||||
public boolean contains(int id) {
|
||||
|
||||
return this.contains(id, OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
|
||||
public void remove(ItemStack itemStack) {
|
||||
|
||||
if (itemStack != null) {
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
|
||||
CustomStackWrapper customStackWrapper = new CustomStackWrapper(itemStack);
|
||||
|
||||
while (stackBlackList.contains(customStackWrapper)) {
|
||||
stackBlackList.remove(customStackWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(Item item) {
|
||||
|
||||
this.remove(new ItemStack(item.itemID, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public void remove(Block block) {
|
||||
|
||||
this.remove(new ItemStack(block.blockID, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
public void remove(int id, int meta) {
|
||||
|
||||
this.remove(new ItemStack(id, 1, meta));
|
||||
}
|
||||
|
||||
public void remove(int id) {
|
||||
|
||||
this.remove(id, OreDictionary.WILDCARD_VALUE);
|
||||
}
|
||||
|
||||
static {
|
||||
getInstance().add(Block.bed);
|
||||
getInstance().add(Block.pistonExtension);
|
||||
getInstance().add(Block.pistonMoving);
|
||||
getInstance().add(Block.mobSpawner);
|
||||
getInstance().add(Block.redstoneWire);
|
||||
getInstance().add(Block.crops);
|
||||
getInstance().add(Block.furnaceBurning);
|
||||
getInstance().add(Block.signPost);
|
||||
getInstance().add(Block.doorWood);
|
||||
getInstance().add(Block.signWall);
|
||||
getInstance().add(Block.doorIron);
|
||||
getInstance().add(Block.torchRedstoneIdle);
|
||||
getInstance().add(Block.reed);
|
||||
getInstance().add(Block.portal);
|
||||
getInstance().add(Block.cake);
|
||||
getInstance().add(Block.redstoneRepeaterIdle);
|
||||
getInstance().add(Block.redstoneRepeaterActive);
|
||||
getInstance().add(Block.lockedChest);
|
||||
getInstance().add(Block.pumpkinStem);
|
||||
getInstance().add(Block.melonStem);
|
||||
getInstance().add(Block.netherStalk);
|
||||
getInstance().add(Block.brewingStand);
|
||||
getInstance().add(Block.cauldron);
|
||||
getInstance().add(Block.endPortal);
|
||||
getInstance().add(Block.redstoneLampActive);
|
||||
getInstance().add(Block.commandBlock);
|
||||
getInstance().add(Block.carrot);
|
||||
getInstance().add(Block.potato);
|
||||
getInstance().add(Block.skull);
|
||||
getInstance().add(Block.redstoneComparatorIdle);
|
||||
getInstance().add(Block.redstoneComparatorActive);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,10 @@ import java.util.Map;
|
|||
*
|
||||
*/
|
||||
public class EMCEntry {
|
||||
|
||||
public enum EMCType {
|
||||
CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI;
|
||||
}
|
||||
|
||||
private float cost, recoveryPercentage;
|
||||
private boolean learnable, recoverable;
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Equivalent-Exchange-3
|
||||
*
|
||||
* EMCRegistry
|
||||
*
|
||||
* @author pahimar
|
||||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
*
|
||||
*/
|
||||
public class EMCRegistry {
|
||||
|
||||
private static final EMCRegistry emcRegistry = new EMCRegistry();
|
||||
|
||||
private HashMap<Integer, HashMap<Integer, EMCEntry>> emcMap = new HashMap<Integer, HashMap<Integer, EMCEntry>>();
|
||||
|
||||
public static EMCRegistry instance() {
|
||||
|
||||
return emcRegistry;
|
||||
}
|
||||
|
||||
public EMCEntry getEMCValue(Block block) {
|
||||
|
||||
if (block != null)
|
||||
return getEMCValue(block.blockID, 0);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public EMCEntry getEMCValue(Item item) {
|
||||
|
||||
if (item != null)
|
||||
return getEMCValue(item.itemID, 0);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public EMCEntry getEMCValue(ItemStack itemStack) {
|
||||
|
||||
if (itemStack != null)
|
||||
return getEMCValue(itemStack.itemID, itemStack.getItemDamage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public EMCEntry getEMCValue(int id) {
|
||||
|
||||
return getEMCValue(id, 0);
|
||||
}
|
||||
|
||||
public EMCEntry getEMCValue(int id, int meta) {
|
||||
|
||||
if (emcMap.containsKey(id)) {
|
||||
if (emcMap.get(id).containsKey(meta))
|
||||
return emcMap.get(id).get(meta);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addEMCValue(Block block, EMCEntry emcEntry) {
|
||||
|
||||
addEMCValue(block.blockID, 0, emcEntry);
|
||||
}
|
||||
|
||||
public void addEMCValue(Block block, int meta, EMCEntry emcEntry) {
|
||||
|
||||
addEMCValue(block.blockID, meta, emcEntry);
|
||||
}
|
||||
|
||||
public void addEMCValue(Item item, EMCEntry emcEntry) {
|
||||
|
||||
addEMCValue(item.itemID, 0, emcEntry);
|
||||
}
|
||||
|
||||
public void addEMCValue(ItemStack itemStack, EMCEntry emcEntry) {
|
||||
|
||||
addEMCValue(itemStack.itemID, itemStack.getItemDamage(), emcEntry);
|
||||
}
|
||||
|
||||
public void addEMCValue(int id, EMCEntry emcEntry) {
|
||||
|
||||
addEMCValue(id, 0, emcEntry);
|
||||
}
|
||||
|
||||
public void addEMCValue(int id, int meta, EMCEntry emcEntry) {
|
||||
|
||||
HashMap<Integer, EMCEntry> tempMap = new HashMap<Integer, EMCEntry>();
|
||||
|
||||
if (emcMap.containsKey(id)) {
|
||||
tempMap = emcMap.get(id);
|
||||
|
||||
if (tempMap.containsKey(meta))
|
||||
return;
|
||||
}
|
||||
|
||||
tempMap.put(meta, emcEntry);
|
||||
emcMap.put(id, tempMap);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
/**
|
||||
* Equivalent-Exchange-3
|
||||
*
|
||||
* EMCType
|
||||
*
|
||||
* @author pahimar
|
||||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
*
|
||||
*/
|
||||
public enum EMCType {
|
||||
CORPOREAL, KINETIC, TEMPORAL, ESSENTIA, AMORPHOUS, VOID, OMNI;
|
||||
}
|
|
@ -4,11 +4,11 @@ import net.minecraft.item.ItemStack;
|
|||
|
||||
import com.pahimar.ee3.core.util.ItemUtil;
|
||||
|
||||
public class ItemStackWrapper {
|
||||
public class CustomStackWrapper {
|
||||
|
||||
public ItemStack itemStack;
|
||||
|
||||
public ItemStackWrapper(ItemStack itemStack) {
|
||||
public CustomStackWrapper(ItemStack itemStack) {
|
||||
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ public class ItemStackWrapper {
|
|||
@Override
|
||||
public boolean equals(Object object) {
|
||||
|
||||
if (!(object instanceof ItemStackWrapper)) {
|
||||
if (!(object instanceof CustomStackWrapper)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStackWrapper wrappedItemStack = (ItemStackWrapper) object;
|
||||
CustomStackWrapper wrappedItemStack = (CustomStackWrapper) object;
|
||||
|
||||
return ItemUtil.compare(this.itemStack, wrappedItemStack.itemStack);
|
||||
}
|
Loading…
Reference in a new issue