Coming along with round robin mode :)

This commit is contained in:
Aidan C. Brady 2013-11-08 11:13:51 -05:00
parent 7cc72e65b3
commit 51ad429973
7 changed files with 137 additions and 5 deletions

View file

@ -187,6 +187,14 @@ public class GuiLogisticalSorter extends GuiMekanism
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Object3D.get(tileEntity), data));
}
if(xAxis >= 12 && xAxis <= 26 && yAxis >= 84 && yAxis <= 98)
{
ArrayList data = new ArrayList();
data.add(2);
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Object3D.get(tileEntity), data));
}
}
}
@ -257,6 +265,9 @@ public class GuiLogisticalSorter extends GuiMekanism
fontRenderer.drawString("IS: " + getItemStackFilters().size(), 11, 37, 0x00CD00);
fontRenderer.drawString("OD: " + getOreDictFilters().size(), 11, 46, 0x00CD00);
fontRenderer.drawString("RR:", 12, 74, 0x00CD00);
fontRenderer.drawString(tileEntity.roundRobin ? "On" : "Off", 27, 86, 0x00CD00);
fontRenderer.drawString("Auto:", 12, 100, 0x00CD00);
fontRenderer.drawString(tileEntity.autoEject ? "On" : "Off", 27, 112, 0x00CD00);
@ -380,6 +391,14 @@ public class GuiLogisticalSorter extends GuiMekanism
else {
drawTexturedModalRect(guiWidth + 12, guiHeight + 110, 176, 14, 14, 14);
}
if(xAxis >= 12 && xAxis <= 26 && yAxis >= 84 && yAxis <= 98)
{
drawTexturedModalRect(guiWidth + 12, guiHeight + 84, 176 + 14, 0, 14, 14);
}
else {
drawTexturedModalRect(guiWidth + 12, guiHeight + 84, 176 + 14, 14, 14, 14);
}
}
public ArrayList getItemStackFilters()

View file

@ -36,6 +36,10 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
public boolean autoEject;
public boolean roundRobin;
public int rrIndex = 0;
public final int MAX_DELAY = 10;
public int delayTicks;
@ -104,7 +108,23 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
if(inInventory != null && inInventory.getStack() != null)
{
if(TransporterUtils.insert(this, transporter, inInventory.getStack(), filterColor))
boolean inserted = false;
if(!roundRobin)
{
if(TransporterUtils.insert(this, transporter, inInventory.getStack(), filterColor))
{
inserted = true;
}
}
else {
if(TransporterUtils.insertRR(this, transporter, inInventory.getStack(), filterColor))
{
inserted = true;
}
}
if(inserted)
{
inInventory.use();
inventory.onInventoryChanged();
@ -139,6 +159,9 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
}
nbtTags.setBoolean("autoEject", autoEject);
nbtTags.setBoolean("roundRobin", roundRobin);
nbtTags.setInteger("rrIndex", rrIndex);
NBTTagList filterTags = new NBTTagList();
@ -168,6 +191,9 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
}
autoEject = nbtTags.getBoolean("autoEject");
roundRobin = nbtTags.getBoolean("roundRobin");
rrIndex = nbtTags.getInteger("rrIndex");
if(nbtTags.hasKey("filters"))
{
@ -195,6 +221,10 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
{
autoEject = !autoEject;
}
else if(type == 2)
{
roundRobin = !roundRobin;
}
return;
}
@ -219,6 +249,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
}
autoEject = dataStream.readBoolean();
roundRobin = dataStream.readBoolean();
filters.clear();
@ -247,6 +278,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
}
autoEject = dataStream.readBoolean();
roundRobin = dataStream.readBoolean();
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
}
@ -282,6 +314,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
}
data.add(autoEject);
data.add(roundRobin);
data.add(filters.size());
@ -311,6 +344,7 @@ public class TileEntityLogisticalSorter extends TileEntityElectricBlock implemen
}
data.add(autoEject);
data.add(roundRobin);
return data;

View file

@ -231,6 +231,28 @@ public class TileEntityLogisticalTransporter extends TileEntity implements ITile
return false;
}
public boolean insertRR(TileEntityLogisticalSorter outputter, ItemStack itemStack, EnumColor color)
{
TransporterStack stack = new TransporterStack();
stack.itemStack = itemStack;
stack.originalLocation = Object3D.get(outputter);
stack.color = color;
if(!stack.canInsertToTransporter(this))
{
return false;
}
if(stack.recalculateRRPath(outputter, this))
{
transit.add(stack);
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getSyncPacket(stack, false)), Object3D.get(this), 50D);
return true;
}
return false;
}
public void entityEntering(TransporterStack stack)
{
stack.progress = 0;

View file

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
import mekanism.common.util.TransporterUtils;
import net.minecraft.tileentity.TileEntity;
@ -220,9 +221,41 @@ public final class TransporterPathfinder
return closest.path;
}
public List<Object3D> findRR(int index)
public List<Object3D> findRR(TileEntityLogisticalSorter outputter)
{
return null;
loop(start, new ArrayList<Object3D>(), 0);
Collections.sort(destinations);
Destination closest = null;
if(!destinations.isEmpty())
{
if(outputter.rrIndex <= destinations.size()-1)
{
closest = destinations.get(outputter.rrIndex);
if(outputter.rrIndex == destinations.size()-1)
{
outputter.rrIndex = 0;
}
else if(outputter.rrIndex < destinations.size()-1)
{
outputter.rrIndex++;
}
}
else {
closest = destinations.get(destinations.size()-1);
outputter.rrIndex = 0;
}
}
if(closest == null)
{
return null;
}
return closest.path;
}
}
@ -239,10 +272,10 @@ public final class TransporterPathfinder
return path;
}
public static List<Object3D> getNewRRPath(TileEntityLogisticalTransporter start, TransporterStack stack, int index)
public static List<Object3D> getNewRRPath(TileEntityLogisticalTransporter start, TransporterStack stack, TileEntityLogisticalSorter outputter)
{
DestPath d = new DestPath(start.worldObj, Object3D.get(start), stack);
List<Object3D> path = d.findRR(index);
List<Object3D> path = d.findRR(outputter);
if(path == null)
{

View file

@ -5,6 +5,7 @@ import java.util.List;
import mekanism.api.EnumColor;
import mekanism.api.Object3D;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
import mekanism.common.util.TransporterUtils;
import net.minecraft.item.ItemStack;
@ -150,6 +151,23 @@ public class TransporterStack
return true;
}
public boolean recalculateRRPath(TileEntityLogisticalSorter outputter, TileEntityLogisticalTransporter tileEntity)
{
List<Object3D> newPath = TransporterPathfinder.getNewRRPath(tileEntity, this, outputter);
if(newPath == null)
{
return false;
}
pathToTarget = newPath;
noTarget = false;
initiatedPath = true;
return true;
}
public boolean calculateIdle(TileEntityLogisticalTransporter tileEntity)
{
List<Object3D> newPath = TransporterPathfinder.getIdlePath(tileEntity, this);

View file

@ -7,6 +7,7 @@ import mekanism.api.EnumColor;
import mekanism.api.IConfigurable;
import mekanism.api.Object3D;
import mekanism.api.transmitters.ITransmitter;
import mekanism.common.tileentity.TileEntityLogisticalSorter;
import mekanism.common.tileentity.TileEntityLogisticalTransporter;
import mekanism.common.transporter.InvStack;
import mekanism.common.transporter.TransporterStack;
@ -161,6 +162,11 @@ public final class TransporterUtils
return tileEntity.insert(Object3D.get(outputter), itemStack.copy(), color);
}
public static boolean insertRR(TileEntityLogisticalSorter outputter, TileEntityLogisticalTransporter tileEntity, ItemStack itemStack, EnumColor color)
{
return tileEntity.insertRR(outputter, itemStack.copy(), color);
}
public static boolean canInsert(TileEntity tileEntity, EnumColor color, ItemStack itemStack, int side)
{
if(!(tileEntity instanceof IInventory))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 5 KiB