Filter now renders item it is filter on sides

This commit is contained in:
Calclavia 2014-03-12 20:56:07 +08:00
parent 8f14af4bb7
commit 2e4de27e94
8 changed files with 225 additions and 75 deletions

View file

@ -10,7 +10,6 @@ import resonantinduction.archaic.crate.ItemBlockCrate;
import resonantinduction.archaic.crate.TileCrate;
import resonantinduction.archaic.engineering.ItemHammer;
import resonantinduction.archaic.engineering.TileEngineeringTable;
import resonantinduction.archaic.filter.BlockFilter;
import resonantinduction.archaic.filter.BlockImprinter;
import resonantinduction.archaic.filter.TileFilter;
import resonantinduction.archaic.filter.TileImprinter;
@ -107,7 +106,7 @@ public class Archaic
blockCast = contentRegistry.createTile(BlockCastingMold.class, TileCastingMold.class);
blockGutter = contentRegistry.newBlock(TileGutter.class);
blockGrate = contentRegistry.newBlock(TileGrate.class);
blockFilter = contentRegistry.createTile(BlockFilter.class, TileFilter.class);
blockFilter = contentRegistry.newBlock(TileFilter.class);
blockTank = contentRegistry.newBlock(TileTank.class);
itemHandCrank = contentRegistry.createItem(ItemHandCrank.class);
@ -119,6 +118,7 @@ public class Archaic
TabRI.ITEMSTACK = new ItemStack(blockEngineeringTable);
PacketAnnotation.register(TileFirebox.class);
PacketAnnotation.register(TileFilter.class);
proxy.preInit();
}

View file

@ -1,67 +0,0 @@
package resonantinduction.archaic.filter;
import java.util.List;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import resonantinduction.core.prefab.imprint.BlockImprintable;
/**
* Used for filtering liquid mixtures
*
* @author Calclavia
*
*/
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
public TileEntity createNewTileEntity(World var1)
{
return new TileFilter();
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
}

View file

@ -1,26 +1,61 @@
package resonantinduction.archaic.filter;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
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.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraftforge.common.ForgeDirection;
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.ResonantInduction;
import resonantinduction.core.prefab.imprint.ItemImprint;
import resonantinduction.core.prefab.imprint.TileFilterable;
import resonantinduction.core.render.RenderItemOverlayTile;
import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.fluid.BlockFluidMixture;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.content.module.TileRender;
import calclavia.lib.network.Synced.SyncedInput;
import calclavia.lib.network.Synced.SyncedOutput;
import calclavia.lib.prefab.vector.Cuboid;
import calclavia.lib.utility.LanguageUtility;
import calclavia.lib.utility.inventory.InventoryUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileFilter extends TileFilterable implements IFilterable
{
public TileFilter()
{
super(Material.iron);
maxSlots = 1;
isOpaqueCube = false;
normalRender = false;
}
public Iterable<Cuboid> getCollisionBoxes(Cuboid intersect, Entity entity)
{
if (entity == null)
return null;
if (entity instanceof EntityItem)
{
if (isFiltering(((EntityItem) entity).getEntityItem()))
{
return null;
}
}
return super.getCollisionBoxes(intersect, entity);
}
@Override
@ -30,6 +65,17 @@ public class TileFilter extends TileFilterable implements IFilterable
if (ticks % 60 == 0)
{
/**
* Toggle item filter render
*/
List<ItemStack> filteredStacks = ItemImprint.getFilterList(getFilter());
if (filteredStacks.size() > 0)
renderIndex = (renderIndex + 1) % filteredStacks.size();
/**
* Fluid filters
*/
Vector3 position = new Vector3(this);
Vector3 checkAbove = position.clone().translate(ForgeDirection.UP);
Vector3 checkBelow = position.clone().translate(ForgeDirection.DOWN);
@ -72,6 +118,55 @@ public class TileFilter extends TileFilterable implements IFilterable
}
}
@SyncedOutput
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
}
@SyncedInput
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
}
private int renderIndex = 0;
@SideOnly(Side.CLIENT)
protected TileRender newRenderer()
{
return new TileRender()
{
@Override
public boolean renderDynamic(Vector3 position, boolean isItem, float frame)
{
if (isItem)
return false;
if (getFilter() != null)
{
List<ItemStack> filteredStacks = ItemImprint.getFilterList(getFilter());
if (filteredStacks.size() > 0)
{
ItemStack renderStack = filteredStacks.get(renderIndex);
RenderItemOverlayTile.renderItemOnSides(TileFilter.this, renderStack, position.x, position.y, position.z);
}
}
return false;
}
};
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_ANNOTATION.getPacket(this);
}
@Override
public boolean canStore(ItemStack stack, int slot, ForgeDirection side)
{
@ -82,6 +177,7 @@ public class TileFilter extends TileFilterable implements IFilterable
public void setFilter(ItemStack filter)
{
setInventorySlotContents(0, filter);
markUpdate();
}
@Override

View file

@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import resonantinduction.core.Reference;
import resonantinduction.core.resource.ItemHandCrank;
import calclavia.lib.prefab.turbine.BlockTurbine;
import calclavia.lib.prefab.turbine.TileTurbine;
@ -63,6 +64,28 @@ public class BlockMechanicalTurbine extends BlockTurbine
}
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemHandCrank)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileTurbine)
{
if (!world.isRemote)
{
TileMechanicalTurbine tile = (TileMechanicalTurbine) tileEntity;
tile.mechanicalNode.torque = -tile.mechanicalNode.torque;
tile.mechanicalNode.angularVelocity = -tile.mechanicalNode.angularVelocity;
}
return true;
}
}
return false;
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{

View file

@ -21,7 +21,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileMechanicalPiston extends TileMechanical implements IRotatable
{
@Config
private int mechanicalPistonBreakCount = 5;
private static int mechanicalPistonBreakCount = 5;
public TileMechanicalPiston()
{

View file

@ -0,0 +1,30 @@
package resonantinduction.core.grid;
import net.minecraftforge.event.Event;
//NO-OP
abstract class NodeProviderEvent extends Event
{
public final INodeProvider provider;
protected NodeProviderEvent(INodeProvider provider)
{
this.provider = provider;
}
public static class NodeProviderLoadEvent extends NodeProviderEvent
{
protected NodeProviderLoadEvent(INodeProvider provider)
{
super(provider);
}
}
public static class NodeProviderUnloadEvent extends NodeProviderEvent
{
protected NodeProviderUnloadEvent(INodeProvider provider)
{
super(provider);
}
}
}

View file

@ -1,9 +1,11 @@
package resonantinduction.core.prefab.imprint;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import calclavia.lib.utility.nbt.NBTUtility;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
@ -110,12 +112,23 @@ public class ItemImprint extends Item
{
HashSet<ItemStack> filterStacks = new HashSet<ItemStack>();
if (itemStack.getTagCompound() == null)
NBTTagCompound nbt = NBTUtility.getNBTTagCompound(itemStack);
NBTTagList tagList = nbt.getTagList("Items");
for (int i = 0; i < tagList.tagCount(); ++i)
{
itemStack.setTagCompound(new NBTTagCompound());
NBTTagCompound var4 = (NBTTagCompound) tagList.tagAt(i);
filterStacks.add(ItemStack.loadItemStackFromNBT(var4));
}
NBTTagCompound nbt = itemStack.getTagCompound();
return filterStacks;
}
public static List<ItemStack> getFilterList(ItemStack itemStack)
{
List<ItemStack> filterStacks = new ArrayList<ItemStack>();
NBTTagCompound nbt = NBTUtility.getNBTTagCompound(itemStack);
NBTTagList tagList = nbt.getTagList("Items");
for (int i = 0; i < tagList.tagCount(); ++i)

View file

@ -2,14 +2,19 @@ package resonantinduction.core.prefab.imprint;
import java.util.Set;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.api.IFilterable;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.content.module.prefab.TileInventory;
import calclavia.lib.prefab.tile.IRotatable;
import calclavia.lib.prefab.tile.TileExternalInventory;
public abstract class TileFilterable extends TileExternalInventory implements IRotatable, IFilterable
public abstract class TileFilterable extends TileInventory implements IRotatable, IFilterable
{
private ItemStack filterItem;
private boolean inverted;
@ -18,6 +23,13 @@ public abstract class TileFilterable extends TileExternalInventory implements IR
public TileFilterable()
{
super(null);
this.maxSlots = 2;
}
public TileFilterable(Material material)
{
super(material);
this.maxSlots = 2;
}
@ -26,6 +38,49 @@ public abstract class TileFilterable extends TileExternalInventory implements IR
return true;
}
/** Allows filters to be placed inside of this block. */
@Override
public boolean use(EntityPlayer player, int side, Vector3 hit)
{
ItemStack containingStack = getFilter();
if (containingStack != null)
{
if (!world().isRemote)
{
EntityItem dropStack = new EntityItem(world(), player.posX, player.posY, player.posZ, containingStack);
dropStack.delayBeforeCanPickup = 0;
world().spawnEntityInWorld(dropStack);
}
setFilter(null);
return true;
}
else
{
if (player.getCurrentEquippedItem() != null)
{
if (player.getCurrentEquippedItem().getItem() instanceof ItemImprint)
{
setFilter(player.getCurrentEquippedItem());
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
return true;
}
}
}
return false;
}
@Override
public boolean configure(EntityPlayer player, int side, Vector3 hit)
{
toggleInversion();
markUpdate();
markRender();
return true;
}
/**
* Looks through the things in the filter and finds out which item is being filtered.
*