Did some work on actual upgrade system

This commit is contained in:
Aidan C. Brady 2014-07-21 20:46:35 -04:00
parent 435596831e
commit 2523d2fd6b
10 changed files with 166 additions and 83 deletions

View file

@ -0,0 +1,8 @@
package mekanism.common;
import net.minecraft.item.ItemStack;
public interface IUpgradeItem
{
public Upgrade getUpgradeType(ItemStack stack);
}

View file

@ -4,14 +4,16 @@ import mekanism.common.util.MekanismUtils;
public enum Upgrade
{
SPEED("speed"),
ENERGY("energy");
SPEED("speed", 16),
ENERGY("energy", 16);
private String name;
private int maxStack;
private Upgrade(String s)
private Upgrade(String s, int max)
{
name = s;
maxStack = max;
}
public String getName()
@ -23,4 +25,9 @@ public enum Upgrade
{
return MekanismUtils.localize("upgrade." + name + ".desc");
}
public int getMax()
{
return maxStack;
}
}

View file

@ -15,6 +15,7 @@ import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.SideData;
import mekanism.common.Upgrade;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentUpgrade;
@ -23,7 +24,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
@ -294,26 +294,26 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
return upgradeComponent.getUpgrades(Upgrade.ENERGY);
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.ENERGY, multiplier);
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
return upgradeComponent.getUpgrades(Upgrade.SPEED);
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.SPEED, multiplier);
MekanismUtils.saveChunk(this);
}

View file

@ -22,6 +22,7 @@ import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.SideData;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
@ -505,26 +506,26 @@ public class TileEntityChemicalCrystallizer extends TileEntityElectricBlock impl
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
return upgradeComponent.getUpgrades(Upgrade.ENERGY);
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.ENERGY, multiplier);
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
return upgradeComponent.getUpgrades(Upgrade.SPEED);
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.SPEED, multiplier);
MekanismUtils.saveChunk(this);
}

View file

@ -18,6 +18,7 @@ import mekanism.common.IActiveState;
import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
@ -437,26 +438,26 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityElectricBloc
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
return upgradeComponent.getUpgrades(Upgrade.ENERGY);
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.ENERGY, multiplier);
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
return upgradeComponent.getUpgrades(Upgrade.SPEED);
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.SPEED, multiplier);
MekanismUtils.saveChunk(this);
}

View file

@ -17,6 +17,7 @@ import mekanism.common.IActiveState;
import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
@ -363,26 +364,26 @@ public class TileEntityChemicalOxidizer extends TileEntityElectricBlock implemen
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
return upgradeComponent.getUpgrades(Upgrade.ENERGY);
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.ENERGY, multiplier);
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
return upgradeComponent.getUpgrades(Upgrade.SPEED);
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.SPEED, multiplier);
MekanismUtils.saveChunk(this);
}

View file

@ -19,6 +19,7 @@ import mekanism.common.ILogisticalTransporter;
import mekanism.common.IRedstoneControl;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.inventory.container.ContainerNull;
@ -967,26 +968,26 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
return upgradeComponent.getUpgrades(Upgrade.ENERGY);
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.ENERGY, multiplier);
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
return upgradeComponent.getUpgrades(Upgrade.SPEED);
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.SPEED, multiplier);
MekanismUtils.saveChunk(this);
}

View file

@ -24,6 +24,7 @@ import mekanism.common.IUpgradeManagement;
import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.SideData;
import mekanism.common.Upgrade;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
@ -39,7 +40,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
@ -826,26 +826,26 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
return upgradeComponent.getUpgrades(Upgrade.ENERGY);
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.ENERGY, multiplier);
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
return upgradeComponent.getUpgrades(Upgrade.SPEED);
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.SPEED, multiplier);
MekanismUtils.saveChunk(this);
}

View file

@ -20,6 +20,7 @@ import mekanism.common.IUpgradeTile;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.SideData;
import mekanism.common.Upgrade;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler;
@ -33,7 +34,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
@ -548,26 +548,26 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
@Override
public int getEnergyMultiplier(Object... data)
{
return upgradeComponent.energyMultiplier;
return upgradeComponent.getUpgrades(Upgrade.ENERGY);
}
@Override
public void setEnergyMultiplier(int multiplier, Object... data)
{
upgradeComponent.energyMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.ENERGY, multiplier);
MekanismUtils.saveChunk(this);
}
@Override
public int getSpeedMultiplier(Object... data)
{
return upgradeComponent.speedMultiplier;
return upgradeComponent.getUpgrades(Upgrade.SPEED);
}
@Override
public void setSpeedMultiplier(int multiplier, Object... data)
{
upgradeComponent.speedMultiplier = multiplier;
upgradeComponent.setUpgrades(Upgrade.SPEED, multiplier);
MekanismUtils.saveChunk(this);
}

View file

@ -3,17 +3,27 @@ package mekanism.common.tile.component;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import mekanism.common.ITileComponent;
import mekanism.common.Mekanism;
import mekanism.common.IUpgradeItem;
import mekanism.common.Upgrade;
import mekanism.common.tile.TileEntityContainerBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants.NBT;
public class TileComponentUpgrade implements ITileComponent
{
/** How long it takes this machine to install an upgrade. */
public static int UPGRADE_TICKS_REQUIRED = 40;
private Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
private Set<Upgrade> supported = new HashSet<Upgrade>();
/** The inventory slot the upgrade slot of this component occupies. */
private int upgradeSlot;
@ -21,12 +31,6 @@ public class TileComponentUpgrade implements ITileComponent
/** How many upgrade ticks have progressed. */
public int upgradeTicks;
/** This machine's speed multiplier. */
public int speedMultiplier;
/** This machine's energy multiplier. */
public int energyMultiplier;
/** TileEntity implementing this component. */
public TileEntityContainerBlock tileEntity;
@ -34,6 +38,9 @@ public class TileComponentUpgrade implements ITileComponent
{
tileEntity = tile;
upgradeSlot = slot;
setSupported(Upgrade.SPEED);
setSupported(Upgrade.ENERGY);
tile.components.add(this);
}
@ -43,9 +50,11 @@ public class TileComponentUpgrade implements ITileComponent
{
if(!tileEntity.getWorldObj().isRemote)
{
if(tileEntity.inventory[upgradeSlot] != null)
if(tileEntity.inventory[upgradeSlot] != null && tileEntity.inventory[upgradeSlot].getItem() instanceof IUpgradeItem)
{
if(tileEntity.inventory[upgradeSlot].isItemEqual(new ItemStack(Mekanism.EnergyUpgrade)) && energyMultiplier < 8)
Upgrade type = ((IUpgradeItem)tileEntity.inventory[upgradeSlot].getItem()).getUpgradeType(tileEntity.inventory[upgradeSlot]);
if(supports(type) && getUpgrades(type) < type.getMax())
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
@ -54,28 +63,7 @@ public class TileComponentUpgrade implements ITileComponent
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
energyMultiplier++;
tileEntity.inventory[upgradeSlot].stackSize--;
if(tileEntity.inventory[upgradeSlot].stackSize == 0)
{
tileEntity.inventory[upgradeSlot] = null;
}
tileEntity.markDirty();
}
}
else if(tileEntity.inventory[upgradeSlot].isItemEqual(new ItemStack(Mekanism.SpeedUpgrade)) && speedMultiplier < 8)
{
if(upgradeTicks < UPGRADE_TICKS_REQUIRED)
{
upgradeTicks++;
}
else if(upgradeTicks == UPGRADE_TICKS_REQUIRED)
{
upgradeTicks = 0;
speedMultiplier++;
addUpgrade(type);
tileEntity.inventory[upgradeSlot].stackSize--;
@ -106,34 +94,110 @@ public class TileComponentUpgrade implements ITileComponent
{
return upgradeTicks*i / UPGRADE_TICKS_REQUIRED;
}
@Override
public void read(NBTTagCompound nbtTags)
public int getUpgrades(Upgrade upgrade)
{
speedMultiplier = nbtTags.getInteger("speedMultiplier");
energyMultiplier = nbtTags.getInteger("energyMultiplier");
return upgrades.get(upgrade);
}
public void addUpgrade(Upgrade upgrade)
{
upgrades.put(upgrade, Math.min(upgrade.getMax(), upgrades.get(upgrade)+1));
}
public void setUpgrades(Upgrade upgrade, int amount)
{
upgrades.put(upgrade, amount);
if(upgrades.get(upgrade) == 0)
{
upgrades.remove(upgrade);
}
}
public void removeUpgrade(Upgrade upgrade)
{
upgrades.put(upgrade, Math.max(0, upgrades.get(upgrade)-1));
if(upgrades.get(upgrade) == 0)
{
upgrades.remove(upgrade);
}
}
public void setSupported(Upgrade upgrade)
{
supported.add(upgrade);
}
public boolean supports(Upgrade upgrade)
{
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)
{
speedMultiplier = dataStream.readInt();
energyMultiplier = dataStream.readInt();
upgrades.clear();
int amount = dataStream.readInt();
for(int i = 0; i < amount; i++)
{
upgrades.put(Upgrade.values()[dataStream.readInt()], dataStream.readInt());
}
upgradeTicks = dataStream.readInt();
}
@Override
public void write(ArrayList data)
{
data.add(upgrades.size());
for(Map.Entry<Upgrade, Integer> entry : upgrades.entrySet())
{
data.add(entry.getKey().ordinal());
data.add(entry.getValue());
}
data.add(upgradeTicks);
}
@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"));
}
}
@Override
public void write(NBTTagCompound nbtTags)
{
nbtTags.setInteger("speedMultiplier", speedMultiplier);
nbtTags.setInteger("energyMultiplier", energyMultiplier);
}
@Override
public void write(ArrayList data)
{
data.add(speedMultiplier);
data.add(energyMultiplier);
data.add(upgradeTicks);
NBTTagList list = new NBTTagList();
for(Upgrade upgrade : upgrades.keySet())
{
list.appendTag(getTagFor(upgrade));
}
nbtTags.setTag("upgrades", list);
}
}