Merge pull request #359 from ljfa-ag/magnetism

Cache values of isBlockOre for Ritual of Magnetism
This commit is contained in:
WayofTime 2015-06-21 13:26:57 -04:00
commit 9686c6f8b5
2 changed files with 28 additions and 3 deletions

View file

@ -79,6 +79,12 @@ public class ItemType
return result; return result;
} }
@Override
public String toString()
{
return item.getUnlocalizedName() + "@" + meta;
}
public static ItemType fromStack(ItemStack stack) public static ItemType fromStack(ItemStack stack)
{ {
return new ItemType(stack.getItem(), stack.getItemDamage(), stack.stackTagCompound); return new ItemType(stack.getItem(), stack.getItemDamage(), stack.stackTagCompound);

View file

@ -1,11 +1,14 @@
package WayofTime.alchemicalWizardry.common.rituals; package WayofTime.alchemicalWizardry.common.rituals;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockOre; import net.minecraft.block.BlockOre;
import net.minecraft.block.BlockRedstoneOre; import net.minecraft.block.BlockRedstoneOre;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -16,6 +19,7 @@ import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone;
import WayofTime.alchemicalWizardry.api.rituals.RitualComponent; import WayofTime.alchemicalWizardry.api.rituals.RitualComponent;
import WayofTime.alchemicalWizardry.api.rituals.RitualEffect; import WayofTime.alchemicalWizardry.api.rituals.RitualEffect;
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler; import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
import WayofTime.alchemicalWizardry.common.ItemType;
import WayofTime.alchemicalWizardry.common.block.BlockTeleposer; import WayofTime.alchemicalWizardry.common.block.BlockTeleposer;
public class RitualEffectMagnetic extends RitualEffect public class RitualEffectMagnetic extends RitualEffect
@ -24,15 +28,29 @@ public class RitualEffectMagnetic extends RitualEffect
private static final int terraeDrain = 10; private static final int terraeDrain = 10;
private static final int orbisTerraeDrain = 10; private static final int orbisTerraeDrain = 10;
private static final Map<ItemType, Boolean> oreBlockCache = new HashMap<ItemType, Boolean>();
public static boolean isBlockOre(Block block, int meta) public static boolean isBlockOre(Block block, int meta)
{ {
if (block == null) if (block == null || Item.getItemFromBlock(block) == null)
return false; return false;
if (block instanceof BlockOre || block instanceof BlockRedstoneOre) if (block instanceof BlockOre || block instanceof BlockRedstoneOre)
return true; return true;
ItemStack itemStack = new ItemStack(block, 1, meta); ItemType type = new ItemType(block, meta);
Boolean result = oreBlockCache.get(type);
if (result == null)
{
result = computeIsItemOre(type);
oreBlockCache.put(type, result);
}
return result;
}
private static boolean computeIsItemOre(ItemType type)
{
ItemStack itemStack = type.createStack(1);
for (int id : OreDictionary.getOreIDs(itemStack)) for (int id : OreDictionary.getOreIDs(itemStack))
{ {
String oreName = OreDictionary.getOreName(id); String oreName = OreDictionary.getOreName(id);
@ -75,6 +93,7 @@ public class RitualEffectMagnetic extends RitualEffect
int zRep = 0; int zRep = 0;
boolean replace = false; boolean replace = false;
outer:
for (int j = 1; j <= 3; j++) for (int j = 1; j <= 3; j++)
{ {
for (int i = -1; i <= 1; i++) for (int i = -1; i <= 1; i++)
@ -87,7 +106,7 @@ public class RitualEffectMagnetic extends RitualEffect
yRep = y + j; yRep = y + j;
zRep = z + k; zRep = z + k;
replace = true; replace = true;
break; break outer;
} }
} }
} }