Run formatter
This commit is contained in:
parent
61c44a831b
commit
08258fd6ef
606 changed files with 13464 additions and 22975 deletions
|
@ -1,43 +1,37 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This particular implementation of IItemFilter allows any item to be drained
|
||||
* from or inputed to the connected inventory. Every stack is accepted here!
|
||||
* We're basically Olive Gardens.
|
||||
*
|
||||
*
|
||||
* @author WayofTime
|
||||
*
|
||||
*/
|
||||
public class DefaultItemFilter implements IItemFilter
|
||||
{
|
||||
public class DefaultItemFilter implements IItemFilter {
|
||||
protected TileEntity accessedTile;
|
||||
protected IItemHandler itemHandler;
|
||||
|
||||
/**
|
||||
* Initializes the filter so that it knows what it wants to fulfill.
|
||||
*
|
||||
* @param filteredList
|
||||
* - The list of ItemStacks that the filter is set to.
|
||||
* @param itemHandler
|
||||
* - The inventory that is being accessed. This inventory is either
|
||||
* being pulled from or pushed to.
|
||||
* @param isFilterOutput
|
||||
* - Tells the filter what actions to expect. If true, it should be
|
||||
* initialized as an output filter. If false, it should be
|
||||
* initialized as an input filter.
|
||||
*
|
||||
* @param filteredList - The list of ItemStacks that the filter is set to.
|
||||
* @param itemHandler - The inventory that is being accessed. This inventory is either
|
||||
* being pulled from or pushed to.
|
||||
* @param isFilterOutput - Tells the filter what actions to expect. If true, it should be
|
||||
* initialized as an output filter. If false, it should be
|
||||
* initialized as an input filter.
|
||||
*/
|
||||
@Override
|
||||
public void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IItemHandler itemHandler, boolean isFilterOutput)
|
||||
{
|
||||
public void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IItemHandler itemHandler, boolean isFilterOutput) {
|
||||
this.accessedTile = tile;
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
@ -46,20 +40,16 @@ public class DefaultItemFilter implements IItemFilter
|
|||
* This method is only called when the output inventory this filter is
|
||||
* managing receives an ItemStack. Should only really be called by the Input
|
||||
* filter via it's transfer method.
|
||||
*
|
||||
* @param inputStack
|
||||
* - The stack to transfer
|
||||
*
|
||||
*
|
||||
* @param inputStack - The stack to transfer
|
||||
* @return - The remainder of the stack after it has been absorbed into the
|
||||
* inventory.
|
||||
* inventory.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack transferStackThroughOutputFilter(ItemStack inputStack)
|
||||
{
|
||||
public ItemStack transferStackThroughOutputFilter(ItemStack inputStack) {
|
||||
int allowedAmount = inputStack.getCount(); //This is done to make the migration to a maximum amount transfered a lot easier
|
||||
|
||||
if (allowedAmount <= 0)
|
||||
{
|
||||
if (allowedAmount <= 0) {
|
||||
return inputStack;
|
||||
}
|
||||
|
||||
|
@ -83,10 +73,8 @@ public class DefaultItemFilter implements IItemFilter
|
|||
* the input inventory to the output inventory.
|
||||
*/
|
||||
@Override
|
||||
public int transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer)
|
||||
{
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
|
||||
{
|
||||
public int transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer) {
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
|
||||
ItemStack inputStack = itemHandler.getStackInSlot(slot);
|
||||
if (inputStack.isEmpty() || itemHandler.extractItem(slot, inputStack.getCount(), true).isEmpty())//(accessedInventory instanceof ISidedInventory && !((ISidedInventory) accessedInventory).canExtractItem(slot, inputStack, accessedSide)))
|
||||
{
|
||||
|
@ -100,8 +88,7 @@ public class DefaultItemFilter implements IItemFilter
|
|||
ItemStack remainderStack = outputFilter.transferStackThroughOutputFilter(testStack);
|
||||
int changeAmount = allowedAmount - (remainderStack.isEmpty() ? 0 : remainderStack.getCount());
|
||||
|
||||
if (!remainderStack.isEmpty() && remainderStack.getCount() == allowedAmount)
|
||||
{
|
||||
if (!remainderStack.isEmpty() && remainderStack.getCount() == allowedAmount) {
|
||||
//Nothing has changed. Moving on!
|
||||
continue;
|
||||
}
|
||||
|
@ -119,14 +106,12 @@ public class DefaultItemFilter implements IItemFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doesStackMatchFilter(ItemStack testStack)
|
||||
{
|
||||
public boolean doesStackMatchFilter(ItemStack testStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack)
|
||||
{
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
public interface IFluidFilter extends IRoutingFilter
|
||||
{
|
||||
import java.util.List;
|
||||
|
||||
public interface IFluidFilter extends IRoutingFilter {
|
||||
void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IFluidHandler fluidHandler, boolean isFilterOutput);
|
||||
|
||||
/**
|
||||
* This method is only called when the output tank this filter is managing
|
||||
* receives an ItemStack. Should only really be called by the Input filter
|
||||
* via it's transfer method.
|
||||
*
|
||||
* @param fluidStack
|
||||
* - The stack to filter
|
||||
*
|
||||
*
|
||||
* @param fluidStack - The stack to filter
|
||||
* @return - The remainder of the stack after it has been absorbed into the
|
||||
* tank.
|
||||
* tank.
|
||||
*/
|
||||
FluidStack transferStackThroughOutputFilter(FluidStack fluidStack);
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ package WayofTime.bloodmagic.routing;
|
|||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IFluidRoutingNode extends IRoutingNode
|
||||
{
|
||||
public interface IFluidRoutingNode extends IRoutingNode {
|
||||
boolean isTankConnectedToSide(EnumFacing side);
|
||||
|
||||
int getPriority(EnumFacing side);
|
||||
|
|
|
@ -2,8 +2,7 @@ package WayofTime.bloodmagic.routing;
|
|||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IInputFluidRoutingNode extends IFluidRoutingNode
|
||||
{
|
||||
public interface IInputFluidRoutingNode extends IFluidRoutingNode {
|
||||
boolean isFluidInput(EnumFacing side);
|
||||
|
||||
IFluidFilter getInputFluidFilterForSide(EnumFacing side);
|
||||
|
|
|
@ -2,8 +2,7 @@ package WayofTime.bloodmagic.routing;
|
|||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IInputItemRoutingNode extends IItemRoutingNode
|
||||
{
|
||||
public interface IInputItemRoutingNode extends IItemRoutingNode {
|
||||
boolean isInput(EnumFacing side);
|
||||
|
||||
IItemFilter getInputFilterForSide(EnumFacing side);
|
||||
|
|
|
@ -1,25 +1,22 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public interface IItemFilter extends IRoutingFilter
|
||||
{
|
||||
import java.util.List;
|
||||
|
||||
public interface IItemFilter extends IRoutingFilter {
|
||||
void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IItemHandler itemHandler, boolean isFilterOutput);
|
||||
|
||||
/**
|
||||
* This method is only called when the output inventory this filter is
|
||||
* managing receives an ItemStack. Should only really be called by the Input
|
||||
* filter via it's transfer method.
|
||||
*
|
||||
* @param inputStack
|
||||
* - The stack to filter
|
||||
*
|
||||
*
|
||||
* @param inputStack - The stack to filter
|
||||
* @return - The remainder of the stack after it has been absorbed into the
|
||||
* inventory.
|
||||
* inventory.
|
||||
*/
|
||||
ItemStack transferStackThroughOutputFilter(ItemStack inputStack);
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ package WayofTime.bloodmagic.routing;
|
|||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IItemRoutingNode extends IRoutingNode
|
||||
{
|
||||
public interface IItemRoutingNode extends IRoutingNode {
|
||||
boolean isInventoryConnectedToSide(EnumFacing side);
|
||||
|
||||
int getPriority(EnumFacing side);
|
||||
|
|
|
@ -4,8 +4,7 @@ import net.minecraft.util.math.BlockPos;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public interface IMasterRoutingNode extends IRoutingNode
|
||||
{
|
||||
public interface IMasterRoutingNode extends IRoutingNode {
|
||||
boolean isConnected(List<BlockPos> path, BlockPos nodePos);
|
||||
|
||||
void addNodeToList(IRoutingNode node);
|
||||
|
|
|
@ -2,8 +2,7 @@ package WayofTime.bloodmagic.routing;
|
|||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IOutputFluidRoutingNode extends IFluidRoutingNode
|
||||
{
|
||||
public interface IOutputFluidRoutingNode extends IFluidRoutingNode {
|
||||
boolean isFluidOutput(EnumFacing side);
|
||||
|
||||
IFluidFilter getOutputFluidFilterForSide(EnumFacing side);
|
||||
|
|
|
@ -2,8 +2,7 @@ package WayofTime.bloodmagic.routing;
|
|||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
public interface IOutputItemRoutingNode extends IItemRoutingNode
|
||||
{
|
||||
public interface IOutputItemRoutingNode extends IItemRoutingNode {
|
||||
boolean isOutput(EnumFacing side);
|
||||
|
||||
IItemFilter getOutputFilterForSide(EnumFacing side);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
public interface IRoutingFilter
|
||||
{
|
||||
public interface IRoutingFilter {
|
||||
|
||||
}
|
||||
|
|
|
@ -5,8 +5,7 @@ import net.minecraft.world.World;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public interface IRoutingNode
|
||||
{
|
||||
public interface IRoutingNode {
|
||||
void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master);
|
||||
|
||||
BlockPos getBlockPos();
|
||||
|
|
|
@ -2,15 +2,11 @@ package WayofTime.bloodmagic.routing;
|
|||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class IgnoreNBTItemFilter extends TestItemFilter
|
||||
{
|
||||
public class IgnoreNBTItemFilter extends TestItemFilter {
|
||||
@Override
|
||||
public boolean doesStackMatchFilter(ItemStack testStack)
|
||||
{
|
||||
for (ItemStack filterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, testStack))
|
||||
{
|
||||
public boolean doesStackMatchFilter(ItemStack testStack) {
|
||||
for (ItemStack filterStack : requestList) {
|
||||
if (doStacksMatch(filterStack, testStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +15,7 @@ public class IgnoreNBTItemFilter extends TestItemFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack)
|
||||
{
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack) {
|
||||
return ItemStack.areItemsEqual(filterStack, testStack);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,10 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
public class ModIdItemFilter extends TestItemFilter
|
||||
{
|
||||
public class ModIdItemFilter extends TestItemFilter {
|
||||
@Override
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack)
|
||||
{
|
||||
if (ItemStack.areItemsEqualIgnoreDurability(filterStack, testStack))
|
||||
{
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack) {
|
||||
if (ItemStack.areItemsEqualIgnoreDurability(filterStack, testStack)) {
|
||||
String keyId = getModID(filterStack.getItem());
|
||||
String checkedId = getModID(testStack.getItem());
|
||||
return keyId.equals(checkedId);
|
||||
|
@ -20,8 +17,7 @@ public class ModIdItemFilter extends TestItemFilter
|
|||
return false;
|
||||
}
|
||||
|
||||
public String getModID(Item item)
|
||||
{
|
||||
public String getModID(Item item) {
|
||||
ResourceLocation resource = ForgeRegistries.ITEMS.getKey(item);
|
||||
return resource.getResourceDomain();
|
||||
}
|
||||
|
|
|
@ -4,17 +4,13 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class NodeHelper
|
||||
{
|
||||
public static boolean isNodeConnectionEnabled(World world, IRoutingNode node, BlockPos testPos)
|
||||
{
|
||||
if (!node.isConnectionEnabled(testPos))
|
||||
{
|
||||
public class NodeHelper {
|
||||
public static boolean isNodeConnectionEnabled(World world, IRoutingNode node, BlockPos testPos) {
|
||||
if (!node.isConnectionEnabled(testPos)) {
|
||||
return false;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(testPos);
|
||||
if (!(tile instanceof IRoutingNode))
|
||||
{
|
||||
if (!(tile instanceof IRoutingNode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,15 +3,11 @@ package WayofTime.bloodmagic.routing;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class OreDictItemFilter extends TestItemFilter
|
||||
{
|
||||
public class OreDictItemFilter extends TestItemFilter {
|
||||
@Override
|
||||
public boolean doesStackMatchFilter(ItemStack testStack)
|
||||
{
|
||||
for (ItemStack filterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, testStack))
|
||||
{
|
||||
public boolean doesStackMatchFilter(ItemStack testStack) {
|
||||
for (ItemStack filterStack : requestList) {
|
||||
if (doStacksMatch(filterStack, testStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -20,22 +16,17 @@ public class OreDictItemFilter extends TestItemFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack)
|
||||
{
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack) {
|
||||
int[] filterIds = OreDictionary.getOreIDs(filterStack);
|
||||
int[] testIds = OreDictionary.getOreIDs(testStack);
|
||||
|
||||
if (filterIds.length <= 0 || testIds.length <= 0)
|
||||
{
|
||||
if (filterIds.length <= 0 || testIds.length <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int filterId : filterIds)
|
||||
{
|
||||
for (int testId : testIds)
|
||||
{
|
||||
if (filterId == testId)
|
||||
{
|
||||
for (int filterId : filterIds) {
|
||||
for (int testId : testIds) {
|
||||
if (filterId == testId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -14,55 +10,46 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
|
|||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class RoutingFluidFilter implements IFluidFilter
|
||||
{
|
||||
public class RoutingFluidFilter implements IFluidFilter {
|
||||
protected List<FluidStack> requestList;
|
||||
protected TileEntity accessedTile;
|
||||
protected IFluidHandler fluidHandler;
|
||||
|
||||
@Override
|
||||
public void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IFluidHandler fluidHandler, boolean isFilterOutput)
|
||||
{
|
||||
public void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IFluidHandler fluidHandler, boolean isFilterOutput) {
|
||||
this.accessedTile = tile;
|
||||
this.fluidHandler = fluidHandler;
|
||||
if (isFilterOutput)
|
||||
{
|
||||
if (isFilterOutput) {
|
||||
//The requestList contains a list of how much can be extracted.
|
||||
requestList = new ArrayList<FluidStack>();
|
||||
for (ItemStack filterStack : filteredList)
|
||||
{
|
||||
for (ItemStack filterStack : filteredList) {
|
||||
FluidStack fluidFilterStack = getFluidStackFromItemStack(filterStack);
|
||||
if (fluidFilterStack != null)
|
||||
{
|
||||
if (fluidFilterStack != null) {
|
||||
requestList.add(fluidFilterStack);
|
||||
}
|
||||
}
|
||||
|
||||
IFluidTankProperties[] properties = fluidHandler.getTankProperties();
|
||||
|
||||
for (IFluidTankProperties property : properties)
|
||||
{
|
||||
for (IFluidTankProperties property : properties) {
|
||||
FluidStack containedStack = property.getContents();
|
||||
if (containedStack != null)
|
||||
{
|
||||
for (FluidStack fluidFilterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(fluidFilterStack, containedStack))
|
||||
{
|
||||
if (containedStack != null) {
|
||||
for (FluidStack fluidFilterStack : requestList) {
|
||||
if (doStacksMatch(fluidFilterStack, containedStack)) {
|
||||
fluidFilterStack.amount = Math.max(fluidFilterStack.amount - containedStack.amount, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
requestList = new ArrayList<FluidStack>();
|
||||
for (ItemStack filterStack : filteredList)
|
||||
{
|
||||
for (ItemStack filterStack : filteredList) {
|
||||
FluidStack fluidFilterStack = getFluidStackFromItemStack(filterStack);
|
||||
if (fluidFilterStack != null)
|
||||
{
|
||||
if (fluidFilterStack != null) {
|
||||
fluidFilterStack.amount *= -1;
|
||||
requestList.add(fluidFilterStack);
|
||||
}
|
||||
|
@ -70,15 +57,11 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
|
||||
IFluidTankProperties[] properties = fluidHandler.getTankProperties();
|
||||
|
||||
for (IFluidTankProperties property : properties)
|
||||
{
|
||||
for (IFluidTankProperties property : properties) {
|
||||
FluidStack containedStack = property.getContents();
|
||||
if (containedStack != null)
|
||||
{
|
||||
for (FluidStack fluidFilterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(fluidFilterStack, containedStack))
|
||||
{
|
||||
if (containedStack != null) {
|
||||
for (FluidStack fluidFilterStack : requestList) {
|
||||
if (doStacksMatch(fluidFilterStack, containedStack)) {
|
||||
fluidFilterStack.amount += containedStack.amount;
|
||||
}
|
||||
}
|
||||
|
@ -87,35 +70,20 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FluidStack getFluidStackFromItemStack(ItemStack inputStack)
|
||||
{
|
||||
FluidStack fluidStack = FluidUtil.getFluidContained(inputStack);
|
||||
if (fluidStack == null)
|
||||
return null;
|
||||
|
||||
fluidStack.amount = inputStack.getCount();
|
||||
return fluidStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives the remainder~
|
||||
*/
|
||||
@Override
|
||||
public FluidStack transferStackThroughOutputFilter(FluidStack fluidStack)
|
||||
{
|
||||
public FluidStack transferStackThroughOutputFilter(FluidStack fluidStack) {
|
||||
int allowedAmount = 0;
|
||||
for (FluidStack filterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, fluidStack))
|
||||
{
|
||||
for (FluidStack filterStack : requestList) {
|
||||
if (doStacksMatch(filterStack, fluidStack)) {
|
||||
allowedAmount = Math.min(filterStack.amount, fluidStack.amount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allowedAmount <= 0)
|
||||
{
|
||||
if (allowedAmount <= 0) {
|
||||
return fluidStack;
|
||||
}
|
||||
|
||||
|
@ -124,14 +92,11 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
copyStack.amount = fluidStack.amount - filledAmount;
|
||||
|
||||
Iterator<FluidStack> itr = requestList.iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
while (itr.hasNext()) {
|
||||
FluidStack filterStack = itr.next();
|
||||
if (doStacksMatch(filterStack, copyStack))
|
||||
{
|
||||
if (doStacksMatch(filterStack, copyStack)) {
|
||||
filterStack.amount -= filledAmount;
|
||||
if (filterStack.amount <= 0)
|
||||
{
|
||||
if (filterStack.amount <= 0) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
@ -145,13 +110,10 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public int transferThroughInputFilter(IFluidFilter outputFilter, int maxTransfer)
|
||||
{
|
||||
for (FluidStack filterFluidStack : requestList)
|
||||
{
|
||||
public int transferThroughInputFilter(IFluidFilter outputFilter, int maxTransfer) {
|
||||
for (FluidStack filterFluidStack : requestList) {
|
||||
int allowedAmount = Math.min(filterFluidStack.amount, maxTransfer);
|
||||
if (allowedAmount <= 0)
|
||||
{
|
||||
if (allowedAmount <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -163,8 +125,7 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
FluidStack remainderStack = outputFilter.transferStackThroughOutputFilter(drainStack);
|
||||
int drained = remainderStack == null ? copyStack.amount : (copyStack.amount - remainderStack.amount);
|
||||
|
||||
if (drained > 0)
|
||||
{
|
||||
if (drained > 0) {
|
||||
drainStack.amount = drained;
|
||||
|
||||
fluidHandler.drain(drainStack, true);
|
||||
|
@ -172,14 +133,11 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
}
|
||||
|
||||
Iterator<FluidStack> itr = requestList.iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
while (itr.hasNext()) {
|
||||
FluidStack filterStack = itr.next();
|
||||
if (doStacksMatch(filterStack, copyStack))
|
||||
{
|
||||
if (doStacksMatch(filterStack, copyStack)) {
|
||||
filterStack.amount -= drained;
|
||||
if (filterStack.amount <= 0)
|
||||
{
|
||||
if (filterStack.amount <= 0) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
@ -197,12 +155,9 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doesStackMatchFilter(FluidStack testStack)
|
||||
{
|
||||
for (FluidStack filterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, testStack))
|
||||
{
|
||||
public boolean doesStackMatchFilter(FluidStack testStack) {
|
||||
for (FluidStack filterStack : requestList) {
|
||||
if (doStacksMatch(filterStack, testStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -211,8 +166,17 @@ public class RoutingFluidFilter implements IFluidFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doStacksMatch(FluidStack filterStack, FluidStack testStack)
|
||||
{
|
||||
public boolean doStacksMatch(FluidStack filterStack, FluidStack testStack) {
|
||||
return testStack != null && filterStack.getFluid() == testStack.getFluid();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FluidStack getFluidStackFromItemStack(ItemStack inputStack) {
|
||||
FluidStack fluidStack = FluidUtil.getFluidContained(inputStack);
|
||||
if (fluidStack == null)
|
||||
return null;
|
||||
|
||||
fluidStack.amount = inputStack.getCount();
|
||||
return fluidStack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import WayofTime.bloodmagic.util.GhostItemHelper;
|
||||
import WayofTime.bloodmagic.util.Utils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This particular implementation of IItemFilter checks to make sure that a) as
|
||||
* an output filter it will fill until the requested amount and b) as an input
|
||||
* filter it will only syphon until the requested amount.
|
||||
*
|
||||
*
|
||||
* @author WayofTime
|
||||
*
|
||||
*/
|
||||
public class TestItemFilter implements IItemFilter
|
||||
{
|
||||
public class TestItemFilter implements IItemFilter {
|
||||
/*
|
||||
* This list acts as the way the filter keeps track of its contents. For the
|
||||
* case of an output filter, it holds a list of ItemStacks that needs to be
|
||||
|
@ -33,73 +30,56 @@ public class TestItemFilter implements IItemFilter
|
|||
|
||||
/**
|
||||
* Initializes the filter so that it knows what it wants to fulfill.
|
||||
*
|
||||
* @param filteredList
|
||||
* - The list of ItemStacks that the filter is set to.
|
||||
* @param tile
|
||||
* - The inventory that is being accessed. This inventory is either
|
||||
* being pulled from or pushed to.
|
||||
* @param itemHandler
|
||||
* - The item handler
|
||||
* @param isFilterOutput
|
||||
* - Tells the filter what actions to expect. If true, it should be
|
||||
* initialized as an output filter. If false, it should be
|
||||
* initialized as an input filter.
|
||||
*
|
||||
* @param filteredList - The list of ItemStacks that the filter is set to.
|
||||
* @param tile - The inventory that is being accessed. This inventory is either
|
||||
* being pulled from or pushed to.
|
||||
* @param itemHandler - The item handler
|
||||
* @param isFilterOutput - Tells the filter what actions to expect. If true, it should be
|
||||
* initialized as an output filter. If false, it should be
|
||||
* initialized as an input filter.
|
||||
*/
|
||||
@Override
|
||||
public void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IItemHandler itemHandler, boolean isFilterOutput)
|
||||
{
|
||||
public void initializeFilter(List<ItemStack> filteredList, TileEntity tile, IItemHandler itemHandler, boolean isFilterOutput) {
|
||||
this.accessedTile = tile;
|
||||
this.itemHandler = itemHandler;
|
||||
if (isFilterOutput)
|
||||
{
|
||||
if (isFilterOutput) {
|
||||
requestList = filteredList;
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
|
||||
{
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
|
||||
ItemStack checkedStack = itemHandler.getStackInSlot(slot);
|
||||
if (checkedStack.isEmpty())
|
||||
{
|
||||
if (checkedStack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int stackSize = checkedStack.getCount();
|
||||
|
||||
for (ItemStack filterStack : requestList)
|
||||
{
|
||||
if (filterStack.getCount() == 0)
|
||||
{
|
||||
for (ItemStack filterStack : requestList) {
|
||||
if (filterStack.getCount() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (doStacksMatch(filterStack, checkedStack))
|
||||
{
|
||||
if (doStacksMatch(filterStack, checkedStack)) {
|
||||
filterStack.setCount(Math.max(filterStack.getCount() - stackSize, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
requestList = filteredList;
|
||||
for (ItemStack filterStack : requestList)
|
||||
{
|
||||
for (ItemStack filterStack : requestList) {
|
||||
filterStack.setCount(filterStack.getCount() * -1); //Invert the stack size so that
|
||||
}
|
||||
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
|
||||
{
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
|
||||
ItemStack checkedStack = itemHandler.getStackInSlot(slot);
|
||||
if (checkedStack.isEmpty())
|
||||
{
|
||||
if (checkedStack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int stackSize = checkedStack.getCount();
|
||||
|
||||
for (ItemStack filterStack : filteredList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, checkedStack))
|
||||
{
|
||||
for (ItemStack filterStack : filteredList) {
|
||||
if (doStacksMatch(filterStack, checkedStack)) {
|
||||
filterStack.grow(stackSize);
|
||||
}
|
||||
}
|
||||
|
@ -107,11 +87,9 @@ public class TestItemFilter implements IItemFilter
|
|||
}
|
||||
|
||||
Iterator<ItemStack> iterator = requestList.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
while (iterator.hasNext()) {
|
||||
ItemStack filterStack = iterator.next();
|
||||
if (filterStack.isEmpty())
|
||||
{
|
||||
if (filterStack.isEmpty()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
@ -121,27 +99,22 @@ public class TestItemFilter implements IItemFilter
|
|||
* This method is only called when the output inventory this filter is
|
||||
* managing receives an ItemStack. Should only really be called by the Input
|
||||
* filter via it's transfer method.
|
||||
*
|
||||
* @param inputStack
|
||||
* - The stack to transfer
|
||||
*
|
||||
* @param inputStack - The stack to transfer
|
||||
* @return - The remainder of the stack after it has been absorbed into the
|
||||
* inventory.
|
||||
* inventory.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack transferStackThroughOutputFilter(ItemStack inputStack)
|
||||
{
|
||||
public ItemStack transferStackThroughOutputFilter(ItemStack inputStack) {
|
||||
int allowedAmount = 0;
|
||||
for (ItemStack filterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, inputStack))
|
||||
{
|
||||
for (ItemStack filterStack : requestList) {
|
||||
if (doStacksMatch(filterStack, inputStack)) {
|
||||
allowedAmount = Math.min(filterStack.getCount(), inputStack.getCount());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allowedAmount <= 0)
|
||||
{
|
||||
if (allowedAmount <= 0) {
|
||||
return inputStack;
|
||||
}
|
||||
|
||||
|
@ -154,14 +127,11 @@ public class TestItemFilter implements IItemFilter
|
|||
testStack.shrink(changeAmount);
|
||||
|
||||
Iterator<ItemStack> itr = requestList.iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
while (itr.hasNext()) {
|
||||
ItemStack filterStack = itr.next();
|
||||
if (doStacksMatch(filterStack, inputStack))
|
||||
{
|
||||
if (doStacksMatch(filterStack, inputStack)) {
|
||||
filterStack.shrink(changeAmount);
|
||||
if (filterStack.isEmpty())
|
||||
{
|
||||
if (filterStack.isEmpty()) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
@ -179,10 +149,8 @@ public class TestItemFilter implements IItemFilter
|
|||
* the input inventory to the output inventory.
|
||||
*/
|
||||
@Override
|
||||
public int transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer)
|
||||
{
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
|
||||
{
|
||||
public int transferThroughInputFilter(IItemFilter outputFilter, int maxTransfer) {
|
||||
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
|
||||
ItemStack inputStack = itemHandler.getStackInSlot(slot);
|
||||
if (inputStack.isEmpty() || itemHandler.extractItem(slot, inputStack.getCount(), true).isEmpty())//(accessedInventory instanceof ISidedInventory && !((ISidedInventory) accessedInventory).canExtractItem(slot, inputStack, accessedSide)))
|
||||
{
|
||||
|
@ -190,17 +158,14 @@ public class TestItemFilter implements IItemFilter
|
|||
}
|
||||
|
||||
int allowedAmount = 0;
|
||||
for (ItemStack filterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, inputStack))
|
||||
{
|
||||
for (ItemStack filterStack : requestList) {
|
||||
if (doStacksMatch(filterStack, inputStack)) {
|
||||
allowedAmount = Math.min(maxTransfer, Math.min(filterStack.getCount(), itemHandler.extractItem(slot, inputStack.getCount(), true).getCount()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allowedAmount <= 0)
|
||||
{
|
||||
if (allowedAmount <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -209,8 +174,7 @@ public class TestItemFilter implements IItemFilter
|
|||
ItemStack remainderStack = outputFilter.transferStackThroughOutputFilter(testStack);
|
||||
int changeAmount = allowedAmount - (remainderStack.isEmpty() ? 0 : remainderStack.getCount());
|
||||
|
||||
if (!remainderStack.isEmpty() && remainderStack.getCount() == allowedAmount)
|
||||
{
|
||||
if (!remainderStack.isEmpty() && remainderStack.getCount() == allowedAmount) {
|
||||
//Nothing has changed. Moving on!
|
||||
continue;
|
||||
}
|
||||
|
@ -218,14 +182,11 @@ public class TestItemFilter implements IItemFilter
|
|||
itemHandler.extractItem(slot, changeAmount, false);
|
||||
|
||||
Iterator<ItemStack> itr = requestList.iterator();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
while (itr.hasNext()) {
|
||||
ItemStack filterStack = itr.next();
|
||||
if (doStacksMatch(filterStack, inputStack))
|
||||
{
|
||||
if (doStacksMatch(filterStack, inputStack)) {
|
||||
filterStack.shrink(changeAmount);
|
||||
if (filterStack.isEmpty())
|
||||
{
|
||||
if (filterStack.isEmpty()) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
@ -242,12 +203,9 @@ public class TestItemFilter implements IItemFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doesStackMatchFilter(ItemStack testStack)
|
||||
{
|
||||
for (ItemStack filterStack : requestList)
|
||||
{
|
||||
if (doStacksMatch(filterStack, testStack))
|
||||
{
|
||||
public boolean doesStackMatchFilter(ItemStack testStack) {
|
||||
for (ItemStack filterStack : requestList) {
|
||||
if (doStacksMatch(filterStack, testStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -256,8 +214,7 @@ public class TestItemFilter implements IItemFilter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack)
|
||||
{
|
||||
public boolean doStacksMatch(ItemStack filterStack, ItemStack testStack) {
|
||||
return Utils.canCombine(filterStack, testStack);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue