Implemented Priority System for the item routing system. Lower numbers are looked at first.

This commit is contained in:
WayofTime 2016-02-22 21:19:22 -05:00
parent 2c49c49441
commit 7104138e2b
10 changed files with 97 additions and 10 deletions

View file

@ -2,6 +2,8 @@
Version 2.0.0-19 Version 2.0.0-19
------------------------------------------------------ ------------------------------------------------------
- Fixed path blocks so they are actually craftable. - Fixed path blocks so they are actually craftable.
- Added gui stuff to enable priority in the item routing system: nodes with a lower value priority will be accessed first. (May be rotated in the future)
- Grayed out the currently active side's button in the item routers.
------------------------------------------------------ ------------------------------------------------------
Version 2.0.0-18 Version 2.0.0-18

View file

@ -97,6 +97,7 @@ public class Constants
public static final String ROUTING_MASTER = "master"; public static final String ROUTING_MASTER = "master";
public static final String ROUTING_CONNECTION = "connections"; public static final String ROUTING_CONNECTION = "connections";
public static final String ROUTING_PRIORITY = "prioritiesPeople";
public static final String ROUTING_MASTER_GENERAL = "generalList"; public static final String ROUTING_MASTER_GENERAL = "generalList";
public static final String ROUTING_MASTER_INPUT = "inputList"; public static final String ROUTING_MASTER_INPUT = "inputList";
public static final String ROUTING_MASTER_OUTPUT = "outputList"; public static final String ROUTING_MASTER_OUTPUT = "outputList";

View file

@ -7,7 +7,7 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -15,6 +15,7 @@ import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler; import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.ItemRouterButtonPacketProcessor; import WayofTime.bloodmagic.network.ItemRouterButtonPacketProcessor;
import WayofTime.bloodmagic.tile.container.ContainerItemRoutingNode; import WayofTime.bloodmagic.tile.container.ContainerItemRoutingNode;
import WayofTime.bloodmagic.tile.routing.TileFilteredRoutingNode;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class GuiItemRoutingNode extends GuiContainer public class GuiItemRoutingNode extends GuiContainer
@ -25,15 +26,28 @@ public class GuiItemRoutingNode extends GuiContainer
private GuiButton southButton; private GuiButton southButton;
private GuiButton westButton; private GuiButton westButton;
private GuiButton eastButton; private GuiButton eastButton;
private GuiButton incrementButton;
private GuiButton decrementButton;
private TileEntity inventory; private TileFilteredRoutingNode inventory;
public GuiItemRoutingNode(InventoryPlayer playerInventory, IInventory tileRoutingNode) public GuiItemRoutingNode(InventoryPlayer playerInventory, IInventory tileRoutingNode)
{ {
super(new ContainerItemRoutingNode(playerInventory, tileRoutingNode)); super(new ContainerItemRoutingNode(playerInventory, tileRoutingNode));
this.xSize = 176; this.xSize = 176;
this.ySize = 169; this.ySize = 169;
inventory = (TileEntity) tileRoutingNode; inventory = (TileFilteredRoutingNode) tileRoutingNode;
}
private int getCurrentActiveSlotPriority()
{
EnumFacing direction = EnumFacing.getFront(inventory.currentActiveSlot);
if (direction != null)
{
return inventory.getPriority(direction);
}
return 0;
} }
@Override @Override
@ -47,6 +61,9 @@ public class GuiItemRoutingNode extends GuiContainer
this.buttonList.add(this.southButton = new GuiButton(3, (this.width - this.xSize) / 2 + 151, (this.height - this.ySize) / 2 + 50, 18, 18, "S")); this.buttonList.add(this.southButton = new GuiButton(3, (this.width - this.xSize) / 2 + 151, (this.height - this.ySize) / 2 + 50, 18, 18, "S"));
this.buttonList.add(this.westButton = new GuiButton(4, (this.width - this.xSize) / 2 + 133, (this.height - this.ySize) / 2 + 32, 18, 18, "W")); this.buttonList.add(this.westButton = new GuiButton(4, (this.width - this.xSize) / 2 + 133, (this.height - this.ySize) / 2 + 32, 18, 18, "W"));
this.buttonList.add(this.eastButton = new GuiButton(5, (this.width - this.xSize) / 2 + 151, (this.height - this.ySize) / 2 + 32, 18, 18, "E")); this.buttonList.add(this.eastButton = new GuiButton(5, (this.width - this.xSize) / 2 + 151, (this.height - this.ySize) / 2 + 32, 18, 18, "E"));
this.buttonList.add(this.incrementButton = new GuiButton(6, (this.width - this.xSize) / 2 + 97, (this.height - this.ySize) / 2 + 14, 18, 17, "^"));
this.buttonList.add(this.decrementButton = new GuiButton(7, (this.width - this.xSize) / 2 + 97, (this.height - this.ySize) / 2 + 50, 18, 17, "v"));
disableDirectionalButton(inventory.currentActiveSlot);
} }
/** /**
@ -59,14 +76,31 @@ public class GuiItemRoutingNode extends GuiContainer
if (button.enabled) if (button.enabled)
{ {
BloodMagicPacketHandler.INSTANCE.sendToServer(new ItemRouterButtonPacketProcessor(button.id, inventory.getPos(), inventory.getWorld())); BloodMagicPacketHandler.INSTANCE.sendToServer(new ItemRouterButtonPacketProcessor(button.id, inventory.getPos(), inventory.getWorld()));
if (button.id < 6)
{
enableAllDirectionalButtons();
button.enabled = false;
}
} }
} }
private void enableAllDirectionalButtons()
{
for (GuiButton button : this.buttonList)
{
button.enabled = true;
}
}
private void disableDirectionalButton(int id)
{
this.buttonList.get(id).enabled = false;
}
@Override @Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{ {
// this.fontRendererObj.drawString(TextHelper.localize("tile.BloodMagic.soulForge.name"), 8, 5, 4210752); this.fontRendererObj.drawString("" + getCurrentActiveSlotPriority(), 98 + 5, 33 + 4, 0xFFFFFF);
// this.fontRendererObj.drawString(TextHelper.localize("container.inventory"), 8, 111, 4210752);
} }
@Override @Override

View file

@ -66,7 +66,19 @@ public class ItemRouterButtonPacketProcessor implements IMessage, IMessageHandle
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileFilteredRoutingNode) if (tile instanceof TileFilteredRoutingNode)
{ {
((TileFilteredRoutingNode) tile).swapFilters(buttonPress); if (buttonPress >= 6)
{
if (buttonPress == 6)
{
((TileFilteredRoutingNode) tile).incrementCurrentPriotiryToMaximum(9);
} else if (buttonPress == 7)
{
((TileFilteredRoutingNode) tile).decrementCurrentPriority();
}
} else
{
((TileFilteredRoutingNode) tile).swapFilters(buttonPress);
}
} }
} }
} }

View file

@ -88,7 +88,7 @@ public class DefaultItemFilter implements IItemFilter
* the input inventory to the output inventory. * the input inventory to the output inventory.
*/ */
@Override @Override
public void transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer) public int transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer)
{ {
boolean[] canAccessSlot = new boolean[accessedInventory.getSizeInventory()]; boolean[] canAccessSlot = new boolean[accessedInventory.getSizeInventory()];
if (accessedInventory instanceof ISidedInventory) if (accessedInventory instanceof ISidedInventory)
@ -141,7 +141,11 @@ public class DefaultItemFilter implements IItemFilter
maxTransfer -= changeAmount; maxTransfer -= changeAmount;
accessedInventory.setInventorySlotContents(slot, inputStack.stackSize <= 0 ? null : inputStack); //Sets the slot in the inventory accessedInventory.setInventorySlotContents(slot, inputStack.stackSize <= 0 ? null : inputStack); //Sets the slot in the inventory
return changeAmount;
} }
return 0;
} }
@Override @Override

View file

@ -26,7 +26,7 @@ public interface IItemFilter
* This method is only called on an input filter to transfer ItemStacks from * This method is only called on an input filter to transfer ItemStacks from
* the input inventory to the output inventory. * the input inventory to the output inventory.
*/ */
public void transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer); public int transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer);
public boolean doesStackMatchFilter(ItemStack testStack); public boolean doesStackMatchFilter(ItemStack testStack);

View file

@ -215,7 +215,7 @@ public class TestItemFilter implements IItemFilter
* the input inventory to the output inventory. * the input inventory to the output inventory.
*/ */
@Override @Override
public void transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer) public int transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer)
{ {
boolean[] canAccessSlot = new boolean[accessedInventory.getSizeInventory()]; boolean[] canAccessSlot = new boolean[accessedInventory.getSizeInventory()];
if (accessedInventory instanceof ISidedInventory) if (accessedInventory instanceof ISidedInventory)
@ -290,7 +290,11 @@ public class TestItemFilter implements IItemFilter
} }
} }
} }
return changeAmount;
} }
return 0;
} }
@Override @Override

View file

@ -1,5 +1,6 @@
package WayofTime.bloodmagic.tile.routing; package WayofTime.bloodmagic.tile.routing;
import WayofTime.bloodmagic.api.Constants;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -8,6 +9,7 @@ import net.minecraft.util.EnumFacing;
public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedInventory public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedInventory
{ {
public int currentActiveSlot = 0; public int currentActiveSlot = 0;
public int[] priorities = new int[6];
public TileFilteredRoutingNode(int size, String name) public TileFilteredRoutingNode(int size, String name)
{ {
@ -37,6 +39,11 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
{ {
super.readFromNBT(tag); super.readFromNBT(tag);
currentActiveSlot = tag.getInteger("currentSlot"); currentActiveSlot = tag.getInteger("currentSlot");
priorities = tag.getIntArray(Constants.NBT.ROUTING_PRIORITY);
if (priorities.length != 6)
{
priorities = new int[6];
}
} }
@Override @Override
@ -44,6 +51,7 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
{ {
super.writeToNBT(tag); super.writeToNBT(tag);
tag.setInteger("currentSlot", currentActiveSlot); tag.setInteger("currentSlot", currentActiveSlot);
tag.setIntArray(Constants.NBT.ROUTING_PRIORITY, priorities);
} }
public void swapFilters(int requestedSlot) public void swapFilters(int requestedSlot)
@ -72,4 +80,20 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
{ {
return false; return false;
} }
@Override
public int getPriority(EnumFacing side)
{
return priorities[side.getIndex()];
}
public void incrementCurrentPriotiryToMaximum(int max)
{
priorities[currentActiveSlot] = Math.min(priorities[currentActiveSlot] + 1, max);
}
public void decrementCurrentPriority()
{
priorities[currentActiveSlot] = Math.max(priorities[currentActiveSlot] - 1, 0);
}
} }

View file

@ -114,6 +114,8 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
} }
} }
int maxTransfer = 8;
for (Entry<Integer, List<IItemFilter>> outputEntry : outputMap.entrySet()) for (Entry<Integer, List<IItemFilter>> outputEntry : outputMap.entrySet())
{ {
List<IItemFilter> outputList = outputEntry.getValue(); List<IItemFilter> outputList = outputEntry.getValue();
@ -124,7 +126,11 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
List<IItemFilter> inputList = inputEntry.getValue(); List<IItemFilter> inputList = inputEntry.getValue();
for (IItemFilter inputFilter : inputList) for (IItemFilter inputFilter : inputList)
{ {
inputFilter.transferThroughInputFilter(outputFilter, 8); maxTransfer -= inputFilter.transferThroughInputFilter(outputFilter, maxTransfer);
if (maxTransfer <= 0)
{
return;
}
} }
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB