Added efficiency upgrades to the Subspace capacitors
This commit is contained in:
parent
4d8ccf7df2
commit
4b5093f4d9
3 changed files with 139 additions and 14 deletions
|
@ -3,10 +3,13 @@ package cr0s.warpdrive.block.energy;
|
|||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.EnumComponentType;
|
||||
import cr0s.warpdrive.item.ItemComponent;
|
||||
import cr0s.warpdrive.item.ItemTuningFork;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -61,25 +64,34 @@ public class BlockEnergyBank extends BlockAbstractContainer {
|
|||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister iconRegister) {
|
||||
icons = new IIcon[3];
|
||||
icons[0] = iconRegister.registerIcon("warpdrive:energy/energyBank");
|
||||
icons[1] = iconRegister.registerIcon("warpdrive:energy/energyBankInput");
|
||||
icons[2] = iconRegister.registerIcon("warpdrive:energy/energyBankOutput");
|
||||
icons = new IIcon[12];
|
||||
icons[ 0] = iconRegister.registerIcon("warpdrive:energy/energyBankCreativeDisabled");
|
||||
icons[ 1] = iconRegister.registerIcon("warpdrive:energy/energyBankCreativeInput");
|
||||
icons[ 2] = iconRegister.registerIcon("warpdrive:energy/energyBankCreativeOutput");
|
||||
icons[ 3] = iconRegister.registerIcon("warpdrive:energy/energyBankBasicDisabled");
|
||||
icons[ 4] = iconRegister.registerIcon("warpdrive:energy/energyBankBasicInput");
|
||||
icons[ 5] = iconRegister.registerIcon("warpdrive:energy/energyBankBasicOutput");
|
||||
icons[ 6] = iconRegister.registerIcon("warpdrive:energy/energyBankAdvancedDisabled");
|
||||
icons[ 7] = iconRegister.registerIcon("warpdrive:energy/energyBankAdvancedInput");
|
||||
icons[ 8] = iconRegister.registerIcon("warpdrive:energy/energyBankAdvancedOutput");
|
||||
icons[ 9] = iconRegister.registerIcon("warpdrive:energy/energyBankSuperiorDisabled");
|
||||
icons[10] = iconRegister.registerIcon("warpdrive:energy/energyBankSuperiorInput");
|
||||
icons[11] = iconRegister.registerIcon("warpdrive:energy/energyBankSuperiorOutput");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity == null || !(tileEntity instanceof TileEntityEnergyBank)) {
|
||||
return icons[0];
|
||||
return icons[3];
|
||||
}
|
||||
|
||||
return icons[((TileEntityEnergyBank) tileEntity).getMode(EnumFacing.getFront(side))];
|
||||
return icons[3 * ((TileEntityEnergyBank) tileEntity).getTier() + ((TileEntityEnergyBank) tileEntity).getMode(EnumFacing.getFront(side))];
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int side, int metadata) {
|
||||
return icons[side == 1 ? 1 : 2];
|
||||
return icons[metadata * 3 + (side == 1 ? 1 : 2)];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,12 +121,12 @@ public class BlockEnergyBank extends BlockAbstractContainer {
|
|||
ItemStack itemStackHeld = entityPlayer.getHeldItem();
|
||||
EnumFacing facing = EnumFacing.getFront(side);
|
||||
|
||||
if (itemStackHeld == null) {
|
||||
WarpDrive.addChatMessage(entityPlayer, tileEntityEnergyBank.getStatus());
|
||||
return true;
|
||||
|
||||
} else if (itemStackHeld.getItem() instanceof ItemTuningFork) {
|
||||
tileEntityEnergyBank.setMode(facing, (byte)((tileEntityEnergyBank.getMode(facing) + 1) % 3));
|
||||
if (itemStackHeld != null && itemStackHeld.getItem() instanceof ItemTuningFork) {
|
||||
if (entityPlayer.isSneaking()) {
|
||||
tileEntityEnergyBank.setMode(facing, (byte)((tileEntityEnergyBank.getMode(facing) + 2) % 3));
|
||||
} else {
|
||||
tileEntityEnergyBank.setMode(facing, (byte)((tileEntityEnergyBank.getMode(facing) + 1) % 3));
|
||||
}
|
||||
ItemStack itemStack = new ItemStack(Item.getItemFromBlock(this), 1, world.getBlockMetadata(x, y, z));
|
||||
switch (tileEntityEnergyBank.getMode(facing)) {
|
||||
case TileEntityEnergyBank.MODE_INPUT:
|
||||
|
@ -136,6 +148,77 @@ public class BlockEnergyBank extends BlockAbstractContainer {
|
|||
}
|
||||
}
|
||||
|
||||
EnumComponentType enumComponentType = null;
|
||||
if (itemStackHeld != null && itemStackHeld.getItem() instanceof ItemComponent) {
|
||||
enumComponentType = EnumComponentType.get(itemStackHeld.getItemDamage());
|
||||
}
|
||||
|
||||
// sneaking with an empty hand or an upgrade item in hand to dismount current upgrade
|
||||
if (entityPlayer.isSneaking()) {
|
||||
// using an upgrade item or an empty means dismount upgrade
|
||||
if (itemStackHeld == null || enumComponentType != null) {
|
||||
// find a valid upgrade to dismount
|
||||
if (itemStackHeld == null || !tileEntityEnergyBank.hasUpgrade(enumComponentType)) {
|
||||
enumComponentType = (EnumComponentType)tileEntityEnergyBank.getFirstUpgradeOfType(EnumComponentType.class, null);
|
||||
}
|
||||
|
||||
if (enumComponentType == null) {
|
||||
// no more upgrades to dismount
|
||||
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.upgrade.result.noUpgradeToDismount"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!entityPlayer.capabilities.isCreativeMode) {
|
||||
// dismount the current upgrade item
|
||||
ItemStack itemStackDrop = ItemComponent.getItemStackNoCache(enumComponentType, 1);
|
||||
EntityItem entityItem = new EntityItem(world, entityPlayer.posX, entityPlayer.posY + 0.5D, entityPlayer.posZ, itemStackDrop);
|
||||
entityItem.delayBeforeCanPickup = 0;
|
||||
world.spawnEntityInWorld(entityItem);
|
||||
}
|
||||
|
||||
tileEntityEnergyBank.dismountUpgrade(enumComponentType);
|
||||
// upgrade dismounted
|
||||
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.upgrade.result.dismounted", enumComponentType.name()));
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
} else if (itemStackHeld == null) {// no sneaking and no item in hand => show status
|
||||
WarpDrive.addChatMessage(entityPlayer, tileEntityEnergyBank.getStatus());
|
||||
return true;
|
||||
|
||||
} else if (enumComponentType != null) {// no sneaking and an upgrade in hand => mounting an upgrade
|
||||
// validate type
|
||||
if (tileEntityEnergyBank.getUpgradeMaxCount(enumComponentType) <= 0) {
|
||||
// invalid upgrade type
|
||||
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.upgrade.result.invalidUpgrade"));
|
||||
return true;
|
||||
}
|
||||
if (!tileEntityEnergyBank.canUpgrade(enumComponentType)) {
|
||||
// too many upgrades
|
||||
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.upgrade.result.tooManyUpgrades",
|
||||
tileEntityEnergyBank.getUpgradeMaxCount(enumComponentType)));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!entityPlayer.capabilities.isCreativeMode) {
|
||||
// validate quantity
|
||||
if (itemStackHeld.stackSize < 1) {
|
||||
// not enough upgrade items
|
||||
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.upgrade.result.notEnoughUpgrades"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// update player inventory
|
||||
itemStackHeld.stackSize -= 1;
|
||||
}
|
||||
|
||||
// mount the new upgrade item
|
||||
tileEntityEnergyBank.mountUpgrade(enumComponentType);
|
||||
// upgrade mounted
|
||||
WarpDrive.addChatMessage(entityPlayer, StatCollector.translateToLocalFormatted("warpdrive.upgrade.result.mounted", enumComponentType.name()));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package cr0s.warpdrive.block.energy;
|
||||
|
||||
import cr0s.warpdrive.data.EnumComponentType;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
|
@ -28,6 +29,8 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
|
|||
super();
|
||||
this.tier = tier;
|
||||
peripheralName = "warpdriveEnergyBank";
|
||||
|
||||
setUpgradeMaxCount(EnumComponentType.SUPERCONDUCTOR, WarpDriveConfig.ENERGY_BANK_EFFICIENCY_PER_UPGRADE.length - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -42,6 +45,11 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
|
|||
super.onFirstUpdateTick();
|
||||
}
|
||||
|
||||
private double getEfficiency() {
|
||||
int upgradeCount = clamp(0, getUpgradeMaxCount(EnumComponentType.SUPERCONDUCTOR), getUpgradeCount(EnumComponentType.SUPERCONDUCTOR));
|
||||
return WarpDriveConfig.ENERGY_BANK_EFFICIENCY_PER_UPGRADE[upgradeCount];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int energy_getEnergyStored() {
|
||||
if (tier == 0) {
|
||||
|
@ -56,7 +64,7 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
|
|||
if (tier == 0) {
|
||||
return Integer.MAX_VALUE;
|
||||
} else {
|
||||
return Math.min(energy_getEnergyStored(), WarpDriveConfig.ENERGY_BANK_TRANSFER_PER_TICK[tier - 1]);
|
||||
return (int) Math.round(Math.min(energy_getEnergyStored() * getEfficiency(), WarpDriveConfig.ENERGY_BANK_TRANSFER_PER_TICK[tier - 1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,6 +77,23 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean energy_consume(final int amount_internal, final boolean simulate) {
|
||||
int amountWithLoss = (int) Math.round(amount_internal / getEfficiency());
|
||||
if (energy_getEnergyStored() >= amountWithLoss) {
|
||||
if (!simulate) {
|
||||
super.energy_consume(amountWithLoss);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void energy_consume(final int amount_internal) {
|
||||
int amountWithLoss = (int) Math.round(amount_internal > 0 ? amount_internal / getEfficiency() : amount_internal * getEfficiency());
|
||||
super.energy_consume(amountWithLoss);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean energy_canInput(ForgeDirection from) {
|
||||
return modeSide[from.ordinal()] == MODE_INPUT;
|
||||
|
@ -79,6 +104,10 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
|
|||
return modeSide[to.ordinal()] == MODE_OUTPUT;
|
||||
}
|
||||
|
||||
byte getTier() {
|
||||
return tier;
|
||||
}
|
||||
|
||||
byte getMode(final EnumFacing facing) {
|
||||
return modeSide[facing.ordinal()];
|
||||
}
|
||||
|
@ -89,6 +118,12 @@ public class TileEntityEnergyBank extends TileEntityAbstractEnergy {
|
|||
energy_resetConnections(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return super.getStatus()
|
||||
+ "\n" + getUpgradeStatus();
|
||||
}
|
||||
|
||||
// Forge overrides
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbtTagCompound) {
|
||||
|
|
|
@ -281,6 +281,7 @@ public class WarpDriveConfig {
|
|||
public static int[] ENERGY_BANK_MAX_ENERGY_STORED = { 800000, 4000000, 20000000 };
|
||||
public static int[] ENERGY_BANK_IC2_TIER = { 2, 3, 4 };
|
||||
public static int[] ENERGY_BANK_TRANSFER_PER_TICK = { 200, 1000, 5000 };
|
||||
public static double[] ENERGY_BANK_EFFICIENCY_PER_UPGRADE = { 0.95D, 0.98D, 1.0D };
|
||||
|
||||
// Laser lift
|
||||
public static int LIFT_MAX_ENERGY_STORED = 900;
|
||||
|
@ -739,6 +740,12 @@ public class WarpDriveConfig {
|
|||
ENERGY_BANK_TRANSFER_PER_TICK[1] = clamp(ENERGY_BANK_TRANSFER_PER_TICK[0], ENERGY_BANK_TRANSFER_PER_TICK[2], ENERGY_BANK_TRANSFER_PER_TICK[1]);
|
||||
ENERGY_BANK_TRANSFER_PER_TICK[2] = clamp(ENERGY_BANK_TRANSFER_PER_TICK[1], Integer.MAX_VALUE , ENERGY_BANK_TRANSFER_PER_TICK[2]);
|
||||
|
||||
ENERGY_BANK_EFFICIENCY_PER_UPGRADE = config.get("energy_bank", "efficiency_per_upgrade", ENERGY_BANK_EFFICIENCY_PER_UPGRADE, "Energy transfer efficiency for each upgrade apply, first value is without upgrades (0.8 means 20% loss)").getDoubleList();
|
||||
assert(ENERGY_BANK_EFFICIENCY_PER_UPGRADE.length >= 1);
|
||||
ENERGY_BANK_EFFICIENCY_PER_UPGRADE[0] = Math.min(1.0D, clamp( 0.5D, ENERGY_BANK_EFFICIENCY_PER_UPGRADE[1], ENERGY_BANK_EFFICIENCY_PER_UPGRADE[0]));
|
||||
ENERGY_BANK_EFFICIENCY_PER_UPGRADE[1] = Math.min(1.0D, clamp(ENERGY_BANK_EFFICIENCY_PER_UPGRADE[0], ENERGY_BANK_EFFICIENCY_PER_UPGRADE[2], ENERGY_BANK_EFFICIENCY_PER_UPGRADE[1]));
|
||||
ENERGY_BANK_EFFICIENCY_PER_UPGRADE[2] = Math.min(1.0D, clamp(ENERGY_BANK_EFFICIENCY_PER_UPGRADE[1], Integer.MAX_VALUE , ENERGY_BANK_EFFICIENCY_PER_UPGRADE[2]));
|
||||
|
||||
// Lift
|
||||
LIFT_MAX_ENERGY_STORED = clamp(1, Integer.MAX_VALUE,
|
||||
config.get("lift", "max_energy_stored", LIFT_MAX_ENERGY_STORED, "Maximum energy stored").getInt());
|
||||
|
|
Loading…
Add table
Reference in a new issue