mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-13 16:54:06 +00:00
Added the Corporea Interceptor.
This commit is contained in:
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);
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.client.lib.LibResources;
|
||||
import vazkii.botania.common.block.corporea.BlockCorporeaFunnel;
|
||||
import vazkii.botania.common.block.corporea.BlockCorporeaIndex;
|
||||
import vazkii.botania.common.block.corporea.BlockCorporeaInterceptor;
|
||||
import vazkii.botania.common.block.decor.BlockBlaze;
|
||||
import vazkii.botania.common.block.decor.BlockBuriedPetals;
|
||||
import vazkii.botania.common.block.decor.BlockCustomBrick;
|
||||
@@ -129,6 +130,7 @@ import vazkii.botania.common.block.tile.TileTinyPlanet;
|
||||
import vazkii.botania.common.block.tile.TileTinyPotato;
|
||||
import vazkii.botania.common.block.tile.corporea.TileCorporeaFunnel;
|
||||
import vazkii.botania.common.block.tile.corporea.TileCorporeaIndex;
|
||||
import vazkii.botania.common.block.tile.corporea.TileCorporeaInterceptor;
|
||||
import vazkii.botania.common.block.tile.mana.TileDistributor;
|
||||
import vazkii.botania.common.block.tile.mana.TileManaDetector;
|
||||
import vazkii.botania.common.block.tile.mana.TileManaVoid;
|
||||
@@ -216,6 +218,7 @@ public final class ModBlocks {
|
||||
public static Block doubleFlower2;
|
||||
public static Block fakeAir;
|
||||
public static Block blazeBlock;
|
||||
public static Block corporeaInterceptor;
|
||||
|
||||
public static void init() {
|
||||
flower = new BlockModFlower();
|
||||
@@ -284,6 +287,7 @@ public final class ModBlocks {
|
||||
doubleFlower2 = new BlockModDoubleFlower(true);
|
||||
fakeAir = new BlockFakeAir();
|
||||
blazeBlock = new BlockBlaze();
|
||||
corporeaInterceptor = new BlockCorporeaInterceptor();
|
||||
|
||||
ModFluffBlocks.init();
|
||||
|
||||
@@ -368,6 +372,7 @@ public final class ModBlocks {
|
||||
registerTile(TileCorporeaFunnel.class, LibBlockNames.CORPOREA_FUNNEL);
|
||||
registerTile(TilePump.class, LibBlockNames.PUMP);
|
||||
registerTile(TileFakeAir.class, LibBlockNames.FAKE_AIR);
|
||||
registerTile(TileCorporeaInterceptor.class, LibBlockNames.CORPOREA_INTERCEPTOR);
|
||||
|
||||
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_PUREDAISY, SubTilePureDaisy.class);
|
||||
BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_MANASTAR, SubTileManastar.class);
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 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:18:03 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.block.corporea;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.block.tile.corporea.TileCorporeaBase;
|
||||
import vazkii.botania.common.block.tile.corporea.TileCorporeaFunnel;
|
||||
import vazkii.botania.common.block.tile.corporea.TileCorporeaInterceptor;
|
||||
import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockCorporeaInterceptor extends BlockCorporeaBase {
|
||||
|
||||
IIcon[] icons;
|
||||
|
||||
public BlockCorporeaInterceptor() {
|
||||
super(Material.iron, LibBlockNames.CORPOREA_INTERCEPTOR);
|
||||
setHardness(5.5F);
|
||||
setStepSound(soundTypeMetal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
icons = new IIcon[2];
|
||||
for(int i = 0; i < icons.length; i++)
|
||||
icons[i] = IconHelper.forBlock(par1IconRegister, this, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int par1, int par2) {
|
||||
return icons[par1 > 1 ? 1 : 0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, int x, int y, int z, Random rand) {
|
||||
world.setBlockMetadataWithNotify(x, y, z, 0, 1 | 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvidePower() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
|
||||
return world.getBlockMetadata(x, y, z) != 0 ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int tickRate(World p_149738_1_) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileCorporeaBase createNewTileEntity(World world, int meta) {
|
||||
return new TileCorporeaInterceptor();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,6 +74,11 @@ public class TileCorporeaFunnel extends TileCorporeaBase {
|
||||
return filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 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:21:08 PM (GMT)]
|
||||
*/
|
||||
package vazkii.botania.common.block.tile.corporea;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItemFrame;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import vazkii.botania.api.corporea.CorporeaHelper;
|
||||
import vazkii.botania.api.corporea.ICorporeaInterceptor;
|
||||
import vazkii.botania.api.corporea.ICorporeaSpark;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
public class TileCorporeaInterceptor extends TileCorporeaBase implements ICorporeaInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return LibBlockNames.CORPOREA_INTERCEPTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interceptRequest(Object request, int count, ICorporeaSpark spark, ICorporeaSpark source, List<ItemStack> stacks, List<IInventory> inventories, boolean doit) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interceptRequestLast(Object request, int count, ICorporeaSpark spark, ICorporeaSpark source, List<ItemStack> stacks, List<IInventory> inventories, boolean doit) {
|
||||
List<ItemStack> filter = getFilter();
|
||||
for(ItemStack stack : filter)
|
||||
if(requestMatches(request, stack)) {
|
||||
int missing = count;
|
||||
for(ItemStack stack_ : stacks)
|
||||
missing -= stack_.stackSize;
|
||||
|
||||
if(missing > 0 && getBlockMetadata() == 0) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 | 2);
|
||||
worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, getBlockType(), 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean requestMatches(Object request, ItemStack filter) {
|
||||
if(request instanceof ItemStack) {
|
||||
ItemStack stack = (ItemStack) request;
|
||||
return stack.isItemEqual(filter) && ItemStack.areItemStacksEqual(filter, stack);
|
||||
}
|
||||
|
||||
String name = (String) request;
|
||||
return CorporeaHelper.stacksMatch(filter, name);
|
||||
}
|
||||
|
||||
public List<ItemStack> getFilter() {
|
||||
List<ItemStack> filter = new ArrayList();
|
||||
|
||||
final int[] orientationToDir = new int[] {
|
||||
3, 4, 2, 5
|
||||
};
|
||||
|
||||
for(ForgeDirection dir : LibMisc.CARDINAL_DIRECTIONS) {
|
||||
List<EntityItemFrame> frames = worldObj.getEntitiesWithinAABB(EntityItemFrame.class, AxisAlignedBB.getBoundingBox(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, xCoord + dir.offsetX + 1, yCoord + dir.offsetY + 1, zCoord + dir.offsetZ + 1));
|
||||
for(EntityItemFrame frame : frames) {
|
||||
int orientation = frame.hangingDirection;
|
||||
if(orientationToDir[orientation] == dir.ordinal())
|
||||
filter.add(frame.getDisplayedItem());
|
||||
}
|
||||
}
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -237,6 +237,7 @@ public final class BotaniaCreativeTab extends CreativeTabs {
|
||||
addItem(ModItems.corporeaSpark);
|
||||
addBlock(ModBlocks.corporeaIndex);
|
||||
addBlock(ModBlocks.corporeaFunnel);
|
||||
addBlock(ModBlocks.corporeaInterceptor);
|
||||
|
||||
// FLUFF
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ public final class LibBlockNames {
|
||||
public static final String STONE = "stone";
|
||||
public static final String FAKE_AIR = "fakeAir";
|
||||
public static final String BLAZE_BLOCK = "blazeBlock";
|
||||
public static final String CORPOREA_INTERCEPTOR = "corporeaInterceptor";
|
||||
|
||||
public static final String SUBTILE_PUREDAISY = "puredaisy";
|
||||
public static final String SUBTILE_MANASTAR = "manastar";
|
||||
|
||||
@@ -903,6 +903,7 @@ tile.botania:stone9Slab.name=Basalt Brick Slab
|
||||
tile.botania:stone10Slab.name=Diorite Brick Slab
|
||||
tile.botania:stone11Slab.name=Granite Brick Slab
|
||||
tile.botania:blazeBlock.name=Blaze Lamp
|
||||
tile.botania:corporeaInterceptor.name=Corporea Interceptor
|
||||
|
||||
# FLOWER NAMES
|
||||
tile.botania:flower..name=Botania Flower
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 19 KiB |
Reference in new issue
Block a user