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.client.renderer.texture.IIconRegister;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.init.Items;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
|
||||||
import cr0s.warpdrive.WarpDrive;
|
import cr0s.warpdrive.WarpDrive;
|
||||||
import cr0s.warpdrive.api.IAirCanister;
|
import cr0s.warpdrive.api.IAirCanister;
|
||||||
|
import cr0s.warpdrive.data.ComponentType;
|
||||||
|
|
||||||
public class ItemComponent extends Item implements IAirCanister {
|
public class ItemComponent extends Item implements IAirCanister {
|
||||||
private IIcon[] potentialIcons;
|
private IIcon[] icons;
|
||||||
private String[] potentialUnlocalized = new String[9];
|
private static ItemStack[] itemStackCache;
|
||||||
private ItemStack[] cachedIS;
|
|
||||||
|
|
||||||
public ItemComponent() {
|
public ItemComponent() {
|
||||||
super();
|
super();
|
||||||
setHasSubtypes(true);
|
setHasSubtypes(true);
|
||||||
setUnlocalizedName("warpdrive.crafting.Malformed");
|
setUnlocalizedName("warpdrive.crafting.component");
|
||||||
setCreativeTab(WarpDrive.creativeTabWarpDrive);
|
setCreativeTab(WarpDrive.creativeTabWarpDrive);
|
||||||
|
|
||||||
potentialUnlocalized[0] = "EmptyCore";
|
icons = new IIcon[ComponentType.length];
|
||||||
potentialUnlocalized[1] = "TeleCore";
|
itemStackCache = new ItemStack[ComponentType.length];
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItemStack(int damage) {
|
public static ItemStack getItemStack(ComponentType componentType) {
|
||||||
if (damage >=0 && damage < potentialUnlocalized.length) {
|
if (componentType != null) {
|
||||||
if (cachedIS[damage] == null) {
|
int damage = componentType.ordinal();
|
||||||
cachedIS[damage] = new ItemStack(WarpDrive.itemComponent,1,damage);
|
if (itemStackCache[damage] == null) {
|
||||||
|
itemStackCache[damage] = new ItemStack(WarpDrive.itemComponent, 1, damage);
|
||||||
}
|
}
|
||||||
return cachedIS[damage];
|
return itemStackCache[damage];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getISNoCache(int amount,int damage) {
|
public static ItemStack getItemStackNoCache(ComponentType componentType, int amount) {
|
||||||
return new ItemStack(WarpDrive.itemComponent, amount, damage);
|
return new ItemStack(WarpDrive.itemComponent, amount, componentType.ordinal());
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerIcons(IIconRegister par1IconRegister) {
|
public void registerIcons(IIconRegister par1IconRegister) {
|
||||||
for(int i = 0; i < potentialUnlocalized.length; i++) {
|
for(ComponentType componentType : ComponentType.values()) {
|
||||||
potentialIcons[i] = par1IconRegister.registerIcon("warpdrive:component" + potentialUnlocalized[i]);
|
icons[componentType.ordinal()] = par1IconRegister.registerIcon("warpdrive:component" + componentType.unlocalizedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName(ItemStack itemSt) {
|
public String getUnlocalizedName(ItemStack itemStack) {
|
||||||
int damage = itemSt.getItemDamage();
|
int damage = itemStack.getItemDamage();
|
||||||
if (damage >= 0 && damage < potentialUnlocalized.length) {
|
if (damage >= 0 && damage < ComponentType.length) {
|
||||||
return "item.warpdrive.crafting." + potentialUnlocalized[damage];
|
return "item.warpdrive.crafting." + ComponentType.get(damage).unlocalizedName;
|
||||||
}
|
}
|
||||||
return getUnlocalizedName();
|
return getUnlocalizedName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIconFromDamage(int damage) {
|
public IIcon getIconFromDamage(int damage) {
|
||||||
if (damage >= 0 && damage < potentialUnlocalized.length) {
|
if (damage >= 0 && damage < ComponentType.length) {
|
||||||
return potentialIcons[damage];
|
return icons[damage];
|
||||||
}
|
}
|
||||||
return potentialIcons[0];
|
return icons[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
|
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
|
||||||
for(int i = 0; i < potentialUnlocalized.length; i++) {
|
for(ComponentType componentType : ComponentType.values()) {
|
||||||
par3List.add(new ItemStack(par1, 1, i));
|
par3List.add(new ItemStack(par1, 1, componentType.ordinal()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For empty air cans
|
// For empty air canister
|
||||||
@Override
|
@Override
|
||||||
public ItemStack fullDrop(ItemStack is) {
|
public ItemStack fullDrop(ItemStack itemStack) {
|
||||||
if (doesMatch(is, "AirCanisterEmpty")) {
|
if (canContainAir(itemStack)) {
|
||||||
return WarpDrive.itemAirCanisterFull.fullDrop(is);
|
return WarpDrive.itemAirCanisterFull.fullDrop(itemStack);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack emptyDrop(ItemStack is) {
|
public ItemStack emptyDrop(ItemStack itemStack) {
|
||||||
if (doesMatch(is, "AirCanisterEmpty")) {
|
if (canContainAir(itemStack)) {
|
||||||
return WarpDrive.itemAirCanisterFull.emptyDrop(is);
|
return WarpDrive.itemAirCanisterFull.emptyDrop(itemStack);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canContainAir(ItemStack is) {
|
public boolean canContainAir(ItemStack itemStack) {
|
||||||
return doesMatch(is, "AirCanisterEmpty");
|
return (itemStack.getItem() instanceof ItemComponent && itemStack.getItemDamage() == ComponentType.AIR_CANISTER.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsAir(ItemStack is) {
|
public boolean containsAir(ItemStack itemStack) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +1,22 @@
|
||||||
item.warpdrive.crafting.Malformed.name=Bad Item
|
item.warpdrive.crafting.Malformed.name=Bad Item
|
||||||
item.warpdrive.crafting.EmptyCore.name=Empty Core
|
item.warpdrive.crafting.EmeraldCrystal.name=Emerald Tuned Crystal
|
||||||
item.warpdrive.crafting.TeleCore.name=Teleportation Core
|
item.warpdrive.crafting.EnderCrystal.name=Ender Tuned Crystal
|
||||||
item.warpdrive.crafting.WarpCore.name=Warp Core
|
item.warpdrive.crafting.DiamondCrystal.name=Diamond Tuned Crystal
|
||||||
item.warpdrive.crafting.LaserCore.name=Laser Core
|
item.warpdrive.crafting.DiffrationGrating.name=Diffration Grating
|
||||||
item.warpdrive.crafting.ReactorCore.name=Reactor Core
|
item.warpdrive.crafting.ReactorCore.name=Reactor Core
|
||||||
item.warpdrive.crafting.InterfaceComputer.name=Computer Interface
|
item.warpdrive.crafting.ComputerInterface.name=Computer Interface
|
||||||
item.warpdrive.crafting.InterfacePower.name=Power Interface
|
item.warpdrive.crafting.PowerInterface.name=Power Interface
|
||||||
item.warpdrive.crafting.PowerCore.name=Energy Core
|
item.warpdrive.crafting.CapacitiveCrystal.name=Capacitive Crystal
|
||||||
item.warpdrive.crafting.AirCanisterEmpty.name=Empty Air Canister
|
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.energy.IC2reactorLaserFocus.name=IC2 Reactor Laser Focus
|
||||||
item.warpdrive.armor.AirCanisterFull.name=Air Canister
|
item.warpdrive.armor.AirCanisterFull.name=Air Canister
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue