Initial framework for the item routing is completed
This commit is contained in:
parent
eaefd89287
commit
652b6a45fd
src/main/java/WayofTime/bloodmagic
|
@ -0,0 +1,10 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IInputItemRoutingNode extends IItemRoutingNode
|
||||
{
|
||||
public boolean isInput(EnumFacing side);
|
||||
|
||||
public IItemFilter getInputFilterForSide(EnumFacing side);
|
||||
}
|
|
@ -26,7 +26,7 @@ public interface IItemFilter
|
|||
* This method is only called on an input filter to transfer ItemStacks from
|
||||
* the input inventory to the output inventory.
|
||||
*/
|
||||
public void transferThroughInputFilter(TestItemFilter outputFilter);
|
||||
public void transferThroughInputFilter(IItemFilter outputFilter);
|
||||
|
||||
public boolean doesStackMatchFilter(ItemStack testStack);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.util.EnumFacing;
|
|||
|
||||
public interface IItemRoutingNode extends IRoutingNode
|
||||
{
|
||||
IItemFilter generateFilterForSide(EnumFacing side); //Will later return an IItemFilter once fully implemented.
|
||||
|
||||
boolean isInventoryConnectedToSide(EnumFacing side);
|
||||
|
||||
int getPriority(EnumFacing side);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IOutputItemRoutingNode extends IItemRoutingNode
|
||||
{
|
||||
public boolean isOutput(EnumFacing side);
|
||||
|
||||
public IItemFilter getOutputFilterForSide(EnumFacing side);
|
||||
}
|
|
@ -205,7 +205,7 @@ public class TestItemFilter implements IItemFilter
|
|||
* This method is only called on an input filter to transfer ItemStacks from
|
||||
* the input inventory to the output inventory.
|
||||
*/
|
||||
public void transferThroughInputFilter(TestItemFilter outputFilter)
|
||||
public void transferThroughInputFilter(IItemFilter outputFilter)
|
||||
{
|
||||
boolean[] canAccessSlot = new boolean[accessedInventory.getSizeInventory()];
|
||||
if (accessedInventory instanceof ISidedInventory)
|
||||
|
|
|
@ -3,16 +3,17 @@ package WayofTime.bloodmagic.routing;
|
|||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.tile.routing.TileInputRoutingNode;
|
||||
import WayofTime.bloodmagic.tile.routing.TileOutputRoutingNode;
|
||||
|
||||
public class TileMasterRoutingNode extends TileEntity implements IMasterRoutingNode, ITickable
|
||||
{
|
||||
|
@ -27,36 +28,94 @@ public class TileMasterRoutingNode extends TileEntity implements IMasterRoutingN
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
// if (worldObj.isRemote || worldObj.getTotalWorldTime() % tickRate != 0) //Temporary tick rate solver
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Map<Integer, List<IItemFilter>> outputMap = new HashMap<Integer, List<IItemFilter>>();
|
||||
//
|
||||
// for (BlockPos outputPos : outputNodeList)
|
||||
// {
|
||||
// TileEntity outputTile = worldObj.getTileEntity(outputPos);
|
||||
// if (outputTile instanceof TileOutputRoutingNode && this.isConnected(new LinkedList<BlockPos>(), outputPos))
|
||||
// {
|
||||
// TileOutputRoutingNode outputNode = (TileOutputRoutingNode) outputTile;
|
||||
//
|
||||
// for (EnumFacing facing : EnumFacing.VALUES)
|
||||
// {
|
||||
// if (!outputNode.isInventoryConnectedToSide(facing))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// TileEntity tile = worldObj.getTileEntity(outputPos.offset(facing));
|
||||
// if (!(tile instanceof IInventory))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if (worldObj.isRemote || worldObj.getTotalWorldTime() % tickRate != 0) //Temporary tick rate solver
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Integer, List<IItemFilter>> outputMap = new HashMap<Integer, List<IItemFilter>>();
|
||||
|
||||
for (BlockPos outputPos : outputNodeList)
|
||||
{
|
||||
TileEntity outputTile = worldObj.getTileEntity(outputPos);
|
||||
if (outputTile instanceof IOutputItemRoutingNode && this.isConnected(new LinkedList<BlockPos>(), outputPos))
|
||||
{
|
||||
IOutputItemRoutingNode outputNode = (IOutputItemRoutingNode) outputTile;
|
||||
|
||||
for (EnumFacing facing : EnumFacing.VALUES)
|
||||
{
|
||||
if (!outputNode.isInventoryConnectedToSide(facing) || !outputNode.isOutput(facing))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IItemFilter filter = outputNode.getOutputFilterForSide(facing);
|
||||
if (filter != null)
|
||||
{
|
||||
int priority = outputNode.getPriority(facing);
|
||||
if (outputMap.containsKey(priority))
|
||||
{
|
||||
outputMap.get(priority).add(filter);
|
||||
} else
|
||||
{
|
||||
List<IItemFilter> filterList = new LinkedList<IItemFilter>();
|
||||
filterList.add(filter);
|
||||
outputMap.put(priority, filterList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<Integer, List<IItemFilter>> inputMap = new HashMap<Integer, List<IItemFilter>>();
|
||||
|
||||
for (BlockPos inputPos : inputNodeList)
|
||||
{
|
||||
TileEntity inputTile = worldObj.getTileEntity(inputPos);
|
||||
if (inputTile instanceof IInputItemRoutingNode && this.isConnected(new LinkedList<BlockPos>(), inputPos))
|
||||
{
|
||||
IInputItemRoutingNode inputNode = (IInputItemRoutingNode) inputTile;
|
||||
|
||||
for (EnumFacing facing : EnumFacing.VALUES)
|
||||
{
|
||||
if (!inputNode.isInventoryConnectedToSide(facing) || !inputNode.isInput(facing))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IItemFilter filter = inputNode.getInputFilterForSide(facing);
|
||||
if (filter != null)
|
||||
{
|
||||
int priority = inputNode.getPriority(facing);
|
||||
if (inputMap.containsKey(priority))
|
||||
{
|
||||
inputMap.get(priority).add(filter);
|
||||
} else
|
||||
{
|
||||
List<IItemFilter> filterList = new LinkedList<IItemFilter>();
|
||||
filterList.add(filter);
|
||||
inputMap.put(priority, filterList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Entry<Integer, List<IItemFilter>> outputEntry : outputMap.entrySet())
|
||||
{
|
||||
List<IItemFilter> outputList = outputEntry.getValue();
|
||||
for (IItemFilter outputFilter : outputList)
|
||||
{
|
||||
for (Entry<Integer, List<IItemFilter>> inputEntry : inputMap.entrySet())
|
||||
{
|
||||
List<IItemFilter> inputList = inputEntry.getValue();
|
||||
for (IItemFilter inputFilter : inputList)
|
||||
{
|
||||
inputFilter.transferThroughInputFilter(outputFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,11 +246,11 @@ public class TileMasterRoutingNode extends TileEntity implements IMasterRoutingN
|
|||
{
|
||||
generalNodeList.add(newPos);
|
||||
}
|
||||
if (node instanceof TileInputRoutingNode && !inputNodeList.contains(newPos))
|
||||
if (node instanceof IInputItemRoutingNode && !inputNodeList.contains(newPos))
|
||||
{
|
||||
inputNodeList.add(newPos);
|
||||
}
|
||||
if (node instanceof TileOutputRoutingNode && !outputNodeList.contains(newPos))
|
||||
if (node instanceof IOutputItemRoutingNode && !outputNodeList.contains(newPos))
|
||||
{
|
||||
outputNodeList.add(newPos);
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ public class ContainerItemRoutingNode extends Container
|
|||
{
|
||||
if (slotStack != null)
|
||||
{
|
||||
GhostItemHelper.decrementGhostAmout(slotStack, 1);
|
||||
GhostItemHelper.decrementGhostAmount(slotStack, 1);
|
||||
if (GhostItemHelper.getItemGhostAmount(slotStack) < 0)
|
||||
{
|
||||
slot.putStack(null);
|
||||
|
|
|
@ -14,6 +14,18 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
|
|||
super(size, name);
|
||||
}
|
||||
|
||||
public ItemStack getFilterStack(EnumFacing side)
|
||||
{
|
||||
int index = side.getIndex();
|
||||
if (currentActiveSlot == index)
|
||||
{
|
||||
return getStackInSlot(0);
|
||||
} else
|
||||
{
|
||||
return getStackInSlot(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,63 @@
|
|||
package WayofTime.bloodmagic.tile.routing;
|
||||
|
||||
public class TileInputRoutingNode extends TileFilteredRoutingNode
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import WayofTime.bloodmagic.item.inventory.ItemInventory;
|
||||
import WayofTime.bloodmagic.routing.IInputItemRoutingNode;
|
||||
import WayofTime.bloodmagic.routing.IItemFilter;
|
||||
import WayofTime.bloodmagic.routing.TestItemFilter;
|
||||
import WayofTime.bloodmagic.util.GhostItemHelper;
|
||||
|
||||
public class TileInputRoutingNode extends TileFilteredRoutingNode implements IInputItemRoutingNode
|
||||
{
|
||||
public TileInputRoutingNode()
|
||||
{
|
||||
super(7, "inputNode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInput(EnumFacing side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemFilter getInputFilterForSide(EnumFacing side)
|
||||
{
|
||||
ItemStack filterStack = this.getFilterStack(side);
|
||||
|
||||
if (filterStack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(pos.offset(side));
|
||||
if (tile instanceof IInventory)
|
||||
{
|
||||
IItemFilter testFilter = new TestItemFilter();
|
||||
List<ItemStack> filteredList = new LinkedList<ItemStack>();
|
||||
ItemInventory inv = new ItemInventory(filterStack, 9, ""); //TODO: Change to grab the filter from the Item later.
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if (stack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
filteredList.add(GhostItemHelper.getStackFromGhost(stack));
|
||||
}
|
||||
|
||||
testFilter.initializeFilter(filteredList, (IInventory) tile, side, false);
|
||||
|
||||
return testFilter;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,63 @@
|
|||
package WayofTime.bloodmagic.tile.routing;
|
||||
|
||||
public class TileOutputRoutingNode extends TileFilteredRoutingNode
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import WayofTime.bloodmagic.item.inventory.ItemInventory;
|
||||
import WayofTime.bloodmagic.routing.IItemFilter;
|
||||
import WayofTime.bloodmagic.routing.IOutputItemRoutingNode;
|
||||
import WayofTime.bloodmagic.routing.TestItemFilter;
|
||||
import WayofTime.bloodmagic.util.GhostItemHelper;
|
||||
|
||||
public class TileOutputRoutingNode extends TileFilteredRoutingNode implements IOutputItemRoutingNode
|
||||
{
|
||||
public TileOutputRoutingNode()
|
||||
{
|
||||
super(7, "outputNode");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutput(EnumFacing side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemFilter getOutputFilterForSide(EnumFacing side)
|
||||
{
|
||||
ItemStack filterStack = this.getFilterStack(side);
|
||||
|
||||
if (filterStack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(pos.offset(side));
|
||||
if (tile instanceof IInventory)
|
||||
{
|
||||
IItemFilter testFilter = new TestItemFilter();
|
||||
List<ItemStack> filteredList = new LinkedList<ItemStack>();
|
||||
ItemInventory inv = new ItemInventory(filterStack, 9, ""); //TODO: Change to grab the filter from the Item later.
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if (stack == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
filteredList.add(GhostItemHelper.getStackFromGhost(stack));
|
||||
}
|
||||
|
||||
testFilter.initializeFilter(filteredList, (IInventory) tile, side, true);
|
||||
|
||||
return testFilter;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import net.minecraft.util.BlockPos;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.routing.IItemFilter;
|
||||
import WayofTime.bloodmagic.routing.IItemRoutingNode;
|
||||
import WayofTime.bloodmagic.routing.IMasterRoutingNode;
|
||||
import WayofTime.bloodmagic.routing.IRoutingNode;
|
||||
|
@ -168,13 +167,12 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
|
|||
@Override
|
||||
public boolean isInventoryConnectedToSide(EnumFacing side)
|
||||
{
|
||||
//TODO: Implement connections for side
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemFilter generateFilterForSide(EnumFacing side)
|
||||
public int getPriority(EnumFacing side)
|
||||
{
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,10 +41,22 @@ public class GhostItemHelper
|
|||
setItemGhostAmount(stack, amount);
|
||||
}
|
||||
|
||||
public static void decrementGhostAmout(ItemStack stack, int value)
|
||||
public static void decrementGhostAmount(ItemStack stack, int value)
|
||||
{
|
||||
int amount = getItemGhostAmount(stack);
|
||||
amount -= value;
|
||||
setItemGhostAmount(stack, amount);
|
||||
}
|
||||
|
||||
public static ItemStack getStackFromGhost(ItemStack ghostStack)
|
||||
{
|
||||
ItemStack newStack = ghostStack.copy();
|
||||
NBTHelper.checkNBT(newStack);
|
||||
NBTTagCompound tag = newStack.getTagCompound();
|
||||
int amount = getItemGhostAmount(ghostStack);
|
||||
tag.removeTag(Constants.NBT.GHOST_STACK_SIZE);
|
||||
newStack.stackSize = amount;
|
||||
|
||||
return newStack;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue