Cleared out errors from removing energy prefab

This commit is contained in:
DarkGuardsman 2014-01-19 21:09:32 -05:00
parent f0538c0ace
commit 11e7035c95
4 changed files with 225 additions and 457 deletions

View file

@ -1,9 +1,9 @@
package resonantinduction.core.debug;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.prefab.tile.TileEnergyMachine;
import resonantinduction.core.prefab.tile.TileMachine;
public class TileEntityInfLoad extends TileEnergyMachine
public class TileEntityInfLoad extends TileMachine
{
@Override
@ -23,10 +23,4 @@ public class TileEntityInfLoad extends TileEnergyMachine
{
return true;
}
@Override
public long getMaxEnergyStored()
{
return Long.MAX_VALUE;
}
}

View file

@ -3,51 +3,52 @@ package resonantinduction.core.debug;
import java.util.EnumSet;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.prefab.tile.TileEnergyMachine;
import resonantinduction.core.prefab.tile.TileMachine;
import universalelectricity.api.energy.EnergyStorageHandler;
public class TileEntityInfSupply extends TileEnergyMachine
public class TileEntityInfSupply extends TileMachine
{
@Override
public void updateEntity()
{
super.updateEntity();
this.setJoulesPerTick(10000);
this.produce();
}
public TileEntityInfSupply()
{
this.energy = new EnergyStorageHandler(Long.MAX_VALUE);
this.energy.setMaxExtract(Long.MAX_VALUE);
}
@Override
public EnumSet<ForgeDirection> getOutputDirections()
{
return EnumSet.allOf(ForgeDirection.class);
}
@Override
public void updateEntity()
{
super.updateEntity();
this.energy.setEnergy(Long.MAX_VALUE);
this.produce();
}
@Override
public EnumSet<ForgeDirection> getInputDirections()
{
return EnumSet.noneOf(ForgeDirection.class);
}
@Override
public EnumSet<ForgeDirection> getOutputDirections()
{
return EnumSet.allOf(ForgeDirection.class);
}
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
return 0;
}
@Override
public EnumSet<ForgeDirection> getInputDirections()
{
return EnumSet.noneOf(ForgeDirection.class);
}
@Override
public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract)
{
return request;
}
@Override
public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive)
{
return 0;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
@Override
public long onExtractEnergy(ForgeDirection from, long request, boolean doExtract)
{
return request;
}
@Override
public long getMaxEnergyStored()
{
return Long.MAX_VALUE;
}
@Override
public boolean canConnect(ForgeDirection direction)
{
return true;
}
}

View file

@ -1,209 +0,0 @@
package resonantinduction.core.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import resonantinduction.core.Reference;
import resonantinduction.core.gui.GuiButtonImage.ButtonIcon;
import resonantinduction.core.prefab.tile.TileMachine;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class GuiMachineContainer extends GuiContainer
{
protected static final int MAX_BUTTON_ID = 3;
protected TileMachine tileEntity;
protected EntityPlayer entityPlayer;
protected Object mod;
protected int guiID = -1, guiID2 = -1, guiID3 = -1;
protected ButtonIcon guiIcon = ButtonIcon.CHEST, guiIcon2 = ButtonIcon.PERSON,
guiIcon3 = ButtonIcon.BLANK;
protected String invName = "Home", invName2 = "2", invName3 = "3";
public ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.GUI_DIRECTORY + "gui_grey.png");
protected int containerWidth;
protected int containerHeight;
public GuiMachineContainer(Object mod, Container container, InventoryPlayer inventoryPlayer, TileMachine tileEntity)
{
super(container);
this.tileEntity = tileEntity;
this.entityPlayer = inventoryPlayer.player;
this.ySize = 380 / 2;
this.mod = mod;
}
@SuppressWarnings("unchecked")
@Override
public void initGui()
{
super.initGui();
this.buttonList.clear();
containerWidth = (this.width - this.xSize) / 2;
containerHeight = (this.height - this.ySize) / 2;
if (guiID != -1)
this.buttonList.add(new GuiButtonImage(0, containerWidth - 22, containerHeight + 0, guiIcon));
if (guiID2 != -1)
this.buttonList.add(new GuiButtonImage(1, containerWidth - 22, containerHeight + 22, guiIcon2));
if (guiID3 != -1)
this.buttonList.add(new GuiButtonImage(2, containerWidth - 22, containerHeight + 44, guiIcon3));
}
@Override
protected void actionPerformed(GuiButton button)
{
super.actionPerformed(button);
switch (button.id)
{
case 0:
{
if (guiID != -1)
this.entityPlayer.openGui(mod, guiID, this.tileEntity.worldObj, this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord);
break;
}
case 1:
{
if (guiID2 != -1)
this.entityPlayer.openGui(mod, guiID2, this.tileEntity.worldObj, this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord);
break;
}
case 2:
{
if (guiID3 != -1)
this.entityPlayer.openGui(mod, guiID3, this.tileEntity.worldObj, this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord);
break;
}
}
}
/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
this.fontRenderer.drawString("\u00a77" + tileEntity.getInvName(), (int) (this.xSize / 2 - 7 * 2.5), 4, 4210752);
/** Render Tool Tips */
if (((GuiButtonImage) this.buttonList.get(0)).isIntersect(x, y))
{
this.drawTooltip(x - this.guiLeft, y - this.guiTop + 10, invName);
}
else if (((GuiButtonImage) this.buttonList.get(1)).isIntersect(x, y))
{
this.drawTooltip(x - this.guiLeft, y - this.guiTop + 10, invName2);
}
else if (((GuiButtonImage) this.buttonList.get(2)).isIntersect(x, y))
{
this.drawTooltip(x - this.guiLeft, y - this.guiTop + 10, invName3);
}
}
/** Draw the background layer for the GuiContainer (everything behind the items) */
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int x, int y)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int containerWidth = (this.width - this.xSize) / 2;
int containerHeight = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
}
public void drawTooltip(int x, int y, String... toolTips)
{
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_DEPTH_TEST);
if (toolTips != null)
{
int var5 = 0;
int var6;
int var7;
for (var6 = 0; var6 < toolTips.length; ++var6)
{
var7 = this.fontRenderer.getStringWidth(toolTips[var6]);
if (var7 > var5)
{
var5 = var7;
}
}
var6 = x + 12;
var7 = y - 12;
int var9 = 8;
if (toolTips.length > 1)
{
var9 += 2 + (toolTips.length - 1) * 10;
}
if (this.guiTop + var7 + var9 + 6 > this.height)
{
var7 = this.height - var9 - this.guiTop - 6;
}
this.zLevel = 300.0F;
int var10 = -267386864;
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
int var11 = 1347420415;
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
for (int var13 = 0; var13 < toolTips.length; ++var13)
{
String var14 = "\u00a77" + toolTips[var13];
this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
if (var13 == 0)
{
var7 += 2;
}
var7 += 10;
}
this.zLevel = 0.0F;
}
}
public int getGuiTop()
{
return this.guiTop;
}
public int getGuiLeft()
{
return this.guiLeft;
}
public TileEntity getTile()
{
return this.tileEntity;
}
}

View file

@ -3,13 +3,11 @@ package resonantinduction.electrical.encoder;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.prefab.tile.TileMachine;
import resonantinduction.electrical.Electrical;
import resonantinduction.electrical.armbot.Program;
import resonantinduction.electrical.armbot.task.TaskRotateTo;
@ -19,234 +17,218 @@ import resonantinduction.electrical.encoder.coding.TaskRegistry;
import universalelectricity.api.vector.Vector2;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.network.PacketHandler;
import calclavia.lib.prefab.tile.TileExternalInventory;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.PacketDispatcher;
public class TileEncoder extends TileMachine implements ISidedInventory, IPacketReceiver
public class TileEncoder extends TileExternalInventory implements ISidedInventory, IPacketReceiver
{
private ItemStack disk;
private IInventoryWatcher watcher;
public static final int PROGRAM_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
public static final int PROGRAM_CHANGE_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
public static final int REMOVE_TASK_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
public static final int NEW_TASK_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
private ItemStack disk;
private IInventoryWatcher watcher;
public static final int PROGRAM_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
public static final int PROGRAM_CHANGE_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
public static final int REMOVE_TASK_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
public static final int NEW_TASK_PACKET_ID = Electrical.contentRegistry.getNextPacketID();
protected IProgram program;
protected IProgram program;
public TileEncoder()
{
super();
this.hasGUI = true;
}
@Override
public void initiate()
{
super.initiate();
if (!this.worldObj.isRemote)
{
program = new Program();
program.setTaskAt(0, 0, new TaskRotateTo());
}
}
@Override
public void initiate()
{
super.initiate();
if (!this.worldObj.isRemote)
{
program = new Program();
program.setTaskAt(0, 0, new TaskRotateTo());
}
}
@Override
public void onInventoryChanged()
{
super.onInventoryChanged();
if (watcher != null)
{
watcher.inventoryChanged();
}
}
@Override
public void onInventoryChanged()
{
super.onInventoryChanged();
if (watcher != null)
{
watcher.inventoryChanged();
}
}
@Override
public String getInvName()
{
return "Encoder";
}
@Override
public String getInvName()
{
return "Encoder";
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
public void setWatcher(IInventoryWatcher watcher)
{
this.watcher = watcher;
}
public void setWatcher(IInventoryWatcher watcher)
{
this.watcher = watcher;
}
public IInventoryWatcher getWatcher()
{
return this.watcher;
}
public IInventoryWatcher getWatcher()
{
return this.watcher;
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (this.disk != null)
{
NBTTagCompound diskNBT = new NBTTagCompound();
this.disk.writeToNBT(diskNBT);
nbt.setCompoundTag("disk", diskNBT);
}
}
if (this.disk != null)
{
NBTTagCompound diskNBT = new NBTTagCompound();
this.disk.writeToNBT(diskNBT);
nbt.setCompoundTag("disk", diskNBT);
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagCompound diskNBT = nbt.getCompoundTag("disk");
NBTTagCompound diskNBT = nbt.getCompoundTag("disk");
if (diskNBT != null)
{
this.disk = ItemStack.loadItemStackFromNBT(diskNBT);
}
if (diskNBT != null)
{
this.disk = ItemStack.loadItemStackFromNBT(diskNBT);
}
}
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
int readInt = data.readInt();
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
int readInt = data.readInt();
if (readInt == PROGRAM_PACKET_ID)
{
if (data.readBoolean())
{
Program program = new Program();
program.load(PacketHandler.readNBTTagCompound(data));
this.program = program;
}
else
{
this.program = null;
}
}
else if (readInt == PROGRAM_CHANGE_PACKET_ID)
{
ITask task = TaskRegistry.getCommand(data.readUTF());
task.setPosition(data.readInt(), data.readInt());
task.load(PacketHandler.readNBTTagCompound(data));
this.getProgram().setTaskAt(task.getCol(), task.getRow(), task);
this.sendGUIPacket();
}
else if (readInt == NEW_TASK_PACKET_ID)
{
ITask task = TaskRegistry.getCommand(data.readUTF());
task.setPosition(data.readInt(), data.readInt());
task.load(PacketHandler.readNBTTagCompound(data));
this.getProgram().insertTask(task.getCol(), task.getRow(), task);
this.sendGUIPacket();
}
else if (readInt == REMOVE_TASK_PACKET_ID)
{
this.getProgram().setTaskAt(data.readInt(), data.readInt(), null);
this.sendGUIPacket();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
if (readInt == PROGRAM_PACKET_ID)
{
if (data.readBoolean())
{
Program program = new Program();
program.load(PacketHandler.readNBTTagCompound(data));
this.program = program;
}
else
{
this.program = null;
}
}
else if (readInt == PROGRAM_CHANGE_PACKET_ID)
{
ITask task = TaskRegistry.getCommand(data.readUTF());
task.setPosition(data.readInt(), data.readInt());
task.load(PacketHandler.readNBTTagCompound(data));
this.getProgram().setTaskAt(task.getCol(), task.getRow(), task);
this.sendGUIPacket();
}
else if (readInt == NEW_TASK_PACKET_ID)
{
ITask task = TaskRegistry.getCommand(data.readUTF());
task.setPosition(data.readInt(), data.readInt());
task.load(PacketHandler.readNBTTagCompound(data));
this.getProgram().insertTask(task.getCol(), task.getRow(), task);
this.sendGUIPacket();
}
else if (readInt == REMOVE_TASK_PACKET_ID)
{
this.getProgram().setTaskAt(data.readInt(), data.readInt(), null);
this.sendGUIPacket();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
private void sendGUIPacket()
{
// TODO Auto-generated method stub
}
/** Sends a gui packet only to the given player */
@Override
public Packet getGUIPacket()
{
return this.getDescriptionPacket();
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
boolean exists = this.program != null;
if (exists)
{
this.program.save(tag);
}
return ResonantInduction.PACKET_TILE.getPacket(this, TileEncoder.PROGRAM_PACKET_ID, this, exists, tag);
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
boolean exists = this.program != null;
if (exists)
{
this.program.save(tag);
}
return ResonantInduction.PACKET_TILE.getPacket(this, TileEncoder.PROGRAM_PACKET_ID, this, exists, tag);
}
}
public void removeTask(Vector2 vec)
{
if (vec != null)
{
if (this.worldObj.isRemote)
{
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, TileEncoder.REMOVE_TASK_PACKET_ID, this, vec.intX(), vec.intY()));
}
else
{
this.program.setTaskAt(vec.intX(), vec.intY(), null);
}
}
}
public void removeTask(Vector2 vec)
{
if (vec != null)
{
if (this.worldObj.isRemote)
{
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, TileEncoder.REMOVE_TASK_PACKET_ID, this, vec.intX(), vec.intY()));
}
else
{
this.program.setTaskAt(vec.intX(), vec.intY(), null);
}
}
}
public void updateTask(ITask editTask)
{
public void updateTask(ITask editTask)
{
if (editTask != null)
{
if (this.worldObj.isRemote)
{
NBTTagCompound nbt = new NBTTagCompound();
editTask.save(nbt);
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, PROGRAM_CHANGE_PACKET_ID, this, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), nbt));
}
else
{
this.program.setTaskAt(editTask.getCol(), editTask.getRow(), editTask);
}
}
if (editTask != null)
{
if (this.worldObj.isRemote)
{
NBTTagCompound nbt = new NBTTagCompound();
editTask.save(nbt);
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, PROGRAM_CHANGE_PACKET_ID, this, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), nbt));
}
else
{
this.program.setTaskAt(editTask.getCol(), editTask.getRow(), editTask);
}
}
}
}
public void insertTask(ITask editTask)
{
if (editTask != null)
{
if (this.worldObj.isRemote)
{
NBTTagCompound nbt = new NBTTagCompound();
editTask.save(nbt);
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, NEW_TASK_PACKET_ID, this, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), nbt));
}
else
{
this.program.insertTask(editTask.getCol(), editTask.getRow(), editTask);
}
}
public void insertTask(ITask editTask)
{
if (editTask != null)
{
if (this.worldObj.isRemote)
{
NBTTagCompound nbt = new NBTTagCompound();
editTask.save(nbt);
PacketDispatcher.sendPacketToServer(ResonantInduction.PACKET_TILE.getPacket(this, NEW_TASK_PACKET_ID, this, editTask.getMethodName(), editTask.getCol(), editTask.getRow(), nbt));
}
else
{
this.program.insertTask(editTask.getCol(), editTask.getRow(), editTask);
}
}
}
@Override
public boolean isInvNameLocalized()
{
// TODO ?
return false;
}
public IProgram getProgram()
{
return this.program;
}
@Override
public Class<? extends Container> getContainer()
{
return ContainerEncoder.class;
}
}
public IProgram getProgram()
{
if (this.program == null)
{
this.program = new Program();
}
return this.program;
}
}