Finished the initial sorter

This commit is contained in:
Calclavia 2014-03-03 21:57:53 +08:00
parent 4b919ed7e3
commit 7f490b260a
3 changed files with 124 additions and 9 deletions

View file

@ -1,28 +1,122 @@
package resonantinduction.mechanical.logistic.belt;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.Entity;
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.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import resonantinduction.api.IFilterable;
import resonantinduction.core.Reference;
import resonantinduction.core.prefab.imprint.ItemImprint;
import universalelectricity.api.UniversalElectricity;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.content.module.TileBase;
import calclavia.lib.content.module.TileRender;
import calclavia.lib.content.module.prefab.TileInventory;
import calclavia.lib.prefab.vector.Cuboid;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileSorter extends TileBase
public class TileSorter extends TileInventory
{
private boolean isInverted = false;
public TileSorter()
{
super(UniversalElectricity.machine);
textureName = "material_metal_side";
maxSlots = 6;
normalRender = false;
isOpaqueCube = false;
bounds = Cuboid.full().expand(-0.1);
}
@Override
public boolean use(EntityPlayer player, int side, Vector3 vector3)
{
return interactCurrentItem(side, player);
}
protected boolean configure(EntityPlayer player, int side, Vector3 vector3)
{
isInverted = !isInverted;
if (world().isRemote)
{
player.addChatMessage("Sorter filter inversion: " + isInverted);
}
return true;
}
@Override
public boolean canStore(ItemStack stack, int slot, ForgeDirection side)
{
return stack.getItem() instanceof IFilterable;
}
@Override
public void collide(Entity entity)
{
if (entity instanceof EntityItem)
{
EntityItem entityItem = (EntityItem) entity;
List<ForgeDirection> possibleDirections = new ArrayList<ForgeDirection>();
/**
* Move item to position where a filter allows it.
*/
for (int i = 0; i < getSizeInventory(); i++)
{
ItemStack stack = getStackInSlot(i);
if (isInverted == ItemImprint.isFiltering(stack, entityItem.getEntityItem()))
{
possibleDirections.add(ForgeDirection.getOrientation(i));
}
}
int size = possibleDirections.size();
if (size > 0)
{
ForgeDirection dir = possibleDirections.get(size > 1 ? world().rand.nextInt(size - 1) : 0);
Vector3 set = center().translate(dir, 0.9);
entityItem.posX = set.x;
entityItem.posY = set.y;
entityItem.posZ = set.z;
}
}
}
@Override
public Cuboid getSelectBounds()
{
return Cuboid.full();
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
nbt.getBoolean("isInverted");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setBoolean("isInverted", isInverted);
}
@SideOnly(Side.CLIENT)
@ -40,7 +134,7 @@ public class TileSorter extends TileBase
RenderUtility.enableBlending();
GL11.glTranslated(position.x + 0.5, position.y + 0.5, position.z + 0.5);
RenderUtility.bind(TEXTURE);
MODEL.renderAll();
MODEL.renderAllExcept("port");
RenderUtility.disableBlending();
GL11.glPopMatrix();
}

View file

@ -41,7 +41,7 @@ public class ItemImprint extends Item
if (entity != null && !(entity instanceof IProjectile) && !(entity instanceof EntityPlayer))
{
String stringName = EntityList.getEntityString(entity);
// TODO add to filter
// TODO Add to filter
// player.sendChatToPlayer("Target: " + stringName);
return true;
}
@ -91,6 +91,27 @@ public class ItemImprint extends Item
itemStack.getTagCompound().setTag("Items", nbt);
}
public static boolean isFiltering(ItemStack filter, ItemStack itemStack)
{
if (filter != null && itemStack != null)
{
Set<ItemStack> checkStacks = getFilters(filter);
if (checkStacks != null)
{
for (ItemStack stack : checkStacks)
{
if (stack.isItemEqual(itemStack))
{
return true;
}
}
}
}
return false;
}
public static HashSet<ItemStack> getFilters(ItemStack itemStack)
{
HashSet<ItemStack> filterStacks = new HashSet<ItemStack>();

View file

@ -69,7 +69,7 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
RenderUtility.rotateBlockBasedOnDirection(dir);
GL11.glTranslated(translation.x, translation.y, translation.z);
GL11.glScalef(scale,scale,scale);
GL11.glScalef(scale, scale, scale);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
renderItem(tileEntity.worldObj, ForgeDirection.UP, inventory[i], new Vector3(0, 0, 0), 0, 4);
GL11.glPopMatrix();
@ -131,14 +131,12 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
renderItemOnSide(tile, itemStack, direction, x, y, z, renderText, amount);
RenderUtility.renderText(renderText, direction, 0.02f, x, y - 0.35f, z);
RenderUtility.renderText(amount, direction, 0.02f, x, y - 0.15f, z);
RenderUtility.disableLightmap();
}
}
protected static void renderItemOnSide(TileEntity tile, ItemStack itemStack, ForgeDirection direction, double x, double y, double z, String renderText, String amount)
{
setupLight(tile, direction.offsetX, direction.offsetZ);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
if (itemStack != null)
{
@ -169,6 +167,8 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
setupLight(tile, direction.offsetX, direction.offsetZ);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
GL11.glDisable(2896);
if (!ForgeHooksClient.renderInventoryItem(renderBlocks, renderEngine, itemStack, true, 0.0F, 0.0F, 0.0F))
@ -193,7 +193,7 @@ public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
int br = world.getLightBrightnessForSkyBlocks(tileEntity.xCoord + xDifference, tileEntity.yCoord, tileEntity.zCoord + zDifference, 0);
int var11 = br % 65536;
int var12 = br / 65536;
float scale = 0.6F;
float scale = 1;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, var11 * scale, var12 * scale);
}