More work!

This commit is contained in:
Aidan C. Brady 2014-07-21 21:21:53 -04:00
parent 2523d2fd6b
commit 076c5f7377
8 changed files with 116 additions and 62 deletions

View file

@ -81,7 +81,6 @@ import mekanism.common.item.ItemGasMask;
import mekanism.common.item.ItemHDPE;
import mekanism.common.item.ItemIngot;
import mekanism.common.item.ItemJetpack;
import mekanism.common.item.ItemMachineUpgrade;
import mekanism.common.item.ItemMekanism;
import mekanism.common.item.ItemNetworkReader;
import mekanism.common.item.ItemPortableTeleporter;
@ -90,6 +89,7 @@ import mekanism.common.item.ItemRobit;
import mekanism.common.item.ItemScubaTank;
import mekanism.common.item.ItemSeismicReader;
import mekanism.common.item.ItemShard;
import mekanism.common.item.ItemUpgrade;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.multipart.ItemGlowPanel;
import mekanism.common.multipart.ItemPartTransmitter;
@ -964,8 +964,8 @@ public class Mekanism
CompressedObsidian = new ItemMekanism().setUnlocalizedName("CompressedObsidian");
TeleportationCore = new ItemMekanism().setUnlocalizedName("TeleportationCore");
ElectrolyticCore = new ItemMekanism().setUnlocalizedName("ElectrolyticCore");
SpeedUpgrade = new ItemMachineUpgrade().setUnlocalizedName("SpeedUpgrade");
EnergyUpgrade = new ItemMachineUpgrade().setUnlocalizedName("EnergyUpgrade");
SpeedUpgrade = new ItemUpgrade(Upgrade.SPEED).setUnlocalizedName("SpeedUpgrade");
EnergyUpgrade = new ItemUpgrade(Upgrade.ENERGY).setUnlocalizedName("EnergyUpgrade");
EnergyTablet = (ItemEnergized)new ItemEnergized(1000000).setUnlocalizedName("EnergyTablet");
Dictionary = new ItemDictionary().setUnlocalizedName("Dictionary");
FilterCard = new ItemFilterCard().setUnlocalizedName("FilterCard");

View file

@ -1,19 +1,29 @@
package mekanism.common;
import java.util.HashMap;
import java.util.Map;
import mekanism.api.EnumColor;
import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;
public enum Upgrade
{
SPEED("speed", 16),
ENERGY("energy", 16);
SPEED("speed", 8, EnumColor.RED),
ENERGY("energy", 8, EnumColor.BRIGHT_GREEN);
private String name;
private int maxStack;
private EnumColor color;
private boolean canMultiply;
private Upgrade(String s, int max)
private Upgrade(String s, int max, EnumColor c)
{
name = s;
maxStack = max;
color = c;
}
public String getName()
@ -30,4 +40,52 @@ public enum Upgrade
{
return maxStack;
}
public EnumColor getColor()
{
return color;
}
public boolean canMultiply()
{
return getMax() > 1;
}
public static Map<Upgrade, Integer> buildMap(NBTTagCompound nbtTags)
{
Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
NBTTagList list = nbtTags.getTagList("upgrades", NBT.TAG_COMPOUND);
for(int tagCount = 0; tagCount < list.tagCount(); tagCount++)
{
NBTTagCompound compound = (NBTTagCompound)list.getCompoundTagAt(tagCount);
Upgrade upgrade = Upgrade.values()[compound.getInteger("type")];
upgrades.put(upgrade, compound.getInteger("amount"));
}
return upgrades;
}
public static void saveMap(Map<Upgrade, Integer> upgrades, NBTTagCompound nbtTags)
{
NBTTagList list = new NBTTagList();
for(Map.Entry<Upgrade, Integer> entry : upgrades.entrySet())
{
list.appendTag(getTagFor(entry.getKey(), entry.getValue()));
}
nbtTags.setTag("upgrades", list);
}
public static NBTTagCompound getTagFor(Upgrade upgrade, int amount)
{
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("type", upgrade.ordinal());
compound.setInteger("amount", amount);
return compound;
}
}

View file

@ -17,6 +17,7 @@ import mekanism.common.ISpecialBounds;
import mekanism.common.ISustainedInventory;
import mekanism.common.ISustainedTank;
import mekanism.common.IUpgradeManagement;
import mekanism.common.IUpgradeTile;
import mekanism.common.ItemAttacher;
import mekanism.common.Mekanism;
import mekanism.common.miner.MinerFilter;
@ -74,7 +75,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
@ -1015,10 +1015,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
if(((IUpgradeManagement)itemStack.getItem()).supportsUpgrades(itemStack))
{
IUpgradeManagement upgrade = (IUpgradeManagement)itemStack.getItem();
upgrade.setEnergyMultiplier(((IUpgradeManagement)tileEntity).getEnergyMultiplier(), itemStack);
upgrade.setSpeedMultiplier(((IUpgradeManagement)tileEntity).getSpeedMultiplier(), itemStack);
((IUpgradeTile)tileEntity).getComponent().write(itemStack.stackTagCompound);
}
if(tileEntity instanceof IInvConfiguration)

View file

@ -6,6 +6,7 @@ import ic2.api.item.IElectricItemManager;
import ic2.api.item.ISpecialElectricItem;
import java.util.List;
import java.util.Map;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
@ -21,7 +22,9 @@ import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.ISustainedInventory;
import mekanism.common.ISustainedTank;
import mekanism.common.IUpgradeManagement;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.integration.IC2ItemManager;
import mekanism.common.inventory.InventoryElectricChest;
@ -180,17 +183,21 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
list.add(EnumColor.PINK + FluidRegistry.getFluidName(getFluidStack(itemstack)) + ": " + EnumColor.GREY + getFluidStack(itemstack).amount + "mB");
}
}
if(supportsUpgrades(itemstack))
{
list.add(EnumColor.PURPLE + MekanismUtils.localize("tooltip.upgrade.energy") + ": " + EnumColor.GREY + "x" + (getEnergyMultiplier(itemstack)+1));
list.add(EnumColor.PURPLE + MekanismUtils.localize("tooltip.upgrade.speed") + ": " + EnumColor.GREY + "x" + (getSpeedMultiplier(itemstack)+1));
}
if(type != MachineType.CHARGEPAD && type != MachineType.LOGISTICAL_SORTER)
{
list.add(EnumColor.AQUA + MekanismUtils.localize("tooltip.inventory") + ": " + EnumColor.GREY + LangUtils.transYesNo(getInventory(itemstack) != null && getInventory(itemstack).tagCount() != 0));
}
if(supportsUpgrades(itemstack) && itemstack.stackTagCompound != null && itemstack.stackTagCompound.hasKey("upgrades"))
{
Map<Upgrade, Integer> upgrades = Upgrade.buildMap(itemstack.stackTagCompound);
for(Map.Entry<Upgrade, Integer> entry : upgrades.entrySet())
{
list.add(entry.getKey().getColor() + "- " + entry.getKey().getName() + (entry.getKey().canMultiply() ? ": " + EnumColor.GREY + entry.getValue(): ""));
}
}
}
else {
list.addAll(MekanismUtils.splitLines(type.getDescription()));
@ -245,10 +252,12 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, ISpec
{
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(x, y, z);
if(tileEntity instanceof IUpgradeManagement)
if(tileEntity instanceof IUpgradeTile)
{
((IUpgradeManagement)tileEntity).setEnergyMultiplier(getEnergyMultiplier(stack));
((IUpgradeManagement)tileEntity).setSpeedMultiplier(getSpeedMultiplier(stack));
if(stack.stackTagCompound != null && stack.stackTagCompound.hasKey("upgrades"))
{
((IUpgradeTile)tileEntity).getComponent().read(stack.stackTagCompound);
}
}
if(tileEntity instanceof IInvConfiguration)

View file

@ -1,13 +0,0 @@
package mekanism.common.item;
import mekanism.common.Mekanism;
public class ItemMachineUpgrade extends ItemMekanism
{
public ItemMachineUpgrade()
{
super();
setMaxStackSize(8);
setCreativeTab(Mekanism.tabMekanism);
}
}

View file

@ -0,0 +1,23 @@
package mekanism.common.item;
import mekanism.common.IUpgradeItem;
import mekanism.common.Upgrade;
import net.minecraft.item.ItemStack;
public class ItemUpgrade extends ItemMekanism implements IUpgradeItem
{
private Upgrade upgrade;
public ItemUpgrade(Upgrade type)
{
upgrade = type;
setMaxStackSize(type.getMax());
}
@Override
public Upgrade getUpgradeType(ItemStack stack)
{
return upgrade;
}
}

View file

@ -14,7 +14,6 @@ import mekanism.common.Upgrade;
import mekanism.common.tile.TileEntityContainerBlock;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;
public class TileComponentUpgrade implements ITileComponent
{
@ -134,16 +133,6 @@ public class TileComponentUpgrade implements ITileComponent
{
return supported.contains(upgrade);
}
public NBTTagCompound getTagFor(Upgrade upgrade)
{
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("type", upgrade.ordinal());
compound.setInteger("amount", getUpgrades(upgrade));
return compound;
}
@Override
public void read(ByteBuf dataStream)
@ -177,27 +166,12 @@ public class TileComponentUpgrade implements ITileComponent
@Override
public void read(NBTTagCompound nbtTags)
{
NBTTagList list = nbtTags.getTagList("upgrades", NBT.TAG_COMPOUND);
for(int tagCount = 0; tagCount < list.tagCount(); tagCount++)
{
NBTTagCompound compound = (NBTTagCompound)list.getCompoundTagAt(tagCount);
Upgrade upgrade = Upgrade.values()[compound.getInteger("type")];
upgrades.put(upgrade, compound.getInteger("amount"));
}
upgrades = Upgrade.buildMap(nbtTags);
}
@Override
public void write(NBTTagCompound nbtTags)
{
NBTTagList list = new NBTTagList();
for(Upgrade upgrade : upgrades.keySet())
{
list.appendTag(getTagFor(upgrade));
}
nbtTags.setTag("upgrades", list);
Upgrade.saveMap(upgrades, nbtTags);
}
}

View file

@ -290,6 +290,12 @@ update.toDownload=to download
update.devBuild=Using developer build
update.outdated=Using outdated version on one or more modules
//Upgrades
upgrade.energy=Energy
upgrade.energy.desc=Increases energy efficiency and capacity of machinery.
upgrade.speed=Speed
upgrade.speed.desc=Increases speed of machinery.
//Key description text
key.mode=Mode Switch
key.voice=Voice