Generalise the EnergyMeter. The name may not be entirely accurate any more.

This commit is contained in:
Ben Spiers 2013-08-23 19:23:08 +01:00
parent 2045c26c7d
commit 6cf89af4b2
12 changed files with 172 additions and 10 deletions

View file

@ -77,6 +77,12 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
return transmitters.size(); return transmitters.size();
} }
@Override
public int getAcceptorSize()
{
return possibleAcceptors.size();
}
@Override @Override
public void tick() public void tick()
{ {

View file

@ -263,4 +263,16 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
{ {
return TransmissionType.GAS; return TransmissionType.GAS;
} }
@Override
public String getNeeded()
{
return "Undefined for Gas networks.";
}
@Override
public String getFlow()
{
return "Not defined yet for Fluid networks";
}
} }

View file

@ -49,4 +49,12 @@ public interface ITransmitter<N>
public void fixNetwork(); public void fixNetwork();
public boolean areNetworksEqual(TileEntity tileEntity); public boolean areNetworksEqual(TileEntity tileEntity);
public int getNetworkSize();
public int getNetworkAcceptorSize();
public String getNetworkNeeded();
public String getNetworkFlow();
} }

View file

@ -8,6 +8,12 @@ public interface ITransmitterNetwork<A, N>
public int getSize(); public int getSize();
public int getAcceptorSize();
public String getNeeded();
public String getFlow();
public Set<A> getAcceptors(Object... data); public Set<A> getAcceptors(Object... data);
public void removeTransmitter(ITransmitter<N> transmitter); public void removeTransmitter(ITransmitter<N> transmitter);

View file

@ -21,6 +21,7 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event; import net.minecraftforge.event.Event;
import universalelectricity.core.block.IElectrical; import universalelectricity.core.block.IElectrical;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.electricity.ElectricityPack;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler.PowerReceiver; import buildcraft.api.power.PowerHandler.PowerReceiver;
@ -60,7 +61,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
register(); register();
} }
public double getEnergyNeeded(ArrayList<TileEntity> ignored) public double getEnergyNeeded(List<TileEntity> ignored)
{ {
double totalNeeded = 0; double totalNeeded = 0;
@ -427,4 +428,16 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
{ {
return TransmissionType.ENERGY; return TransmissionType.ENERGY;
} }
@Override
public String getNeeded()
{
return ElectricityDisplay.getDisplay((float) (getEnergyNeeded(new ArrayList<TileEntity>())*Mekanism.TO_UE), ElectricityDisplay.ElectricUnit.JOULES);
}
@Override
public String getFlow()
{
return ElectricityDisplay.getDisplay((float) (getPower()*Mekanism.TO_UE), ElectricityDisplay.ElectricUnit.WATT);
}
} }

View file

@ -267,4 +267,16 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
{ {
return TransmissionType.FLUID; return TransmissionType.FLUID;
} }
@Override
public String getNeeded()
{
return "Undefined for Fluid networks";
}
@Override
public String getFlow()
{
return "Not defined yet for Fluid networks";
}
} }

View file

@ -196,4 +196,16 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
{ {
return TransmissionType.ITEM; return TransmissionType.ITEM;
} }
@Override
public String getFlow()
{
return "Undefined for Inventory networks";
}
@Override
public String getNeeded()
{
return "Undefined for Inventory Networks";
}
} }

View file

@ -5,14 +5,11 @@ import java.util.ArrayList;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.ITransmitter; import mekanism.api.ITransmitter;
import mekanism.api.TransmitterNetworkRegistry; import mekanism.api.TransmitterNetworkRegistry;
import mekanism.api.TransmissionType;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.World; import net.minecraft.world.World;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
public class ItemEnergyMeter extends ItemEnergized public class ItemEnergyMeter extends ItemEnergized
{ {
@ -30,19 +27,19 @@ public class ItemEnergyMeter extends ItemEnergized
{ {
TileEntity tileEntity = world.getBlockTileEntity(x, y, z); TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(MekanismUtils.checkTransmissionType(tileEntity, TransmissionType.ENERGY)) if(tileEntity instanceof ITransmitter)
{ {
if(getEnergy(stack) >= ENERGY_PER_USE) if(getEnergy(stack) >= ENERGY_PER_USE)
{ {
setEnergy(stack, getEnergy(stack)-ENERGY_PER_USE); setEnergy(stack, getEnergy(stack)-ENERGY_PER_USE);
ITransmitter<EnergyNetwork> cable = (ITransmitter<EnergyNetwork>)tileEntity; ITransmitter cable = (ITransmitter)tileEntity;
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " -------------")); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " -------------"));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Cables: " + EnumColor.DARK_GREY + cable.getNetwork().transmitters.size())); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Cables: " + EnumColor.DARK_GREY + cable.getNetworkSize()));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Acceptors: " + EnumColor.DARK_GREY + cable.getNetwork().possibleAcceptors.size())); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Acceptors: " + EnumColor.DARK_GREY + cable.getNetworkAcceptorSize()));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Needed energy: " + EnumColor.DARK_GREY + ElectricityDisplay.getDisplay((float)(cable.getNetwork().getEnergyNeeded(new ArrayList())*Mekanism.TO_UE), ElectricUnit.JOULES))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Needed energy: " + EnumColor.DARK_GREY + cable.getNetworkNeeded()));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Power: " + EnumColor.DARK_GREY + ElectricityDisplay.getDisplay((float)(cable.getNetwork().getPower()*Mekanism.TO_UE), ElectricUnit.WATT))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Power: " + EnumColor.DARK_GREY + cable.getNetworkFlow() ));
player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------")); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------"));
} }
} }

View file

@ -161,4 +161,28 @@ public class TileEntityLogisticalTransporter extends TileEntityTransmitter<Inven
{ {
return INFINITE_EXTENT_AABB; return INFINITE_EXTENT_AABB;
} }
@Override
public int getNetworkSize()
{
return getNetwork().getSize();
}
@Override
public int getNetworkAcceptorSize()
{
return getNetwork().getAcceptorSize();
}
@Override
public String getNetworkNeeded()
{
return getNetwork().getNeeded();
}
@Override
public String getNetworkFlow()
{
return getNetwork().getFlow();
}
} }

View file

@ -266,4 +266,28 @@ public class TileEntityMechanicalPipe extends TileEntityTransmitter<FluidNetwork
{ {
return new FluidTankInfo[] {dummyTank.getInfo()}; return new FluidTankInfo[] {dummyTank.getInfo()};
} }
@Override
public int getNetworkSize()
{
return getNetwork().getSize();
}
@Override
public int getNetworkAcceptorSize()
{
return getNetwork().getAcceptorSize();
}
@Override
public String getNetworkNeeded()
{
return getNetwork().getNeeded();
}
@Override
public String getNetworkFlow()
{
return getNetwork().getFlow();
}
} }

View file

@ -129,4 +129,28 @@ public class TileEntityPressurizedTube extends TileEntityTransmitter<GasNetwork>
{ {
return false; return false;
} }
@Override
public int getNetworkSize()
{
return getNetwork().getSize();
}
@Override
public int getNetworkAcceptorSize()
{
return getNetwork().getAcceptorSize();
}
@Override
public String getNetworkNeeded()
{
return getNetwork().getNeeded();
}
@Override
public String getNetworkFlow()
{
return getNetwork().getFlow();
}
} }

View file

@ -170,4 +170,28 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
{ {
return 2048; return 2048;
} }
@Override
public int getNetworkSize()
{
return getNetwork().getSize();
}
@Override
public int getNetworkAcceptorSize()
{
return getNetwork().getAcceptorSize();
}
@Override
public String getNetworkNeeded()
{
return getNetwork().getNeeded();
}
@Override
public String getNetworkFlow()
{
return getNetwork().getFlow();
}
} }