mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-28 07:55:41 +00:00
Implemented priority for item conduit outputs.
This commit is contained in:
1 parent
4ebb438153
commit
78c2586da3
8 files changed
+125
-21
No files matched your search
@@ -1,6 +1,9 @@
|
||||
package crazypants.enderio.conduit.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -18,6 +21,7 @@ import crazypants.enderio.gui.RedstoneModeButton;
|
||||
import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.machine.IRedstoneModeControlable;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.DyeColor;
|
||||
@@ -39,6 +43,8 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
private static final int ID_LOOP = 22;
|
||||
private static final int ID_CHANNEL = 23;
|
||||
private static final int ID_ROUND_ROBIN = 24;
|
||||
private static final int ID_PRIORITY_UP = 25;
|
||||
private static final int ID_PRIORITY_DOWN = 26;
|
||||
|
||||
private IItemConduit itemConduit;
|
||||
|
||||
@@ -57,6 +63,9 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
private ToggleButtonEIO loopB;
|
||||
private ToggleButtonEIO roundRobinB;
|
||||
|
||||
private IconButtonEIO priUpB;
|
||||
private IconButtonEIO priDownB;
|
||||
|
||||
private RedstoneModeButton rsB;
|
||||
private ColorButton colorB;
|
||||
|
||||
@@ -65,6 +74,11 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
boolean isAdvanced;
|
||||
|
||||
private ItemFilter activeFilter;
|
||||
|
||||
private int priLeft = 120;
|
||||
private int priWidth = 32;
|
||||
|
||||
private GuiToolTip priorityTooltip;
|
||||
|
||||
protected ItemSettings(final GuiExternalConnection gui, IConduit con) {
|
||||
super(IconEIO.WRENCH_OVERLAY_ITEM, Lang.localize("itemItemConduit.name"), gui, con);
|
||||
@@ -80,7 +94,7 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
nextFilterB = new IconButtonEIO(gui, NEXT_FILTER_ID, x, y, IconEIO.RIGHT_ARROW);
|
||||
nextFilterB.setSize(8, 16);
|
||||
|
||||
x = 112;
|
||||
x = 115;
|
||||
rsB = new RedstoneModeButton(gui, ID_REDSTONE_BUTTON, x, y, new IRedstoneModeControlable() {
|
||||
|
||||
@Override
|
||||
@@ -99,25 +113,33 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
}
|
||||
});
|
||||
|
||||
x += rsB.getWidth() + gap;
|
||||
x += rsB.getWidth() + 4;
|
||||
colorB = new ColorButton(gui, ID_COLOR_BUTTON, x, y);
|
||||
colorB.setColorIndex(itemConduit.getExtractionSignalColor(gui.dir).ordinal());
|
||||
colorB.setToolTipHeading(Lang.localize("gui.conduit.item.sigCol"));
|
||||
|
||||
x += gap + colorB.getWidth();
|
||||
|
||||
x += 4 + colorB.getWidth();
|
||||
roundRobinB = new ToggleButtonEIO(gui, ID_ROUND_ROBIN, x, y, IconEIO.ROUND_ROBIN_OFF, IconEIO.ROUND_ROBIN);
|
||||
roundRobinB.setSelectedToolTip(Lang.localize("gui.conduit.item.roundRobinEnabled"));
|
||||
roundRobinB.setUnselectedToolTip(Lang.localize("gui.conduit.item.roundRobinDisabled"));
|
||||
roundRobinB.setPaintSelectedBorder(false);
|
||||
|
||||
x += gap + roundRobinB.getWidth();
|
||||
|
||||
x += 4 + roundRobinB.getWidth();
|
||||
loopB = new ToggleButtonEIO(gui, ID_LOOP, x, y, IconEIO.LOOP_OFF, IconEIO.LOOP);
|
||||
loopB.setSelectedToolTip(Lang.localize("gui.conduit.item.selfFeedEnabled"));
|
||||
loopB.setUnselectedToolTip(Lang.localize("gui.conduit.item.selfFeedDisabled"));
|
||||
loopB.setPaintSelectedBorder(false);
|
||||
|
||||
|
||||
|
||||
x = priLeft + priWidth + 9;
|
||||
priUpB = new IconButtonEIO(gui, ID_PRIORITY_UP, x, y, IconEIO.ADD_BUT);
|
||||
priUpB.setSize(10, 10);
|
||||
|
||||
y += 10;
|
||||
priDownB = new IconButtonEIO(gui, ID_PRIORITY_DOWN, x, y, IconEIO.MINUS_BUT);
|
||||
priDownB.setSize(10, 10);
|
||||
|
||||
priorityTooltip = new GuiToolTip(new Rectangle(priLeft + 9, y, priWidth, 20), Lang.localize("gui.conduit.item.priority"));
|
||||
|
||||
x = 115;
|
||||
y = 66;
|
||||
whiteListB = new IconButtonEIO(gui, ID_WHITELIST, x, y, IconEIO.FILTER_WHITELIST);
|
||||
@@ -273,15 +295,22 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
whiteListB.setToolTip(Lang.localize("gui.conduit.item.whitelist"));
|
||||
}
|
||||
|
||||
if(mode == ConnectionMode.IN_OUT) {
|
||||
if(mode == ConnectionMode.IN_OUT && !outputActive) {
|
||||
loopB.onGuiInit();
|
||||
loopB.setSelected(itemConduit.isSelfFeedEnabled(gui.dir));
|
||||
loopB.setSelected(itemConduit.isSelfFeedEnabled(gui.dir));
|
||||
}
|
||||
if(!outputActive) {
|
||||
|
||||
if((mode == ConnectionMode.IN_OUT && !outputActive) || mode == ConnectionMode.INPUT) {
|
||||
roundRobinB.onGuiInit();
|
||||
roundRobinB.setSelected(itemConduit.isRoundRobinEnabled(gui.dir));
|
||||
}
|
||||
|
||||
if((mode == ConnectionMode.IN_OUT && outputActive) || mode == ConnectionMode.OUTPUT) {
|
||||
priUpB.onGuiInit();
|
||||
priDownB.onGuiInit();
|
||||
gui.addToolTip(priorityTooltip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -318,10 +347,18 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
} else if(guiButton.id == ID_LOOP) {
|
||||
itemConduit.setSelfFeedEnabled(gui.dir, !itemConduit.isSelfFeedEnabled(gui.dir));
|
||||
EnderIO.packetPipeline.sendToServer(new PacketItemConduitFilter(itemConduit, gui.dir));
|
||||
|
||||
|
||||
} else if(guiButton.id == ID_ROUND_ROBIN) {
|
||||
itemConduit.setRoundRobinEnabled(gui.dir, !itemConduit.isRoundRobinEnabled(gui.dir));
|
||||
EnderIO.packetPipeline.sendToServer(new PacketItemConduitFilter(itemConduit, gui.dir));
|
||||
|
||||
} else if(guiButton.id == ID_PRIORITY_UP) {
|
||||
itemConduit.setOutputPriority(gui.dir, itemConduit.getOutputPriority(gui.dir) + 1);
|
||||
EnderIO.packetPipeline.sendToServer(new PacketItemConduitFilter(itemConduit, gui.dir));
|
||||
|
||||
} else if(guiButton.id == ID_PRIORITY_DOWN) {
|
||||
itemConduit.setOutputPriority(gui.dir, itemConduit.getOutputPriority(gui.dir) - 1);
|
||||
EnderIO.packetPipeline.sendToServer(new PacketItemConduitFilter(itemConduit, gui.dir));
|
||||
|
||||
} else if(guiButton.id == ID_CHANNEL) {
|
||||
|
||||
@@ -379,6 +416,15 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
int x = 0;
|
||||
int rgb = ColorUtil.getRGB(Color.darkGray);
|
||||
fr.drawString(heading, left + x, top, rgb);
|
||||
|
||||
boolean outputActive = (mode == ConnectionMode.IN_OUT && !inOutShowIn) || (mode == ConnectionMode.OUTPUT);
|
||||
if(outputActive) {
|
||||
GL11.glColor3f(1, 1, 1);
|
||||
IconEIO.BUTTON_DOWN.renderIcon(left + priLeft, top - 5, priWidth, 20, 0, true);
|
||||
String str = itemConduit.getOutputPriority(gui.dir) + "";
|
||||
int sw = fr.getStringWidth(str);
|
||||
fr.drawString(str, left + priLeft + priWidth - sw - gap, top, ColorUtil.getRGB(Color.black));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -396,8 +442,12 @@ public class ItemSettings extends BaseSettingsPanel {
|
||||
useOreDictB.detach();
|
||||
whiteListB.detach();
|
||||
stickyB.detach();
|
||||
roundRobinB.detach();
|
||||
loopB.detach();
|
||||
nextFilterB.detach();
|
||||
priUpB.detach();
|
||||
priDownB.detach();
|
||||
gui.removeToolTip(priorityTooltip);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,6 +35,10 @@ public interface IItemConduit extends IConduit, IItemDuct, IExtractor {
|
||||
ItemFilter getInputFilter(ForgeDirection dir);
|
||||
|
||||
ItemFilter getOutputFilter(ForgeDirection dir);
|
||||
|
||||
int getOutputPriority(ForgeDirection dir);
|
||||
|
||||
void setOutputPriority(ForgeDirection dir, int priority);
|
||||
|
||||
int getMetaData();
|
||||
|
||||
|
||||
@@ -92,9 +92,11 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
protected final EnumMap<ForgeDirection, ItemFilter> inputFilters = new EnumMap<ForgeDirection, ItemFilter>(ForgeDirection.class);
|
||||
|
||||
protected final EnumMap<ForgeDirection, Boolean> selfFeed = new EnumMap<ForgeDirection, Boolean>(ForgeDirection.class);
|
||||
|
||||
|
||||
protected final EnumMap<ForgeDirection, Boolean> roundRobin = new EnumMap<ForgeDirection, Boolean>(ForgeDirection.class);
|
||||
|
||||
protected final EnumMap<ForgeDirection, Integer> priority = new EnumMap<ForgeDirection, Integer>(ForgeDirection.class);
|
||||
|
||||
protected final EnumMap<ForgeDirection, DyeColor> outputColors = new EnumMap<ForgeDirection, DyeColor>(ForgeDirection.class);
|
||||
protected final EnumMap<ForgeDirection, DyeColor> inputColors = new EnumMap<ForgeDirection, DyeColor>(ForgeDirection.class);
|
||||
|
||||
@@ -172,7 +174,7 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
} else if(network == null) {
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
return network.sendItems(this, item, from);
|
||||
}
|
||||
|
||||
@@ -365,7 +367,7 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
network.routesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRoundRobinEnabled(ForgeDirection dir) {
|
||||
Boolean val = roundRobin.get(dir);
|
||||
@@ -383,6 +385,24 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOutputPriority(ForgeDirection dir) {
|
||||
Integer res = priority.get(dir);
|
||||
if(res == null) {
|
||||
return 0;
|
||||
}
|
||||
return res.intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOutputPriority(ForgeDirection dir, int priority) {
|
||||
this.priority.put(dir, priority);
|
||||
if(network != null) {
|
||||
network.routesChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectToExternal(ForgeDirection direction, boolean ignoreDisabled) {
|
||||
IInventory inv = getExternalInventory(direction);
|
||||
@@ -513,12 +533,18 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
nbtRoot.setBoolean("selfFeed." + entry.getKey().name(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (Entry<ForgeDirection, Boolean> entry : roundRobin.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
nbtRoot.setBoolean("roundRobin." + entry.getKey().name(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<ForgeDirection, Integer> entry : priority.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
nbtRoot.setInteger("priority." + entry.getKey().name(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<ForgeDirection, DyeColor> entry : inputColors.entrySet()) {
|
||||
if(entry.getValue() != null) {
|
||||
@@ -577,12 +603,18 @@ public class ItemConduit extends AbstractConduit implements IItemConduit {
|
||||
boolean val = nbtRoot.getBoolean(key);
|
||||
selfFeed.put(dir, val);
|
||||
}
|
||||
|
||||
|
||||
key = "roundRobin." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
boolean val = nbtRoot.getBoolean(key);
|
||||
roundRobin.put(dir, val);
|
||||
}
|
||||
|
||||
key = "priority." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
int val = nbtRoot.getInteger(key);
|
||||
priority.put(dir, val);
|
||||
}
|
||||
|
||||
key = "inSC." + dir.name();
|
||||
if(nbtRoot.hasKey(key)) {
|
||||
|
||||
@@ -80,6 +80,10 @@ class NetworkedInventory {
|
||||
boolean isSticky() {
|
||||
return con.getOutputFilter(conDir).isValid() && con.getOutputFilter(conDir).isSticky();
|
||||
}
|
||||
|
||||
int getPriority() {
|
||||
return con.getOutputPriority(conDir);
|
||||
}
|
||||
|
||||
public void onTick(long tick) {
|
||||
int transfered;
|
||||
@@ -266,9 +270,9 @@ class NetworkedInventory {
|
||||
&& con.getInputColor(conDir) == other.con.getOutputColor(other.conDir)) {
|
||||
|
||||
if(Config.itemConduitUsePhyscialDistance) {
|
||||
sendPriority.add(new Target(other, distanceTo(other), other.isSticky()));
|
||||
sendPriority.add(new Target(other, distanceTo(other), other.isSticky(), other.getPriority()));
|
||||
} else {
|
||||
result.add(new Target(other, 9999999, other.isSticky()));
|
||||
result.add(new Target(other, 9999999, other.isSticky(), other.getPriority()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,11 +377,13 @@ class NetworkedInventory {
|
||||
NetworkedInventory inv;
|
||||
int distance;
|
||||
boolean stickyInput;
|
||||
int priority;
|
||||
|
||||
Target(NetworkedInventory inv, int distance, boolean stickyInput) {
|
||||
Target(NetworkedInventory inv, int distance, boolean stickyInput, int priority) {
|
||||
this.inv = inv;
|
||||
this.distance = distance;
|
||||
this.stickyInput = stickyInput;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -388,6 +394,9 @@ class NetworkedInventory {
|
||||
if(!stickyInput && o.stickyInput) {
|
||||
return 1;
|
||||
}
|
||||
if(priority != o.priority) {
|
||||
return ItemConduitNetwork.compare(o.priority,priority);
|
||||
}
|
||||
return ItemConduitNetwork.compare(distance, o.distance);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public class PacketItemConduitFilter extends AbstractConduitPacket<IItemConduit>
|
||||
private boolean roundRobin;
|
||||
private DyeColor colIn;
|
||||
private DyeColor colOut;
|
||||
private int priority;
|
||||
|
||||
private ItemFilter inputFilter;
|
||||
private ItemFilter outputFilter;
|
||||
@@ -31,6 +32,7 @@ public class PacketItemConduitFilter extends AbstractConduitPacket<IItemConduit>
|
||||
roundRobin = con.isRoundRobinEnabled(dir);
|
||||
colIn = con.getInputColor(dir);
|
||||
colOut = con.getOutputColor(dir);
|
||||
priority = con.getOutputPriority(dir);
|
||||
|
||||
inputFilter = con.getInputFilter(dir);
|
||||
outputFilter = con.getOutputFilter(dir);
|
||||
@@ -42,6 +44,7 @@ public class PacketItemConduitFilter extends AbstractConduitPacket<IItemConduit>
|
||||
buf.writeShort(dir.ordinal());
|
||||
buf.writeBoolean(loopMode);
|
||||
buf.writeBoolean(roundRobin);
|
||||
buf.writeInt(priority);
|
||||
buf.writeShort(colIn.ordinal());
|
||||
buf.writeShort(colOut.ordinal());
|
||||
writeFilter(buf, inputFilter);
|
||||
@@ -62,6 +65,7 @@ public class PacketItemConduitFilter extends AbstractConduitPacket<IItemConduit>
|
||||
dir = ForgeDirection.values()[buf.readShort()];
|
||||
loopMode = buf.readBoolean();
|
||||
roundRobin = buf.readBoolean();
|
||||
priority = buf.readInt();
|
||||
colIn = DyeColor.values()[buf.readShort()];
|
||||
colOut = DyeColor.values()[buf.readShort()];
|
||||
inputFilter = readFilter(buf);
|
||||
@@ -85,7 +89,7 @@ public class PacketItemConduitFilter extends AbstractConduitPacket<IItemConduit>
|
||||
conduit.setRoundRobinEnabled(dir, roundRobin);
|
||||
conduit.setInputColor(dir, colIn);
|
||||
conduit.setOutputColor(dir, colOut);
|
||||
|
||||
conduit.setOutputPriority(dir, priority);
|
||||
applyFilter(conduit, inputFilter, true);
|
||||
applyFilter(conduit, outputFilter, false);
|
||||
|
||||
|
||||
@@ -86,6 +86,10 @@ public final class IconEIO {
|
||||
public static final IconEIO IO_WHATSIT = new IconEIO(192, 148, 13,13);
|
||||
|
||||
public static final IconEIO RECIPE = new IconEIO(128, 116, 24,24);
|
||||
|
||||
public static final IconEIO ADD_BUT = new IconEIO(139, 246, 10,10);
|
||||
public static final IconEIO MINUS_BUT = new IconEIO(129, 246, 10,10);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user