Added the Corporea Interceptor.

This commit is contained in:
Lizbeth Rika committed 2015-04-19 19:56:16 +01:00
1 parent 20eff8140e
commit fa65df2d80
11 files changed
+239 -1

No files matched your search

@@ -165,13 +165,21 @@ public final class CorporeaHelper {
public static List<ItemStack> requestItem(Object matcher, int itemCount, ICorporeaSpark spark, boolean checkNBT, boolean doit) {
List<IInventory> inventories = getInventoriesOnNetwork(spark);
List<ItemStack> stacks = new ArrayList();
Map<ICorporeaInterceptor, ICorporeaSpark> interceptors = new HashMap();
lastRequestMatches = 0;
lastRequestExtractions = 0;
int count = itemCount;
for(IInventory inv : inventories) {
ICorporeaSpark invSpark = getSparkForInventory(inv);
if(inv instanceof ICorporeaInterceptor) {
ICorporeaInterceptor interceptor = (ICorporeaInterceptor) inv;
interceptor.interceptRequest(matcher, itemCount, invSpark, spark, stacks, inventories, doit);
interceptors.put(interceptor, invSpark);
}
for(int i = inv.getSizeInventory() - 1; i >= 0; i--) {
if(!isValidSlot(inv, i))
continue;
@@ -198,6 +206,9 @@ public final class CorporeaHelper {
}
}
}
for(ICorporeaInterceptor interceptor : interceptors.keySet())
interceptor.interceptRequestLast(matcher, itemCount, interceptors.get(interceptor), spark, stacks, inventories, doit);
return stacks;
}
@@ -0,0 +1,38 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Apr 19, 2015, 6:23:31 PM (GMT)]
*/
package vazkii.botania.api.corporea;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
/**
* A TileEntity that implements this will be able to intercept corporea
* requests case there is a Corporea Spark on top.
*/
public interface ICorporeaInterceptor {
/**
* Intercepts a request as it goes. The list of inventories has all the inventories
* at this point, but the list of stacks is not complete. The request parameter can
* be either a String or ItemStack.
*/
public void interceptRequest(Object request, int count, ICorporeaSpark spark, ICorporeaSpark source, List<ItemStack> stacks, List<IInventory> inventories, boolean doit);
/**
* Intercepts a request after all the stacks have been found and processed. Both the
* list of inventories and stacks is complete at this point. The request parameter can
* be either a String or ItemStack.
*/
public void interceptRequestLast(Object request, int count, ICorporeaSpark spark, ICorporeaSpark source, List<ItemStack> stacks, List<IInventory> inventories, boolean doit);
}