From 84629a846a79345374b9f5ea14273f1312034fa8 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Fri, 28 Feb 2014 21:10:25 +0800 Subject: [PATCH] Filters can now take imprints and leak items through --- .../archaic/fluid/gutter/BlockGutter.java | 2 +- .../mechanical/process/BlockFilter.java | 34 +++++- .../mechanical/process/TileFilter.java | 29 ++++- .../core/prefab/imprint/BlockImprintable.java | 108 ++++-------------- 4 files changed, 84 insertions(+), 89 deletions(-) diff --git a/archaic/src/main/java/resonantinduction/archaic/fluid/gutter/BlockGutter.java b/archaic/src/main/java/resonantinduction/archaic/fluid/gutter/BlockGutter.java index 4f814232..911270e7 100644 --- a/archaic/src/main/java/resonantinduction/archaic/fluid/gutter/BlockGutter.java +++ b/archaic/src/main/java/resonantinduction/archaic/fluid/gutter/BlockGutter.java @@ -38,7 +38,7 @@ public class BlockGutter extends BlockFluidNetwork public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) { float thickness = 0.1F; - + TileEntity tile = world.getBlockTileEntity(x, y, z); if (tile instanceof TileGutter) diff --git a/mechanical/src/main/java/resonantinduction/mechanical/process/BlockFilter.java b/mechanical/src/main/java/resonantinduction/mechanical/process/BlockFilter.java index e65c825d..1a02b552 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/process/BlockFilter.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/process/BlockFilter.java @@ -1,9 +1,16 @@ package resonantinduction.mechanical.process; +import java.util.List; + import net.minecraft.block.material.Material; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; -import calclavia.lib.prefab.block.BlockTile; +import resonantinduction.api.IFilterable; +import resonantinduction.core.prefab.imprint.BlockImprintable; /** * Used for filtering liquid mixtures @@ -11,11 +18,34 @@ import calclavia.lib.prefab.block.BlockTile; * @author Calclavia * */ -public class BlockFilter extends BlockTile +public class BlockFilter extends BlockImprintable { public BlockFilter(int id) { super(id, Material.iron); + setBlockBounds(0.01f, 0.01f, 0.01f, 0.99f, 0.99f, 0.99f); + } + + @Override + public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) + { + if (entity == null) + return; + + if (entity instanceof EntityItem) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileFilter) + { + if (((TileFilter) tileEntity).isFiltering(((EntityItem) entity).getEntityItem())) + { + return; + } + } + } + + super.addCollisionBoxesToList(world, x, y, z, aabb, list, entity); } @Override diff --git a/mechanical/src/main/java/resonantinduction/mechanical/process/TileFilter.java b/mechanical/src/main/java/resonantinduction/mechanical/process/TileFilter.java index b9489b26..efae0a22 100644 --- a/mechanical/src/main/java/resonantinduction/mechanical/process/TileFilter.java +++ b/mechanical/src/main/java/resonantinduction/mechanical/process/TileFilter.java @@ -1,14 +1,18 @@ package resonantinduction.mechanical.process; import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidHandler; +import resonantinduction.api.IFilterable; import resonantinduction.api.recipe.MachineRecipes; import resonantinduction.api.recipe.MachineRecipes.RecipeType; import resonantinduction.api.recipe.RecipeResource; +import resonantinduction.core.prefab.imprint.ItemImprint; +import resonantinduction.core.prefab.imprint.TileFilterable; import resonantinduction.core.resource.ResourceGenerator; import resonantinduction.core.resource.fluid.BlockFluidMixture; import universalelectricity.api.vector.Vector3; @@ -16,8 +20,13 @@ import calclavia.lib.prefab.tile.TileExternalInventory; import calclavia.lib.utility.LanguageUtility; import calclavia.lib.utility.inventory.InventoryUtility; -public class TileFilter extends TileExternalInventory +public class TileFilter extends TileFilterable implements IFilterable { + public TileFilter() + { + maxSlots = 1; + } + @Override public void updateEntity() { @@ -82,4 +91,22 @@ public class TileFilter extends TileExternalInventory } } } + + @Override + public boolean canStore(ItemStack stack, int slot, ForgeDirection side) + { + return slot == 0 && stack.getItem() instanceof ItemImprint; + } + + @Override + public void setFilter(ItemStack filter) + { + setInventorySlotContents(0, filter); + } + + @Override + public ItemStack getFilter() + { + return getStackInSlot(0); + } } diff --git a/src/main/java/resonantinduction/core/prefab/imprint/BlockImprintable.java b/src/main/java/resonantinduction/core/prefab/imprint/BlockImprintable.java index e2942a6b..79f4cbf6 100644 --- a/src/main/java/resonantinduction/core/prefab/imprint/BlockImprintable.java +++ b/src/main/java/resonantinduction/core/prefab/imprint/BlockImprintable.java @@ -29,38 +29,35 @@ public abstract class BlockImprintable extends BlockRotatable { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); - if (tileEntity != null) + if (tileEntity instanceof IFilterable) { - if (tileEntity instanceof IFilterable) + ItemStack containingStack = ((IFilterable) tileEntity).getFilter(); + + if (containingStack != null) { - ItemStack containingStack = ((IFilterable) tileEntity).getFilter(); - - if (containingStack != null) + if (!world.isRemote) { - if (!world.isRemote) - { - EntityItem dropStack = new EntityItem(world, player.posX, player.posY, player.posZ, containingStack); - dropStack.delayBeforeCanPickup = 0; - world.spawnEntityInWorld(dropStack); - } - - ((IFilterable) tileEntity).setFilter(null); - return true; - } - else - { - if (player.getCurrentEquippedItem() != null) - { - if (player.getCurrentEquippedItem().getItem() instanceof ItemImprint) - { - ((IFilterable) tileEntity).setFilter(player.getCurrentEquippedItem()); - player.inventory.setInventorySlotContents(player.inventory.currentItem, null); - return true; - } - } + EntityItem dropStack = new EntityItem(world, player.posX, player.posY, player.posZ, containingStack); + dropStack.delayBeforeCanPickup = 0; + world.spawnEntityInWorld(dropStack); } + ((IFilterable) tileEntity).setFilter(null); + return true; } + else + { + if (player.getCurrentEquippedItem() != null) + { + if (player.getCurrentEquippedItem().getItem() instanceof ItemImprint) + { + ((IFilterable) tileEntity).setFilter(player.getCurrentEquippedItem()); + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + return true; + } + } + } + } return false; @@ -83,63 +80,4 @@ public abstract class BlockImprintable extends BlockRotatable return true; } - - @Override - public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) - { - return this.onMachineActivated(world, x, y, z, player, side, hitX, hitY, hitZ); - } - - @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack stack) - { - int angle = MathHelper.floor_double((par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; - int change = 2; - - switch (angle) - { - case 0: - change = 2; - break; - case 1: - change = 5; - break; - case 2: - change = 3; - break; - case 3: - change = 4; - break; - - } - world.setBlockMetadataWithNotify(x, y, z, change, 3); - } - - @Override - public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) - { - int original = world.getBlockMetadata(x, y, z); - int change = 2; - - switch (original) - { - case 2: - change = 4; - break; - case 3: - change = 5; - break; - case 4: - change = 3; - break; - case 5: - change = 2; - break; - - } - - world.setBlockMetadataWithNotify(x, y, z, change, 3); - - return true; - } }