Temporarily added back Modular Battery

This commit is contained in:
Calclavia 2013-12-23 17:56:25 +08:00
parent 2d8af00e89
commit 1818682c0a
10 changed files with 36 additions and 305 deletions

View file

@ -5,12 +5,10 @@ itemGroup.resonantinduction=Resonant Induction
## Blocks
tile.resonantinduction\:tesla.name=Tesla Coil
tile.resonantinduction\:contractor.name=Electromagnetic Contractor
tile.resonantinduction\:battery.name=Modular Battery
tile.resonantinduction\:battery.name=Battery
## Items
item.resonantinduction\:quantumEntangler.name=Quantum Entangler
item.resonantinduction\:capacitor.name=Capacitor Cell
item.resonantinduction\:infiniteCapacitor.name=Infinite Capacitor Cell
item.resonantinduction\:linker.name=Electrostatic Linker
item.resonantinduction\:multimeter.name=Multimeter

View file

@ -25,7 +25,7 @@ import resonantinduction.contractor.TileEntityEMContractor;
import resonantinduction.entangler.ItemLinker;
import resonantinduction.entangler.ItemQuantumEntangler;
import resonantinduction.furnace.BlockAdvancedFurnace;
import resonantinduction.furnace.TileEntityAdvancedFurnace;
import resonantinduction.furnace.TileAdvancedFurnace;
import resonantinduction.multimeter.ItemMultimeter;
import resonantinduction.tesla.BlockTesla;
import resonantinduction.tesla.TileEntityTesla;
@ -187,7 +187,7 @@ public class ResonantInduction
{
blockAdvancedFurnace = BlockAdvancedFurnace.createNew(false);
GameRegistry.registerBlock(blockAdvancedFurnace, "ri_" + blockAdvancedFurnace.getUnlocalizedName());
GameRegistry.registerTileEntity(TileEntityAdvancedFurnace.class, "ri_" + blockAdvancedFurnace.getUnlocalizedName());
GameRegistry.registerTileEntity(TileAdvancedFurnace.class, "ri_" + blockAdvancedFurnace.getUnlocalizedName());
}
CONFIGURATION.save();
@ -300,7 +300,7 @@ public class ResonantInduction
}
/** Inject new furnace tile class */
replaceTileEntity(TileEntityFurnace.class, TileEntityAdvancedFurnace.class);
replaceTileEntity(TileEntityFurnace.class, TileAdvancedFurnace.class);
}
public static void replaceTileEntity(Class<? extends TileEntity> findTile, Class<? extends TileEntity> replaceTile)

View file

@ -3,7 +3,7 @@ package resonantinduction.battery;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IElectricalItem;
import universalelectricity.api.item.IElectricalItem;
public class BatteryManager
{

View file

@ -1,43 +0,0 @@
/**
*
*/
package resonantinduction.battery;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import resonantinduction.ResonantInduction;
import resonantinduction.TabRI;
import resonantinduction.api.ICapacitor;
import universalelectricity.compatibility.ItemUniversalElectric;
/**
* Stores power.
*
* @author Calclavia
*
*/
public class ItemCapacitor extends ItemUniversalElectric implements ICapacitor
{
public ItemCapacitor(int id)
{
super(ResonantInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "capacitor", id).getInt(id));
this.setCreativeTab(TabRI.INSTANCE);
this.setUnlocalizedName(ResonantInduction.PREFIX + "capacitor");
this.setTextureName(ResonantInduction.PREFIX + "capacitor");
this.setMaxStackSize(1);
this.setMaxDamage(100);
}
@Override
public float getTransfer(ItemStack itemStack)
{
return this.getMaxEnergyStored(itemStack) * 0.05F;
}
@Override
public float getElectricityCapacity(ItemStack theItem)
{
return 500;
}
}

View file

@ -1,81 +0,0 @@
/**
*
*/
package resonantinduction.battery;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration;
import resonantinduction.ResonantInduction;
import resonantinduction.TabRI;
import universalelectricity.compatibility.ItemUniversalElectric;
/**
* Stores power.
*
* @author Calclavia
*
*/
public class ItemInfiniteCapacitor extends ItemUniversalElectric
{
public ItemInfiniteCapacitor(int id)
{
super(ResonantInduction.CONFIGURATION.get(Configuration.CATEGORY_ITEM, "infiniteCapacitor", id).getInt(id));
this.setCreativeTab(TabRI.INSTANCE);
this.setUnlocalizedName(ResonantInduction.PREFIX + "infiniteCapacitor");
this.setTextureName(ResonantInduction.PREFIX + "capacitor");
this.setMaxStackSize(1);
this.setMaxDamage(100);
}
@Override
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
{
list.add("Infinite");
}
@Override
public float recharge(ItemStack itemStack, float energy, boolean doReceive)
{
return energy;
}
@Override
public float discharge(ItemStack itemStack, float energy, boolean doTransfer)
{
return energy;
}
@Override
public void setElectricity(ItemStack itemStack, float joules)
{
}
@Override
public float getTransfer(ItemStack itemStack)
{
return Float.POSITIVE_INFINITY;
}
@Override
public float getElectricityStored(ItemStack itemStack)
{
return Float.POSITIVE_INFINITY;
}
@Override
public float getElectricityCapacity(ItemStack theItem)
{
return Float.POSITIVE_INFINITY;
}
@Override
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(this));
}
}

View file

@ -7,8 +7,8 @@ import java.util.Set;
import net.minecraft.item.ItemStack;
import resonantinduction.base.ListUtil;
import universalelectricity.api.item.IElectricalItem;
import universalelectricity.api.vector.Vector3;
import universalelectricity.core.item.IElectricalItem;
public class SynchronizedBatteryData
{

View file

@ -22,9 +22,8 @@ import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction;
import resonantinduction.api.ICapacitor;
import resonantinduction.base.ListUtil;
import universalelectricity.api.electricity.ElectricityPack;
import universalelectricity.api.item.IElectricalItem;
import universalelectricity.api.vector.Vector3;
import universalelectricity.core.item.IElectricalItem;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.IPacketSender;
import calclavia.lib.tile.TileEntityElectrical;
@ -37,14 +36,13 @@ import cpw.mods.fml.common.network.Player;
/**
* A modular battery with no GUI.
*
* @author AidanBrady
* @author Calclavia, AidanBrady
*/
public class TileEntityBattery extends TileEntityElectrical implements IPacketSender, IPacketReceiver, IInventory
{
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
public SynchronizedBatteryData prevStructure;
public float clientEnergy;
@ -81,7 +79,7 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
/**
* Attempt to charge entities above it.
*/
ItemStack chargeItem = null;
if (this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))
@ -102,7 +100,7 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
{
if (checkStack.getItem() instanceof IElectricalItem)
{
if (((IElectricalItem) checkStack.getItem()).recharge(checkStack, provideElectricity(this.getTransferThreshhold(), false).getWatts(), false) > 0)
if (((IElectricalItem) checkStack.getItem()).recharge(checkStack, this.energy.extractEnergy((this.getTransferThreshhold(), false).getWatts(), false) > 0)
{
chargeItem = checkStack;
break electricItemLoop;
@ -119,7 +117,7 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
{
if (checkStack.getItem() instanceof IElectricalItem)
{
if (((IElectricalItem) checkStack.getItem()).recharge(checkStack, provideElectricity(this.getTransferThreshhold(), false).getWatts(), false) > 0)
if (((IElectricalItem) checkStack.getItem()).recharge(checkStack, this.energy.extractEnergy((this.getTransferThreshhold(), false).getWatts(), false) > 0)
{
chargeItem = checkStack;
break electricItemLoop;
@ -141,9 +139,9 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
IElectricalItem battery = (IElectricalItem) itemStack.getItem();
float energyStored = getMaxEnergyStored();
float batteryNeeded = battery.recharge(itemStack, provideElectricity(this.getTransferThreshhold(), false).getWatts(), false);
float batteryNeeded = battery.recharge(itemStack, this.energy.extractEnergy((this.getTransferThreshhold(), false).getWatts(), false);
float toGive = Math.min(energyStored, Math.min(battery.getTransfer(itemStack), batteryNeeded));
battery.recharge(itemStack, provideElectricity(toGive, true).getWatts(), true);
battery.recharge(itemStack, this.energy.extractEnergy((toGive, true).getWatts(), true);
}
if (structure.visibleInventory[2] != null)
@ -155,7 +153,7 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
float batteryStored = battery.getElectricityStored(itemStack);
float toReceive = Math.min(energyNeeded, Math.min(this.getTransferThreshhold(), Math.min(battery.getTransfer(itemStack), batteryStored)));
battery.discharge(itemStack, receiveElectricity(toReceive, true), true);
}
}*/
if (prevStructure != structure)
{
@ -350,124 +348,6 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
}
}
@Override
public float receiveElectricity(ElectricityPack receive, boolean doAdd)
{
float amount = receive.getWatts();
float added = 0;
for (ItemStack itemStack : structure.inventory)
{
if (itemStack.getItem() instanceof IElectricalItem)
{
IElectricalItem battery = (IElectricalItem) itemStack.getItem();
float needed = amount - added;
float itemAdd = Math.min(battery.getElectricityCapacity(itemStack) - battery.getElectricityStored(itemStack), needed);
if (doAdd)
{
battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) + itemAdd);
}
added += itemAdd;
if (amount == added)
{
break;
}
}
}
return added;
}
@Override
public ElectricityPack provideElectricity(ElectricityPack pack, boolean doRemove)
{
float amount = pack.getWatts();
List<ItemStack> inverse = ListUtil.inverse(structure.inventory);
float removed = 0;
for (ItemStack itemStack : inverse)
{
if (itemStack.getItem() instanceof IElectricalItem)
{
IElectricalItem battery = (IElectricalItem) itemStack.getItem();
float needed = amount - removed;
float itemRemove = Math.min(battery.getElectricityStored(itemStack), needed);
if (doRemove)
{
battery.setElectricity(itemStack, battery.getElectricityStored(itemStack) - itemRemove);
}
removed += itemRemove;
if (amount == removed)
{
break;
}
}
}
return ElectricityPack.getFromWatts(removed, this.getVoltage());
}
@Override
public float getMaxEnergyStored()
{
if (!this.worldObj.isRemote)
{
float max = 0;
for (ItemStack itemStack : this.structure.inventory)
{
if (itemStack != null)
{
if (itemStack.getItem() instanceof IElectricalItem)
{
max += ((IElectricalItem) itemStack.getItem()).getElectricityCapacity(itemStack);
}
}
}
return max;
}
else
{
return this.clientMaxEnergy;
}
}
@Override
public float getEnergyStored()
{
if (!this.worldObj.isRemote)
{
float energy = 0;
for (ItemStack itemStack : this.structure.inventory)
{
if (itemStack != null)
{
if (itemStack.getItem() instanceof IElectricalItem)
{
energy += ((IElectricalItem) itemStack.getItem()).getElectricityStored(itemStack);
}
}
}
return energy;
}
else
{
return clientEnergy;
}
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player)
{
@ -488,9 +368,7 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
ArrayList data = new ArrayList();
data.add(structure.isMultiblock);
data.add(getEnergyStored());
data.add(structure.inventory.size());
data.add(getMaxEnergyStored());
data.add(structure.height);
data.add(structure.length);
@ -640,27 +518,6 @@ public class TileEntityBattery extends TileEntityElectrical implements IPacketSe
return itemsSack.getItem() instanceof IElectricalItem;
}
@Override
public float getRequest(ForgeDirection direction)
{
if (this.getInputDirections().contains(direction))
{
return Math.min(this.getMaxEnergyStored() - this.getEnergyStored(), this.getTransferThreshhold());
}
return 0;
}
@Override
public float getProvide(ForgeDirection direction)
{
if (this.getOutputDirections().contains(direction))
{
return Math.min(this.getEnergyStored(), this.getTransferThreshhold());
}
return 0;
}
@Override
public EnumSet<ForgeDirection> getInputDirections()
{

View file

@ -70,10 +70,10 @@ public class BlockAdvancedFurnace extends BlockFurnace
@Override
public Icon getBlockTexture(IBlockAccess access, int x, int y, int z, int side)
{
TileEntity tileEntity = (TileEntityAdvancedFurnace) access.getBlockTileEntity(x, y, z);
TileEntity tileEntity = (TileAdvancedFurnace) access.getBlockTileEntity(x, y, z);
int meta = access.getBlockMetadata(x, y, z);
if (((TileEntityAdvancedFurnace) tileEntity).isBurning())
if (((TileAdvancedFurnace) tileEntity).isBurning())
{
return side == 1 ? this.furnaceIconTop : (side == 0 ? this.furnaceIconTop : (side != meta ? this.blockIcon : this.furnaceIconFrontBurn));
}
@ -92,9 +92,9 @@ public class BlockAdvancedFurnace extends BlockFurnace
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random par5Random)
{
TileEntity tileEntity = (TileEntityAdvancedFurnace) world.getBlockTileEntity(x, y, z);
TileEntity tileEntity = (TileAdvancedFurnace) world.getBlockTileEntity(x, y, z);
if (((TileEntityAdvancedFurnace) tileEntity).isBurning())
if (((TileAdvancedFurnace) tileEntity).isBurning())
{
int l = world.getBlockMetadata(x, y, z);
float f = (float) x + 0.5F;
@ -129,6 +129,6 @@ public class BlockAdvancedFurnace extends BlockFurnace
@Override
public TileEntity createNewTileEntity(World par1World)
{
return new TileEntityAdvancedFurnace();
return new TileAdvancedFurnace();
}
}

View file

@ -17,7 +17,7 @@ import calclavia.lib.tile.EnergyStorage;
* @author Calclavia
*
*/
public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEnergyInterface
public class TileAdvancedFurnace extends TileEntityFurnace implements IEnergyInterface
{
private static final float WATTAGE = 5;

View file

@ -77,7 +77,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
public TileEntityTesla()
{
this.energyStorage = new EnergyStorage(TRANSFER_CAP);
this.energy = new EnergyStorage(TRANSFER_CAP);
}
@Override
@ -92,7 +92,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
{
super.updateEntity();
boolean doPacketUpdate = this.energyStorage.getEnergy() > 0;
boolean doPacketUpdate = this.energy.getEnergy() > 0;
/**
* Only transfer if it is the bottom controlling Tesla tower.
@ -101,7 +101,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
{
// this.produce();
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && this.doTransfer) || (this.energyStorage.getEnergy() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))))
if (this.ticks % (5 + this.worldObj.rand.nextInt(2)) == 0 && ((this.worldObj.isRemote && this.doTransfer) || (this.energy.getEnergy() > 0 && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord))))
{
final TileEntityTesla topTesla = this.getTopTelsa();
final Vector3 topTeslaVector = new Vector3(topTesla);
@ -121,11 +121,11 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
if (transferTile instanceof TileEntityTesla && !transferTile.isInvalid())
{
this.transfer(((TileEntityTesla) transferTile), Math.min(this.energyStorage.getEmptySpace(), TRANSFER_CAP));
this.transfer(((TileEntityTesla) transferTile), Math.min(this.energy.getEmptySpace(), TRANSFER_CAP));
if (this.zapCounter % 5 == 0 && ResonantInduction.SOUND_FXS)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "electricshock", this.energyStorage.getEnergy() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "electricshock", this.energy.getEnergy() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
}
}
}
@ -195,14 +195,14 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
if (transferTeslaCoils.size() > 0)
{
long transferEnergy = this.energyStorage.getEnergy() / transferTeslaCoils.size();
long transferEnergy = this.energy.getEnergy() / transferTeslaCoils.size();
int count = 0;
boolean sentPacket = false;
for (ITesla tesla : transferTeslaCoils)
{
if (this.zapCounter % 5 == 0 && ResonantInduction.SOUND_FXS)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "electricshock", this.energyStorage.getEnergy() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, ResonantInduction.PREFIX + "electricshock", this.energy.getEnergy() / 25, 1.3f - 0.5f * (this.dyeID / 16f));
}
Vector3 targetVector = new Vector3((TileEntity) tesla);
@ -251,7 +251,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
this.doTransfer = false;
}
if (!this.worldObj.isRemote && this.energyStorage.getEnergy() > 0 != doPacketUpdate)
if (!this.worldObj.isRemote && this.energy.getEnergy() > 0 != doPacketUpdate)
{
this.sendPacket(2);
}
@ -296,7 +296,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
{
case 1:
{
data.add(this.energyStorage.getEnergy());
data.add(this.energy.getEnergy());
data.add(this.dyeID);
data.add(this.canReceive);
data.add(this.attackEntities);
@ -305,7 +305,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
}
case 2:
{
data.add(this.energyStorage.getEnergy());
data.add(this.energy.getEnergy());
}
}
@ -331,14 +331,14 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
switch (data.readByte())
{
case 1:
this.energyStorage.setEnergy(data.readLong());
this.energy.setEnergy(data.readLong());
this.dyeID = data.readInt();
this.canReceive = data.readBoolean();
this.attackEntities = data.readBoolean();
this.isLinkedClient = data.readBoolean();
break;
case 2:
this.energyStorage.setEnergy(data.readLong());
this.energy.setEnergy(data.readLong());
break;
case 3:
this.doTransfer = true;
@ -368,7 +368,7 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
{
if (doTransfer)
{
this.energyStorage.receiveEnergy(transferEnergy, true);
this.energy.receiveEnergy(transferEnergy, true);
}
this.sendPacket(2);
@ -376,10 +376,10 @@ public class TileEntityTesla extends TileEntityElectrical implements ITesla, IPa
}
else
{
if (this.energyStorage.getEnergy() > 0)
if (this.energy.getEnergy() > 0)
{
transferEnergy += this.energyStorage.getEnergy();
this.energyStorage.setEnergy(0);
transferEnergy += this.energy.getEnergy();
this.energy.setEnergy(0);
}
return this.getControllingTelsa().teslaTransfer(transferEnergy, doTransfer);