Worked on some battery distribution
This commit is contained in:
parent
833fab1301
commit
dee14031be
5 changed files with 37 additions and 32 deletions
|
@ -14,6 +14,7 @@ import resonantinduction.core.Reference;
|
|||
import resonantinduction.core.Settings;
|
||||
import resonantinduction.core.prefab.block.BlockIOBase;
|
||||
import resonantinduction.core.render.RIBlockRenderingHandler;
|
||||
import resonantinduction.electrical.Electrical;
|
||||
import universalelectricity.api.CompatibilityModule;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -32,6 +33,29 @@ public class BlockBattery extends BlockIOBase implements ITileEntityProvider
|
|||
this.setTextureName(Reference.PREFIX + "machine");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World world, int x, int y, int z)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
battery.updateStructure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack)
|
||||
{
|
||||
if (!world.isRemote && itemstack.getItem() instanceof ItemBlockBattery)
|
||||
{
|
||||
ItemBlockBattery itemBlock = (ItemBlockBattery) itemstack.getItem();
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
battery.energy.setCapacity(TileBattery.getEnergyForTier(itemBlock.getTier(itemstack)));
|
||||
battery.energy.setEnergy(itemBlock.getEnergy(itemstack));
|
||||
battery.updateStructure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
|
||||
{
|
||||
|
@ -45,16 +69,6 @@ public class BlockBattery extends BlockIOBase implements ITileEntityProvider
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
TileBattery battery = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
battery.updateStructure();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderAsNormalBlock()
|
||||
{
|
||||
|
|
|
@ -53,20 +53,6 @@ public class ItemBlockBattery extends ItemBlock implements IEnergyItem, IVoltage
|
|||
list.add(LanguageUtility.getLocal("tooltip.battery.energy").replace("%0", color).replace("%1", EnumColor.GREY.toString()).replace("%v0", UnitDisplay.getDisplayShort(joules, Unit.JOULES)).replace("%v1", UnitDisplay.getDisplayShort(this.getEnergyCapacity(itemStack), Unit.JOULES)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
||||
{
|
||||
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, getTier(stack));
|
||||
|
||||
if (place)
|
||||
{
|
||||
TileBattery tileEntity = (TileBattery) world.getBlockTileEntity(x, y, z);
|
||||
tileEntity.setEnergy(null, this.getEnergy(stack));
|
||||
}
|
||||
|
||||
return place;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the item is uncharged when it is crafted and not charged. Change this if you do
|
||||
* not want this to happen!
|
||||
|
|
|
@ -68,7 +68,8 @@ public class RenderBattery extends TileEntitySpecialRenderer
|
|||
{
|
||||
TileBattery tile = (TileBattery) t;
|
||||
|
||||
RenderUtility.bind(Reference.DOMAIN, Reference.MODEL_PATH + "battery/bat_level_" + (int) (((double) tile.energy.getEnergy() / (double) tile.energy.getEnergyCapacity()) * 10) + ".png");
|
||||
int energyLevel = (int) (((double) tile.energy.getEnergy() / (double) TileBattery.getEnergyForTier(tile.getBlockMetadata())) * 10);
|
||||
RenderUtility.bind(Reference.DOMAIN, Reference.MODEL_PATH + "battery/bat_level_" + energyLevel + ".png");
|
||||
MODEL.renderPart("Battery");
|
||||
|
||||
// Render top and bottom
|
||||
|
|
|
@ -29,7 +29,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
public class TileBattery extends TileElectrical implements IConnector<BatteryNetwork>, IVoltageInput, IVoltageOutput, IPacketSender, IPacketReceiver, IEnergyInterface, IEnergyContainer
|
||||
{
|
||||
/** The transfer rate **/
|
||||
public static final long DEFAULT_WATTAGE = getEnergyForTier(1);
|
||||
public static final long DEFAULT_WATTAGE = getEnergyForTier(0);
|
||||
|
||||
/** Voltage increases as series connection increases */
|
||||
public static final long DEFAULT_VOLTAGE = UniversalElectricity.DEFAULT_VOLTAGE;
|
||||
|
@ -40,7 +40,7 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryNet
|
|||
|
||||
public TileBattery()
|
||||
{
|
||||
this.energy = new EnergyStorageHandler(getEnergyForTier(1));
|
||||
this.energy = new EnergyStorageHandler(0);
|
||||
this.saveIOMap = true;
|
||||
}
|
||||
|
||||
|
@ -57,13 +57,13 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryNet
|
|||
public void initiate()
|
||||
{
|
||||
this.updateStructure();
|
||||
energy.setCapacity(getEnergyForTier(getBlockMetadata()));
|
||||
}
|
||||
|
||||
public void updateStructure()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
energy.setCapacity(getEnergyForTier(getBlockMetadata()));
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).translate(dir).getTileEntity(this.worldObj);
|
||||
|
@ -103,7 +103,8 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryNet
|
|||
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
|
||||
{
|
||||
long returnValue = super.onReceiveEnergy(from, receive, doReceive);
|
||||
this.getNetwork().redistribute();
|
||||
if (ticks % 5 == 0)
|
||||
this.getNetwork().redistribute();
|
||||
markUpdate = true;
|
||||
return returnValue;
|
||||
}
|
||||
|
@ -112,7 +113,8 @@ public class TileBattery extends TileElectrical implements IConnector<BatteryNet
|
|||
public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract)
|
||||
{
|
||||
long returnValue = super.onExtractEnergy(from, extract, doExtract);
|
||||
this.getNetwork().redistribute();
|
||||
if (ticks % 5 == 0)
|
||||
this.getNetwork().redistribute();
|
||||
markUpdate = true;
|
||||
return returnValue;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.network.packet.Packet;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.api.net.IConnector;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.network.IPacketReceiver;
|
||||
import calclavia.lib.network.PacketType;
|
||||
|
||||
|
@ -52,12 +53,13 @@ public class PacketNetwork<C extends IConnector> extends PacketType
|
|||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
TileEntity tileEntity = player.worldObj.getBlockTileEntity(x, y, z);
|
||||
|
||||
System.out.println(tileEntity+" rec: "+new Vector3(x,y,z));
|
||||
//TODO: Somehow this would receive the wrong coordinate once in a while...
|
||||
if (tileEntity != null && connectorClass.isAssignableFrom(tileEntity.getClass()))
|
||||
{
|
||||
C instance = (C) ((C) tileEntity).getInstance(ForgeDirection.getOrientation(data.readInt()));
|
||||
Object network = instance.getNetwork();
|
||||
|
||||
|
||||
if (network instanceof IPacketReceiver)
|
||||
{
|
||||
((IPacketReceiver) network).onReceivePacket(data, player, instance);
|
||||
|
|
Loading…
Reference in a new issue