Fixed build
This commit is contained in:
parent
9c0358b38e
commit
449822fef2
7 changed files with 5 additions and 570 deletions
|
@ -1,7 +1,6 @@
|
|||
package mekanism.induction.client;
|
||||
|
||||
import mekanism.induction.client.gui.GuiBattery;
|
||||
import mekanism.induction.client.gui.GuiMultimeter;
|
||||
import mekanism.induction.client.render.BlockRenderingHandler;
|
||||
import mekanism.induction.client.render.RenderBattery;
|
||||
import mekanism.induction.client.render.RenderEMContractor;
|
||||
|
@ -9,7 +8,6 @@ import mekanism.induction.client.render.RenderTesla;
|
|||
import mekanism.induction.common.InductionCommonProxy;
|
||||
import mekanism.induction.common.tileentity.TileEntityBattery;
|
||||
import mekanism.induction.common.tileentity.TileEntityEMContractor;
|
||||
import mekanism.induction.common.tileentity.TileEntityMultimeter;
|
||||
import mekanism.induction.common.tileentity.TileEntityTesla;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -45,11 +43,7 @@ public class InductionClientProxy extends InductionCommonProxy
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if(tileEntity instanceof TileEntityMultimeter)
|
||||
{
|
||||
return new GuiMultimeter(player.inventory, ((TileEntityMultimeter) tileEntity));
|
||||
}
|
||||
else if(tileEntity instanceof TileEntityBattery)
|
||||
if(tileEntity instanceof TileEntityBattery)
|
||||
{
|
||||
return new GuiBattery(player.inventory, ((TileEntityBattery) tileEntity));
|
||||
}
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package mekanism.induction.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketTileEntity;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.induction.common.inventory.container.ContainerMultimeter;
|
||||
import mekanism.induction.common.tileentity.TileEntityMultimeter;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* Multimeter GUI
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiMultimeter extends GuiContainer
|
||||
{
|
||||
TileEntityMultimeter tileEntity;
|
||||
|
||||
private int containerWidth;
|
||||
private int containerHeight;
|
||||
private GuiTextField textFieldLimit;
|
||||
|
||||
public GuiMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tile)
|
||||
{
|
||||
super(new ContainerMultimeter(inventoryPlayer, tile));
|
||||
tileEntity = tile;
|
||||
ySize = 217;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
buttonList.add(new GuiButton(0, width / 2 + 20, height / 2 - 30, 50, 20, "Toggle"));
|
||||
textFieldLimit = new GuiTextField(fontRenderer, 35, 82, 65, 12);
|
||||
textFieldLimit.setMaxStringLength(8);
|
||||
textFieldLimit.setText("" + tileEntity.getLimit());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char par1, int par2)
|
||||
{
|
||||
super.keyTyped(par1, par2);
|
||||
|
||||
if(Character.isDigit(par1) || par2 == Keyboard.KEY_DELETE || par2 == Keyboard.KEY_LEFT || par2 == Keyboard.KEY_RIGHT)
|
||||
{
|
||||
textFieldLimit.textboxKeyTyped(par1, par2);
|
||||
}
|
||||
|
||||
ArrayList data = new ArrayList();
|
||||
data.add((byte)3);
|
||||
|
||||
if(!textFieldLimit.getText().isEmpty())
|
||||
{
|
||||
data.add(Float.parseFloat(textFieldLimit.getText()));
|
||||
}
|
||||
else {
|
||||
data.add(0);
|
||||
}
|
||||
|
||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Object3D.get(tileEntity), data));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int par1, int par2, int par3)
|
||||
{
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
textFieldLimit.mouseClicked(par1 - containerWidth, par2 - containerHeight, par3);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int par1, int par2)
|
||||
{
|
||||
String s = tileEntity.getBlockType().getLocalizedName();
|
||||
fontRenderer.drawString(s, xSize / 2 - fontRenderer.getStringWidth(s) / 2, 15, 4210752);
|
||||
fontRenderer.drawString("Average Energy: " + Math.round(tileEntity.getAverageDetectedEnergy()) + " J", 35, 25, 4210752);
|
||||
fontRenderer.drawString("Energy: " + Math.round(tileEntity.getDetectedEnergy()) + " J", 35, 35, 4210752);
|
||||
fontRenderer.drawString("Output Redstone If... ", 35, 54, 4210752);
|
||||
fontRenderer.drawString(tileEntity.getMode().display, 35, 65, 4210752);
|
||||
fontRenderer.drawString("KiloJoules", 35, 100, 4210752);
|
||||
|
||||
textFieldLimit.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen()
|
||||
{
|
||||
super.updateScreen();
|
||||
|
||||
textFieldLimit.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int x, int y)
|
||||
{
|
||||
containerWidth = (width - xSize) / 2;
|
||||
containerHeight = (height - ySize) / 2;
|
||||
|
||||
mc.renderEngine.bindTexture(MekanismUtils.getResource(ResourceType.GUI, "GuiMultimeter.png"));
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(containerWidth, containerHeight, 0, 0, xSize, ySize);
|
||||
|
||||
int length = Math.min((int) (tileEntity.getDetectedEnergy() / tileEntity.getPeak()) * 115, 115);
|
||||
drawTexturedModalRect(containerWidth + 14, containerHeight + 126 - length, 176, 115 - length, 6, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
ArrayList data = new ArrayList();
|
||||
data.add((byte)2);
|
||||
|
||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Object3D.get(tileEntity), data));
|
||||
}
|
||||
}
|
|
@ -5,10 +5,8 @@ package mekanism.induction.common;
|
|||
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.induction.common.inventory.container.ContainerBattery;
|
||||
import mekanism.induction.common.inventory.container.ContainerMultimeter;
|
||||
import mekanism.induction.common.tileentity.TileEntityBattery;
|
||||
import mekanism.induction.common.tileentity.TileEntityEMContractor;
|
||||
import mekanism.induction.common.tileentity.TileEntityMultimeter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -40,11 +38,7 @@ public class InductionCommonProxy implements IGuiHandler
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if(tileEntity instanceof TileEntityMultimeter)
|
||||
{
|
||||
return new ContainerMultimeter(player.inventory, ((TileEntityMultimeter)tileEntity));
|
||||
}
|
||||
else if(tileEntity instanceof TileEntityBattery)
|
||||
if(tileEntity instanceof TileEntityBattery)
|
||||
{
|
||||
return new ContainerBattery(player.inventory, ((TileEntityBattery)tileEntity));
|
||||
}
|
||||
|
|
|
@ -10,10 +10,8 @@ import mekanism.induction.common.block.BlockBattery;
|
|||
import mekanism.induction.common.block.BlockEMContractor;
|
||||
import mekanism.induction.common.block.BlockTesla;
|
||||
import mekanism.induction.common.item.ItemBlockContractor;
|
||||
import mekanism.induction.common.item.ItemBlockMultimeter;
|
||||
import mekanism.induction.common.tileentity.TileEntityBattery;
|
||||
import mekanism.induction.common.tileentity.TileEntityEMContractor;
|
||||
import mekanism.induction.common.tileentity.TileEntityMultimeter;
|
||||
import mekanism.induction.common.tileentity.TileEntityTesla;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -92,7 +90,6 @@ public class MekanismInduction implements IModule
|
|||
|
||||
//Tiles
|
||||
GameRegistry.registerTileEntity(TileEntityTesla.class, "Tesla");
|
||||
GameRegistry.registerTileEntity(TileEntityMultimeter.class, "Multimeter");
|
||||
GameRegistry.registerTileEntity(TileEntityEMContractor.class, "ElectromagneticContractor");
|
||||
GameRegistry.registerTileEntity(TileEntityBattery.class, "Battery");
|
||||
|
||||
|
@ -109,9 +106,9 @@ public class MekanismInduction implements IModule
|
|||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent evt)
|
||||
{
|
||||
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Tesla), new Object[] { "WEW", " C ", " I ", 'W', Mekanism.EnrichedAlloy, 'E', Item.eyeOfEnder, 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'I', new ItemStack(Mekanism.BasicBlock, 1, 8) }));
|
||||
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Battery, 4), new Object[] { "RRR", "CIC", "RRR", 'R', Item.redstone, 'I', MekanismUtils.getEnergyCube(EnergyCubeTier.BASIC), 'C', "circuitBasic" }));
|
||||
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(ElectromagneticContractor), new Object[] { " I ", "GCG", "WWW", 'W', "ingotSteel", 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'G', "ingotOsmium", 'I', "ingotSteel" }));
|
||||
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Tesla), new Object[] {"WEW", " C ", " I ", 'W', Mekanism.EnrichedAlloy, 'E', Item.eyeOfEnder, 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'I', new ItemStack(Mekanism.BasicBlock, 1, 8)}));
|
||||
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(Battery, 4), new Object[] {"RRR", "CIC", "RRR", 'R', Item.redstone, 'I', MekanismUtils.getEnergyCube(EnergyCubeTier.BASIC), 'C', "circuitBasic"}));
|
||||
GameRegistry.addRecipe(new MekanismRecipe(new ItemStack(ElectromagneticContractor), new Object[] {" I ", "GCG", "WWW", 'W', "ingotSteel", 'C', Mekanism.EnergyTablet.getUnchargedItem(), 'G', "ingotOsmium", 'I', "ingotSteel"}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package mekanism.induction.common.inventory.container;
|
||||
|
||||
import mekanism.induction.common.tileentity.TileEntityMultimeter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ContainerMultimeter extends Container
|
||||
{
|
||||
private final int yDisplacement = 51;
|
||||
private TileEntityMultimeter tileEntity;
|
||||
|
||||
public ContainerMultimeter(InventoryPlayer inventoryPlayer, TileEntityMultimeter tileEntity)
|
||||
{
|
||||
this.tileEntity = tileEntity;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = 0; j < 9; ++j)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + yDisplacement));
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 9; ++i)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142 + yDisplacement));
|
||||
}
|
||||
|
||||
this.tileEntity.playersUsing.add(inventoryPlayer.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityPlayer)
|
||||
{
|
||||
this.tileEntity.playersUsing.remove(entityPlayer);
|
||||
super.onContainerClosed(entityPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityplayer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package mekanism.induction.common.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.induction.common.tileentity.TileEntityMultimeter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* ItemBlock for the Multimeter
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class ItemBlockMultimeter extends ItemBlock
|
||||
{
|
||||
public ItemBlockMultimeter(int par1)
|
||||
{
|
||||
super(par1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
|
||||
{
|
||||
par3List.add("Shift-right click to place,");
|
||||
par3List.add("Right click to scan data.");
|
||||
|
||||
float detection = this.getDetection(itemStack);
|
||||
|
||||
if (detection != -1)
|
||||
{
|
||||
par3List.add("Last Detection: " + detection + " KJ");
|
||||
}
|
||||
else
|
||||
{
|
||||
par3List.add("No detection saved.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemUseFirst(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
|
||||
{
|
||||
if (!par2EntityPlayer.isSneaking())
|
||||
{
|
||||
// if (!world.isRemote)
|
||||
{
|
||||
par2EntityPlayer.addChatMessage("Energy: " + TileEntityMultimeter.getDetectedEnergy(ForgeDirection.getOrientation(par7), world.getBlockTileEntity(x, y, z)) + " J");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onItemUseFirst(par1ItemStack, par2EntityPlayer, world, x, y, z, par7, par8, par9, par10);
|
||||
}
|
||||
|
||||
public float getDetection(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("detection"))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return itemStack.stackTagCompound.getFloat("detection");
|
||||
}
|
||||
|
||||
public void setDetection(ItemStack itemStack, float detection)
|
||||
{
|
||||
if (itemStack.stackTagCompound == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
itemStack.stackTagCompound.setFloat("detection", detection);
|
||||
}
|
||||
}
|
|
@ -1,279 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package mekanism.induction.common.tileentity;
|
||||
|
||||
import ic2.api.tile.IEnergyStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.ITileNetwork;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketDataRequest;
|
||||
import mekanism.common.network.PacketTileEntity;
|
||||
import mekanism.induction.common.MekanismInduction;
|
||||
import mekanism.induction.common.MultimeterEventHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
import universalelectricity.core.block.IElectricalStorage;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import universalelectricity.prefab.tile.IRotatable;
|
||||
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import cofh.api.energy.TileEnergyHandler;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
/**
|
||||
* Block that detects power.
|
||||
*
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileEntityMultimeter extends TileEntityAdvanced implements ITileNetwork, IConnector, IRotatable
|
||||
{
|
||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
|
||||
public enum DetectMode
|
||||
{
|
||||
NONE("None"), LESS_THAN("Less Than"), LESS_THAN_EQUAL("Less Than or Equal"),
|
||||
EQUAL("Equal"), GREATER_THAN("Greater Than or Equal"), GREATER_THAN_EQUAL("Greater Than");
|
||||
|
||||
public String display;
|
||||
|
||||
private DetectMode(String s)
|
||||
{
|
||||
display = s;
|
||||
}
|
||||
}
|
||||
|
||||
private DetectMode detectMode = DetectMode.NONE;
|
||||
private float peakDetection;
|
||||
private float energyLimit;
|
||||
private float detectedEnergy;
|
||||
private float detectedAverageEnergy;
|
||||
public boolean redstoneOn;
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (ticks % 20 == 0)
|
||||
{
|
||||
float prevDetectedEnergy = detectedEnergy;
|
||||
updateDetection(doGetDetectedEnergy());
|
||||
|
||||
boolean outputRedstone = false;
|
||||
|
||||
switch (detectMode)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case EQUAL:
|
||||
outputRedstone = detectedEnergy == energyLimit;
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
outputRedstone = detectedEnergy > energyLimit;
|
||||
break;
|
||||
case GREATER_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy >= energyLimit;
|
||||
break;
|
||||
case LESS_THAN:
|
||||
outputRedstone = detectedEnergy < energyLimit;
|
||||
break;
|
||||
case LESS_THAN_EQUAL:
|
||||
outputRedstone = detectedEnergy <= energyLimit;
|
||||
break;
|
||||
}
|
||||
|
||||
if (outputRedstone != redstoneOn)
|
||||
{
|
||||
redstoneOn = outputRedstone;
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, MekanismInduction.Multimeter.blockID);
|
||||
}
|
||||
|
||||
if (prevDetectedEnergy != detectedEnergy)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
for (EntityPlayer player : playersUsing)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(ByteArrayDataInput input)
|
||||
{
|
||||
switch (input.readByte())
|
||||
{
|
||||
default:
|
||||
detectMode = DetectMode.values()[input.readByte()];
|
||||
detectedEnergy = input.readFloat();
|
||||
energyLimit = input.readFloat();
|
||||
break;
|
||||
case 2:
|
||||
toggleMode();
|
||||
break;
|
||||
case 3:
|
||||
energyLimit = input.readFloat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList getNetworkedData(ArrayList data)
|
||||
{
|
||||
data.add((byte) 1);
|
||||
data.add((byte) detectMode.ordinal());
|
||||
data.add(detectedEnergy);
|
||||
data.add(energyLimit);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate()
|
||||
{
|
||||
super.validate();
|
||||
|
||||
if (worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketDataRequest().setParams(Object3D.get(this)));
|
||||
}
|
||||
}
|
||||
|
||||
public float doGetDetectedEnergy()
|
||||
{
|
||||
ForgeDirection direction = getDirection();
|
||||
TileEntity tileEntity = worldObj.getBlockTileEntity(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
|
||||
return getDetectedEnergy(direction.getOpposite(), tileEntity);
|
||||
}
|
||||
|
||||
public static float getDetectedEnergy(ForgeDirection side, TileEntity tileEntity)
|
||||
{
|
||||
if (tileEntity instanceof TileEntityElectrical)
|
||||
{
|
||||
return ((TileEntityElectrical) tileEntity).getEnergyStored();
|
||||
}
|
||||
else if (tileEntity instanceof IElectricalStorage)
|
||||
{
|
||||
return ((IElectricalStorage) tileEntity).getEnergyStored();
|
||||
}
|
||||
else if (tileEntity instanceof IConductor)
|
||||
{
|
||||
IElectricityNetwork network = ((IConductor) tileEntity).getNetwork();
|
||||
|
||||
if (MultimeterEventHandler.getCache(tileEntity.worldObj).containsKey(network) && MultimeterEventHandler.getCache(tileEntity.worldObj).get(network) instanceof Float)
|
||||
{
|
||||
return MultimeterEventHandler.getCache(tileEntity.worldObj).get(network);
|
||||
}
|
||||
}
|
||||
else if (tileEntity instanceof IEnergyStorage)
|
||||
{
|
||||
return ((IEnergyStorage) tileEntity).getStored();
|
||||
}
|
||||
else if (tileEntity instanceof TileEnergyHandler)
|
||||
{
|
||||
return ((TileEnergyHandler) tileEntity).getEnergyStored(side.getOpposite());
|
||||
}
|
||||
else if (tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
if (((IPowerReceptor) tileEntity).getPowerReceiver(side) != null)
|
||||
{
|
||||
return ((IPowerReceptor) tileEntity).getPowerReceiver(side).getEnergyStored();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void updateDetection(float detected)
|
||||
{
|
||||
detectedEnergy = detected;
|
||||
detectedAverageEnergy = (detectedAverageEnergy + detectedEnergy) / 2;
|
||||
peakDetection = Math.max(peakDetection, detectedEnergy);
|
||||
}
|
||||
|
||||
public float getDetectedEnergy()
|
||||
{
|
||||
return detectedEnergy;
|
||||
}
|
||||
|
||||
public float getAverageDetectedEnergy()
|
||||
{
|
||||
return detectedAverageEnergy;
|
||||
}
|
||||
|
||||
public void toggleMode()
|
||||
{
|
||||
detectMode = DetectMode.values()[(detectMode.ordinal() + 1) % DetectMode.values().length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
detectMode = DetectMode.values()[nbt.getInteger("detectMode")];
|
||||
energyLimit = nbt.getFloat("energyLimit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("detectMode", detectMode.ordinal());
|
||||
nbt.setFloat("energyLimit", energyLimit);
|
||||
}
|
||||
|
||||
public DetectMode getMode()
|
||||
{
|
||||
return detectMode;
|
||||
}
|
||||
|
||||
public float getLimit()
|
||||
{
|
||||
return energyLimit;
|
||||
}
|
||||
|
||||
public float getPeak()
|
||||
{
|
||||
return peakDetection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return direction == getDirection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getDirection()
|
||||
{
|
||||
return ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirection(ForgeDirection direction)
|
||||
{
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue