From 51ad4299737bd883a80ec028fb4dce4d8fe4b7e2 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Fri, 8 Nov 2013 11:13:51 -0500 Subject: [PATCH] Coming along with round robin mode :) --- .../client/gui/GuiLogisticalSorter.java | 19 ++++++++ .../TileEntityLogisticalSorter.java | 36 ++++++++++++++- .../TileEntityLogisticalTransporter.java | 22 ++++++++++ .../transporter/TransporterPathfinder.java | 41 ++++++++++++++++-- .../common/transporter/TransporterStack.java | 18 ++++++++ .../common/util/TransporterUtils.java | 6 +++ .../mekanism/gui/GuiLogisticalSorter.png | Bin 4724 -> 5086 bytes 7 files changed, 137 insertions(+), 5 deletions(-) diff --git a/common/mekanism/client/gui/GuiLogisticalSorter.java b/common/mekanism/client/gui/GuiLogisticalSorter.java index e9bb106f6..82a8af3ae 100644 --- a/common/mekanism/client/gui/GuiLogisticalSorter.java +++ b/common/mekanism/client/gui/GuiLogisticalSorter.java @@ -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() diff --git a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java index 787b8f25e..8752c7958 100644 --- a/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java +++ b/common/mekanism/common/tileentity/TileEntityLogisticalSorter.java @@ -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; diff --git a/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java b/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java index f0a85250d..5be9da066 100644 --- a/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java +++ b/common/mekanism/common/tileentity/TileEntityLogisticalTransporter.java @@ -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; diff --git a/common/mekanism/common/transporter/TransporterPathfinder.java b/common/mekanism/common/transporter/TransporterPathfinder.java index fd7ad973e..8cc3813ae 100644 --- a/common/mekanism/common/transporter/TransporterPathfinder.java +++ b/common/mekanism/common/transporter/TransporterPathfinder.java @@ -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 findRR(int index) + public List findRR(TileEntityLogisticalSorter outputter) { - return null; + loop(start, new ArrayList(), 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 getNewRRPath(TileEntityLogisticalTransporter start, TransporterStack stack, int index) + public static List getNewRRPath(TileEntityLogisticalTransporter start, TransporterStack stack, TileEntityLogisticalSorter outputter) { DestPath d = new DestPath(start.worldObj, Object3D.get(start), stack); - List path = d.findRR(index); + List path = d.findRR(outputter); if(path == null) { diff --git a/common/mekanism/common/transporter/TransporterStack.java b/common/mekanism/common/transporter/TransporterStack.java index f4eebfa7a..d8b5ace37 100644 --- a/common/mekanism/common/transporter/TransporterStack.java +++ b/common/mekanism/common/transporter/TransporterStack.java @@ -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 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 newPath = TransporterPathfinder.getIdlePath(tileEntity, this); diff --git a/common/mekanism/common/util/TransporterUtils.java b/common/mekanism/common/util/TransporterUtils.java index 48c8addda..8698f3a6d 100644 --- a/common/mekanism/common/util/TransporterUtils.java +++ b/common/mekanism/common/util/TransporterUtils.java @@ -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)) diff --git a/resources/assets/mekanism/gui/GuiLogisticalSorter.png b/resources/assets/mekanism/gui/GuiLogisticalSorter.png index 9f5320f646f834848188d395b6263cf10f5c5783..cddb8ec1b9a2cacac28a0138d332234226f31bc0 100644 GIT binary patch delta 4018 zcmcgtdpK148eVHzXN=ekq6;x3L&8WRHkQ!1MWwQlq1%j2Nph=TQ&gx>yNgRPWylaS?u^@6`#jHi&L3y*bN177_E~?e=l6W;{k`A&z2Cd0GYuwiF%C8KcICE=6bh>boJNXBjZ#qcYm5xICY*Y@YHT? zNhP_y4qz8XG7KRD<#6&g091ng*qKsqGsmY#By~46R#)Ap`P#8)zn)+`P*yoO{OAYc zH~Q3tOlroPv5KchdUdyK(eN7*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