Added new components (code)
Existing ones have been reallocated
This commit is contained in:
parent
62f94c2af2
commit
e09a6d1174
4 changed files with 101 additions and 119 deletions
45
src/main/java/cr0s/warpdrive/data/ComponentType.java
Normal file
45
src/main/java/cr0s/warpdrive/data/ComponentType.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package cr0s.warpdrive.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public enum ComponentType {
|
||||
EMERALD_CRYSTAL ("EmeraldCrystal"), // EmptyCore
|
||||
ENDER_CRYSTAL ("EnderCrystal"), // TeleCore
|
||||
DIAMOND_CRYSTAL ("DiamondCrystal"), // WarpCore
|
||||
DIFFRACTION_GRATING("DiffrationGrating"), // LaserCore
|
||||
REACTOR_CORE ("ReactorCore"),
|
||||
COMPUTER_INTERFACE ("ComputerInterface"), // InterfaceComputer
|
||||
POWER_INTERFACE ("PowerInterface"), // InterfacePower
|
||||
CAPACITIVE_CRYSTAL ("CapacitiveCrystal"), // PowerCore
|
||||
AIR_CANISTER ("AirCanisterEmpty"),
|
||||
LENS ("Lens"),
|
||||
ZOOM ("Zoom"),
|
||||
GLASS_TANK ("GlassTank"),
|
||||
FLAT_SCREEN ("FlatScreen"),
|
||||
MEMORY_CRYSTAL ("MemoryCrystal"),
|
||||
MOTOR ("Motor"),
|
||||
BONE_CHARCOAL ("BoneCharcoal"),
|
||||
ACTIVATED_CARBON ("ActivatedCarbon"),
|
||||
LASER_MEDIUM_EMPTY ("LaserMediumEmpty");
|
||||
|
||||
public final String unlocalizedName;
|
||||
|
||||
// cached values
|
||||
public static final int length;
|
||||
private static final HashMap<Integer, ComponentType> ID_MAP = new HashMap<Integer, ComponentType>();
|
||||
|
||||
static {
|
||||
length = ComponentType.values().length;
|
||||
for (ComponentType componentType : values()) {
|
||||
ID_MAP.put(componentType.ordinal(), componentType);
|
||||
}
|
||||
}
|
||||
|
||||
private ComponentType(String unlocalizedName) {
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
}
|
||||
|
||||
public static ComponentType get(final int damage) {
|
||||
return ID_MAP.get(damage);
|
||||
}
|
||||
}
|
|
@ -4,169 +4,97 @@ import java.util.List;
|
|||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IAirCanister;
|
||||
import cr0s.warpdrive.data.ComponentType;
|
||||
|
||||
public class ItemComponent extends Item implements IAirCanister {
|
||||
private IIcon[] potentialIcons;
|
||||
private String[] potentialUnlocalized = new String[9];
|
||||
private ItemStack[] cachedIS;
|
||||
private IIcon[] icons;
|
||||
private static ItemStack[] itemStackCache;
|
||||
|
||||
public ItemComponent() {
|
||||
super();
|
||||
setHasSubtypes(true);
|
||||
setUnlocalizedName("warpdrive.crafting.Malformed");
|
||||
setUnlocalizedName("warpdrive.crafting.component");
|
||||
setCreativeTab(WarpDrive.creativeTabWarpDrive);
|
||||
|
||||
potentialUnlocalized[0] = "EmptyCore";
|
||||
potentialUnlocalized[1] = "TeleCore";
|
||||
potentialUnlocalized[2] = "WarpCore";
|
||||
potentialUnlocalized[3] = "LaserCore";
|
||||
potentialUnlocalized[4] = "ReactorCore";
|
||||
potentialUnlocalized[5] = "InterfaceComputer";
|
||||
potentialUnlocalized[6] = "InterfacePower";
|
||||
potentialUnlocalized[7] = "PowerCore";
|
||||
potentialUnlocalized[8] = "AirCanisterEmpty";
|
||||
|
||||
potentialIcons = new IIcon[potentialUnlocalized.length];
|
||||
cachedIS = new ItemStack[potentialUnlocalized.length];
|
||||
icons = new IIcon[ComponentType.length];
|
||||
itemStackCache = new ItemStack[ComponentType.length];
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(int damage) {
|
||||
if (damage >=0 && damage < potentialUnlocalized.length) {
|
||||
if (cachedIS[damage] == null) {
|
||||
cachedIS[damage] = new ItemStack(WarpDrive.itemComponent,1,damage);
|
||||
public static ItemStack getItemStack(ComponentType componentType) {
|
||||
if (componentType != null) {
|
||||
int damage = componentType.ordinal();
|
||||
if (itemStackCache[damage] == null) {
|
||||
itemStackCache[damage] = new ItemStack(WarpDrive.itemComponent, 1, damage);
|
||||
}
|
||||
return cachedIS[damage];
|
||||
return itemStackCache[damage];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getISNoCache(int amount,int damage) {
|
||||
return new ItemStack(WarpDrive.itemComponent, amount, damage);
|
||||
}
|
||||
|
||||
public void registerRecipes() {
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(0),false,"nrn","r r","nrn",
|
||||
'r', Items.redstone,
|
||||
'n', Items.gold_nugget));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(1),false,"g","e","c",
|
||||
'g', Blocks.glass,
|
||||
'e', Items.ender_pearl,
|
||||
'c', getItemStack(0)));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(2),false," g ","ede"," c ",
|
||||
'g', Blocks.glass,
|
||||
'e', Items.ender_pearl,
|
||||
'd', Items.diamond,
|
||||
'c', getItemStack(0)));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(3),false," g ","rtr"," c ",
|
||||
'g', Blocks.glass,
|
||||
'r', "dyeBlue",
|
||||
't', Blocks.torch,
|
||||
'c', getItemStack(0)));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(4),false," l ","rcr"," l ",
|
||||
'l', "dyeWhite",
|
||||
'r', Items.coal,
|
||||
'c', getItemStack(0)));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(5),false,"g ","gwr","rwr",
|
||||
'g', Items.gold_nugget,
|
||||
'r', Items.redstone,
|
||||
'w', "plankWood"));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(6),false,"gig","iri","gig",
|
||||
'g', Items.gold_nugget,
|
||||
'r', Items.redstone,
|
||||
'i', Items.iron_ingot));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(7),false,"glg","ldl","glg",
|
||||
'g', Items.gold_nugget,
|
||||
'l', "dyeBlue",
|
||||
'd', Items.diamond));
|
||||
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(getItemStack(8),false,"gcg","g g","gcg",
|
||||
'g', Blocks.glass,
|
||||
'c', getItemStack(0)));
|
||||
}
|
||||
|
||||
public boolean doesMatch(ItemStack is, String unlocalised) {
|
||||
if (is == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(is.getItem() instanceof ItemComponent)) {
|
||||
return false;
|
||||
}
|
||||
String data = potentialUnlocalized[is.getItemDamage()];
|
||||
// WarpDrive.logger.info(data);
|
||||
return data.equals(unlocalised);
|
||||
public static ItemStack getItemStackNoCache(ComponentType componentType, int amount) {
|
||||
return new ItemStack(WarpDrive.itemComponent, amount, componentType.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIcons(IIconRegister par1IconRegister) {
|
||||
for(int i = 0; i < potentialUnlocalized.length; i++) {
|
||||
potentialIcons[i] = par1IconRegister.registerIcon("warpdrive:component" + potentialUnlocalized[i]);
|
||||
for(ComponentType componentType : ComponentType.values()) {
|
||||
icons[componentType.ordinal()] = par1IconRegister.registerIcon("warpdrive:component" + componentType.unlocalizedName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemSt) {
|
||||
int damage = itemSt.getItemDamage();
|
||||
if (damage >= 0 && damage < potentialUnlocalized.length) {
|
||||
return "item.warpdrive.crafting." + potentialUnlocalized[damage];
|
||||
public String getUnlocalizedName(ItemStack itemStack) {
|
||||
int damage = itemStack.getItemDamage();
|
||||
if (damage >= 0 && damage < ComponentType.length) {
|
||||
return "item.warpdrive.crafting." + ComponentType.get(damage).unlocalizedName;
|
||||
}
|
||||
return getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconFromDamage(int damage) {
|
||||
if (damage >= 0 && damage < potentialUnlocalized.length) {
|
||||
return potentialIcons[damage];
|
||||
if (damage >= 0 && damage < ComponentType.length) {
|
||||
return icons[damage];
|
||||
}
|
||||
return potentialIcons[0];
|
||||
return icons[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
|
||||
for(int i = 0; i < potentialUnlocalized.length; i++) {
|
||||
par3List.add(new ItemStack(par1, 1, i));
|
||||
for(ComponentType componentType : ComponentType.values()) {
|
||||
par3List.add(new ItemStack(par1, 1, componentType.ordinal()));
|
||||
}
|
||||
}
|
||||
|
||||
// For empty air cans
|
||||
// For empty air canister
|
||||
@Override
|
||||
public ItemStack fullDrop(ItemStack is) {
|
||||
if (doesMatch(is, "AirCanisterEmpty")) {
|
||||
return WarpDrive.itemAirCanisterFull.fullDrop(is);
|
||||
public ItemStack fullDrop(ItemStack itemStack) {
|
||||
if (canContainAir(itemStack)) {
|
||||
return WarpDrive.itemAirCanisterFull.fullDrop(itemStack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack emptyDrop(ItemStack is) {
|
||||
if (doesMatch(is, "AirCanisterEmpty")) {
|
||||
return WarpDrive.itemAirCanisterFull.emptyDrop(is);
|
||||
public ItemStack emptyDrop(ItemStack itemStack) {
|
||||
if (canContainAir(itemStack)) {
|
||||
return WarpDrive.itemAirCanisterFull.emptyDrop(itemStack);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canContainAir(ItemStack is) {
|
||||
return doesMatch(is, "AirCanisterEmpty");
|
||||
public boolean canContainAir(ItemStack itemStack) {
|
||||
return (itemStack.getItem() instanceof ItemComponent && itemStack.getItemDamage() == ComponentType.AIR_CANISTER.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAir(ItemStack is) {
|
||||
public boolean containsAir(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,22 @@
|
|||
item.warpdrive.crafting.Malformed.name=Bad Item
|
||||
item.warpdrive.crafting.EmptyCore.name=Empty Core
|
||||
item.warpdrive.crafting.TeleCore.name=Teleportation Core
|
||||
item.warpdrive.crafting.WarpCore.name=Warp Core
|
||||
item.warpdrive.crafting.LaserCore.name=Laser Core
|
||||
item.warpdrive.crafting.EmeraldCrystal.name=Emerald Tuned Crystal
|
||||
item.warpdrive.crafting.EnderCrystal.name=Ender Tuned Crystal
|
||||
item.warpdrive.crafting.DiamondCrystal.name=Diamond Tuned Crystal
|
||||
item.warpdrive.crafting.DiffrationGrating.name=Diffration Grating
|
||||
item.warpdrive.crafting.ReactorCore.name=Reactor Core
|
||||
item.warpdrive.crafting.InterfaceComputer.name=Computer Interface
|
||||
item.warpdrive.crafting.InterfacePower.name=Power Interface
|
||||
item.warpdrive.crafting.PowerCore.name=Energy Core
|
||||
item.warpdrive.crafting.ComputerInterface.name=Computer Interface
|
||||
item.warpdrive.crafting.PowerInterface.name=Power Interface
|
||||
item.warpdrive.crafting.CapacitiveCrystal.name=Capacitive Crystal
|
||||
item.warpdrive.crafting.AirCanisterEmpty.name=Empty Air Canister
|
||||
item.warpdrive.crafting.Lens.name=Lens
|
||||
item.warpdrive.crafting.Zoom.name=Zoom
|
||||
item.warpdrive.crafting.GlassTank.name=Glass Tank
|
||||
item.warpdrive.crafting.FlatScreen.name=Flat Screen
|
||||
item.warpdrive.crafting.MemoryCrystal.name=Memory Crystal
|
||||
item.warpdrive.crafting.Motor.name=Motor
|
||||
item.warpdrive.crafting.BoneCharcoal.name=Bone Charcoal
|
||||
item.warpdrive.crafting.ActivatedCarbon.name=Activated Carbon
|
||||
item.warpdrive.crafting.LaserMediumEmpty.name=Laser Medium (empty)
|
||||
|
||||
item.warpdrive.energy.IC2reactorLaserFocus.name=IC2 Reactor Laser Focus
|
||||
item.warpdrive.armor.AirCanisterFull.name=Air Canister
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue