Skip to content

Commit

Permalink
Finished Connection rewrite
Browse files Browse the repository at this point in the history
Removed some old interfaces
Updated AE node
Made selected inventories sync properly
  • Loading branch information
hilburn committed May 25, 2015
1 parent ea8a913 commit 415103e
Show file tree
Hide file tree
Showing 32 changed files with 444 additions and 472 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package advancedsystemsmanager.api.network;

public interface IPacketSync extends IPacketReader, IPacketWriter
public interface IPacketSync extends IPacketReader
{
void onUpdate();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package advancedsystemsmanager.api.execution;
package advancedsystemsmanager.api.tileentities;

import advancedsystemsmanager.api.execution.IBufferElement;
import advancedsystemsmanager.flow.execution.ConditionSettingChecker;
import advancedsystemsmanager.flow.menus.MenuItem;
import advancedsystemsmanager.flow.setting.Setting;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package advancedsystemsmanager.api.execution;
package advancedsystemsmanager.api.tileentities;

import advancedsystemsmanager.api.execution.IBufferElement;
import advancedsystemsmanager.flow.menus.MenuLiquid;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.IFluidHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package advancedsystemsmanager.compatibility.appliedenergistics;

import advancedsystemsmanager.api.execution.IBufferElement;
import advancedsystemsmanager.flow.execution.buffers.elements.BufferElementBase;
import advancedsystemsmanager.flow.setting.Setting;
import advancedsystemsmanager.tileentities.TileEntityAENode;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

public class AEFluidBufferElement extends BufferElementBase<Fluid>
{
protected TileEntityAENode node;

public AEFluidBufferElement(int id, TileEntityAENode node, int amount, Fluid fluid, Setting<Fluid> setting, boolean whitelist)
{
this(id, node, amount, fluid);
this.setting = setting;
this.whitelist = whitelist;
}

public AEFluidBufferElement(int id, TileEntityAENode node, int amount, Fluid fluid)
{
super(id);
this.node = node;
this.amount = amount;
this.content = fluid;
}

@Override
public void remove()
{

}

@Override
public void onUpdate()
{

}

@Override
public int getSizeLeft()
{
FluidStack stack = node.getTank().drain(ForgeDirection.UNKNOWN, new FluidStack(content, amount), false);
return stack == null ? 0 : getMaxWithSetting(stack.amount);
}

@Override
public int reduceBufferAmount(int amount)
{
amount = Math.min(amount, this.amount);
FluidStack stack = node.getTank().drain(ForgeDirection.UNKNOWN, new FluidStack(content, amount), true);
return stack == null ? 0 : stack.amount;
}

@Override
public IBufferElement<Fluid> getSplitElement(int elementAmount, int id, boolean fair)
{
AEFluidBufferElement element = new AEFluidBufferElement(this.id, this.node, this.amount, this.content, this.setting, this.whitelist);
int oldAmount = getSizeLeft();
int amount = oldAmount / elementAmount;
if (!fair)
{
int amountLeft = oldAmount % elementAmount;
if (id < amountLeft)
{
amount++;
}
}
element.amount = amount;
return element;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package advancedsystemsmanager.compatibility.appliedenergistics;

import advancedsystemsmanager.api.execution.IBufferElement;
import advancedsystemsmanager.api.execution.Key;
import advancedsystemsmanager.flow.execution.buffers.elements.BufferElementBase;
import advancedsystemsmanager.flow.setting.Setting;
import advancedsystemsmanager.tileentities.TileEntityAENode;
import appeng.api.storage.data.IAEItemStack;
import net.minecraft.item.ItemStack;

public class AEItemBufferElement extends BufferElementBase<ItemStack>
{
private TileEntityAENode node;
private IAEItemStack stack;

public AEItemBufferElement(int id, TileEntityAENode node, IAEItemStack stack, Setting<ItemStack> setting, boolean whitelist)
{
this(id, node, stack);
this.setting = setting;
this.whitelist = whitelist;
}

private AEItemBufferElement(int id, TileEntityAENode node, IAEItemStack stack)
{
super(id);
this.node = node;
this.stack = stack;
this.amount = (int)Math.min(Integer.MAX_VALUE, stack.getStackSize());
}

@Override
public ItemStack getContent()
{
return stack.getItemStack();
}

@Override
public void remove()
{
}

@Override
public void onUpdate()
{

}

@Override
public int getSizeLeft()
{
return (int)Math.min(stack.getStackSize(), amount);
}

@Override
public int reduceBufferAmount(int amount)
{
return (int)node.helper.extract(stack.copy().setStackSize(amount)).getStackSize();
}

@Override
public IBufferElement<ItemStack> getSplitElement(int elementAmount, int id, boolean fair)
{
AEItemBufferElement element = new AEItemBufferElement(this.id, this.node, this.stack, this.setting, this.whitelist);
int oldAmount = this.getSizeLeft();
int amount = oldAmount / elementAmount;
if (!fair)
{
int amountLeft = oldAmount % elementAmount;
if (id < amountLeft)
{
++amount;
}
}
element.amount = amount;
return element;
}

@Override
public Key<ItemStack> getKey()
{
return new Key.ItemKey(stack.getItemStack());
}
}
106 changes: 82 additions & 24 deletions src/main/java/advancedsystemsmanager/flow/Connection.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package advancedsystemsmanager.flow;

import advancedsystemsmanager.tileentities.manager.TileEntityManager;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -11,48 +12,96 @@

public class Connection
{
public static final String NBT_CONNECTION_POS = "CP";
public static final String NBT_CONNECTION_TARGET_COMPONENT = "CT";
public static final String NBT_CONNECTION_TARGET_CONNECTION = "CC";
public static final String NBT_CONNECTION_INPUT_CONNECTION = "ICo";
public static final String NBT_CONNECTION_OUTPUT_COMPONENT = "OC";
public static final String NBT_CONNECTION_OUTPUT_CONNECTION = "OCo";
public static final String NBT_NODES = "N";
public static final String NBT_POS_X = "X";
public static final String NBT_POS_Y = "Y";

public int componentId;
public int connectionId;
public int inputId;
public int inputConnection;
public int outputId;
public int outputConnection;
public List<Point> nodes;
public int selected = -1;

public Connection(int componentId, int connectionId)
{
this.componentId = componentId;
this.connectionId = connectionId;
this(componentId, connectionId, -1, -1);
}

public Connection(int newInput, int newOutput, Connection connection)
{
this(newInput, connection.getInputConnection(), newOutput, connection.getOutputConnection());
}

public Connection(int inputId, int inputConnection, int outputId, int outputConnection)
{
this.inputId = inputId;
this.inputConnection = inputConnection;
this.outputId = outputId;
this.outputConnection = outputConnection;
nodes = new ArrayList<Point>();
}

public int getComponentId()
public int getInputId()
{
return inputId;
}

public void setInputId(int componentId)
{
return componentId;
this.outputId = this.inputId;
this.inputId = componentId;
}

public void setComponentId(int componentId)
public int getInputConnection()
{
this.componentId = componentId;
return inputConnection;
}

public int getConnectionId()
public void setInputConnection(int connectionId)
{
return connectionId;
this.outputConnection = this.inputConnection;
this.inputConnection = connectionId;
}

public void setConnectionId(int connectionId)
public void setOutputId(int componentId)
{
this.connectionId = connectionId;
this.outputId = componentId;
}

public void setOutputConnection(int connectionId)
{
this.outputConnection = connectionId;
}

public void setConnection(TileEntityManager manager)
{
FlowComponent a = manager.getFlowItem(inputId);
FlowComponent b = manager.getFlowItem(outputId);
if (a != null && !a.equals(b))
{
a.setConnection(inputConnection, this);
if (b!= null)b.setConnection(outputConnection, this);
}
}

public void deleteConnection(TileEntityManager manager)
{
FlowComponent a = manager.getFlowItem(inputId);
FlowComponent b = manager.getFlowItem(outputId);
if (a != null)
{
a.setConnection(inputConnection, null);
if (b != null) b.setConnection(outputConnection, null);
}
}

public Connection copy()
{
Connection copy = new Connection(this.componentId, this.connectionId);
Connection copy = new Connection(inputId, inputConnection, outputId, outputConnection);
for (Point node : nodes)
{
copy.nodes.add(node.copy());
Expand Down Expand Up @@ -109,11 +158,11 @@ public void setSelected(int selected)
this.selected = selected;
}

public void writeToNBT(NBTTagCompound tagCompound, int index)
public void writeToNBT(NBTTagCompound tagCompound)
{
tagCompound.setByte(NBT_CONNECTION_POS, (byte)index);
tagCompound.setInteger(NBT_CONNECTION_TARGET_COMPONENT, getComponentId());
tagCompound.setByte(NBT_CONNECTION_TARGET_CONNECTION, (byte)getConnectionId());
tagCompound.setByte(NBT_CONNECTION_INPUT_CONNECTION, (byte)getInputConnection());
tagCompound.setInteger(NBT_CONNECTION_OUTPUT_COMPONENT, getOutputId());
tagCompound.setByte(NBT_CONNECTION_OUTPUT_CONNECTION, (byte)getOutputConnection());


NBTTagList nodes = new NBTTagList();
Expand All @@ -130,10 +179,10 @@ public void writeToNBT(NBTTagCompound tagCompound, int index)
tagCompound.setTag(NBT_NODES, nodes);
}

public static void readFromNBT(Connection[] connections, NBTTagCompound tagCompound)
public static void readFromNBT(Connection[] connections, NBTTagCompound tagCompound, int inputId)
{
int componentId = tagCompound.getInteger(NBT_CONNECTION_TARGET_COMPONENT);
Connection connection = new Connection(componentId, tagCompound.getByte(NBT_CONNECTION_TARGET_CONNECTION));
Connection connection = new Connection(inputId, tagCompound.getByte(NBT_CONNECTION_INPUT_CONNECTION),
tagCompound.getInteger(NBT_CONNECTION_OUTPUT_COMPONENT), tagCompound.getByte(NBT_CONNECTION_OUTPUT_CONNECTION));

if (tagCompound.hasKey(NBT_NODES))
{
Expand All @@ -146,7 +195,16 @@ public static void readFromNBT(Connection[] connections, NBTTagCompound tagCompo
connection.getNodes().add(new Point(nodeTag.getShort(NBT_POS_X), nodeTag.getShort(NBT_POS_Y)));
}
}
connections[connection.getInputConnection()] = connection;
}

public int getOutputId()
{
return outputId;
}

connections[(int)tagCompound.getByte(NBT_CONNECTION_POS)] = connection;
public int getOutputConnection()
{
return outputConnection;
}
}
Loading

0 comments on commit 415103e

Please sign in to comment.