Filters can now take imprints and leak items through

This commit is contained in:
Calclavia 2014-02-28 21:10:25 +08:00
parent fde9a63f78
commit 84629a846a
4 changed files with 84 additions and 89 deletions

View file

@ -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)

View file

@ -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

View file

@ -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);
}
}

View file

@ -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;
}
}