Empty commit

This commit is contained in:
Henry Mao 2012-12-29 11:10:16 +08:00
parent 88596a9361
commit 142c25603a
3 changed files with 311 additions and 311 deletions

View file

@ -1,39 +1,39 @@
package assemblyline.client.render; package assemblyline.client.render;
import java.util.ArrayList; import java.util.ArrayList;
import assemblyline.common.machine.TileEntityFilterable; import assemblyline.common.machine.TileEntityFilterable;
import assemblyline.common.machine.filter.ItemFilter; import assemblyline.common.machine.filter.ItemFilter;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
public abstract class RenderFilterable extends TileEntitySpecialRenderer public abstract class RenderFilterable extends TileEntitySpecialRenderer
{ {
@Override @Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8) public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
{ {
if (tileEntity instanceof TileEntityFilterable) if (tileEntity instanceof TileEntityFilterable)
{ {
TileEntityFilterable filterable = (TileEntityFilterable) tileEntity; TileEntityFilterable filterable = (TileEntityFilterable) tileEntity;
EntityPlayer p = Minecraft.getMinecraft().thePlayer; EntityPlayer p = Minecraft.getMinecraft().thePlayer;
double dist = p.getDistance(filterable.xCoord, filterable.yCoord, filterable.zCoord); double dist = p.getDistance(filterable.xCoord, filterable.yCoord, filterable.zCoord);
if (dist < 5) if (dist < 5)
{ {
ItemStack filter = filterable.getFilter(); ItemStack filter = filterable.getFilter();
if (filter != null) if (filter != null)
{ {
ArrayList<ItemStack> filters = ItemFilter.getFilters(filter); ArrayList<ItemStack> filters = ItemFilter.getFilters(filter);
for (int i = 0; i < filters.size(); i++) for (int i = 0; i < filters.size(); i++)
{ {
RenderHelper.renderFloatingText(filters.get(i).getTooltip(p, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), (float) x + 0.5f, ((float) y + (i * 0.25f)) - 1f, (float) z + 0.5f); RenderHelper.renderFloatingText(filters.get(i).getTooltip(p, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), (float) x + 0.5f, ((float) y + (i * 0.25f)) - 1f, (float) z + 0.5f);
} }
} }
} }
} }
} }
} }

View file

@ -1,50 +1,50 @@
package assemblyline.client.render; package assemblyline.client.render;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderManager;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
public class RenderHelper public class RenderHelper
{ {
public static void renderFloatingText(String text, float x, float y, float z) public static void renderFloatingText(String text, float x, float y, float z)
{ {
RenderManager renderManager = RenderManager.instance; RenderManager renderManager = RenderManager.instance;
FontRenderer fontRenderer = renderManager.getFontRenderer(); FontRenderer fontRenderer = renderManager.getFontRenderer();
float scale = 0.027f; float scale = 0.027f;
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.0F, (float) y + 2.3F, (float) z); GL11.glTranslatef((float) x + 0.0F, (float) y + 2.3F, (float) z);
GL11.glNormal3f(0.0F, 1.0F, 0.0F); GL11.glNormal3f(0.0F, 1.0F, 0.0F);
GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F); GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F); GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
GL11.glScalef(-scale, -scale, scale); GL11.glScalef(-scale, -scale, scale);
GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDepthMask(false); GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator tessellator = Tessellator.instance; Tessellator tessellator = Tessellator.instance;
int yOffset = 0; int yOffset = 0;
GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_TEXTURE_2D);
tessellator.startDrawingQuads(); tessellator.startDrawingQuads();
int stringMiddle = fontRenderer.getStringWidth(text) / 2; int stringMiddle = fontRenderer.getStringWidth(text) / 2;
tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.5F); tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.5F);
tessellator.addVertex((double) (-stringMiddle - 1), (double) (-1 + yOffset), 0.0D); tessellator.addVertex((double) (-stringMiddle - 1), (double) (-1 + yOffset), 0.0D);
tessellator.addVertex((double) (-stringMiddle - 1), (double) (8 + yOffset), 0.0D); tessellator.addVertex((double) (-stringMiddle - 1), (double) (8 + yOffset), 0.0D);
tessellator.addVertex((double) (stringMiddle + 1), (double) (8 + yOffset), 0.0D); tessellator.addVertex((double) (stringMiddle + 1), (double) (8 + yOffset), 0.0D);
tessellator.addVertex((double) (stringMiddle + 1), (double) (-1 + yOffset), 0.0D); tessellator.addVertex((double) (stringMiddle + 1), (double) (-1 + yOffset), 0.0D);
tessellator.draw(); tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_TEXTURE_2D);
fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, 553648127); fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, 553648127);
GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true); GL11.glDepthMask(true);
fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, -1); fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, -1);
GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
} }

View file

@ -1,222 +1,222 @@
package assemblyline.common.machine; package assemblyline.common.machine;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.implement.IRotatable; import universalelectricity.prefab.implement.IRotatable;
import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager; import universalelectricity.prefab.network.PacketManager;
import universalelectricity.prefab.network.PacketManager.PacketType; import universalelectricity.prefab.network.PacketManager.PacketType;
import assemblyline.api.IFilterable; import assemblyline.api.IFilterable;
import assemblyline.common.AssemblyLine; import assemblyline.common.AssemblyLine;
public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork implements IRotatable, IFilterable, IPacketReceiver, IInventory public abstract class TileEntityFilterable extends TileEntityAssemblyNetwork implements IRotatable, IFilterable, IPacketReceiver, IInventory
{ {
private ItemStack filterItem; private ItemStack filterItem;
@Override @Override
public int getSizeInventory() public int getSizeInventory()
{ {
return 1; return 1;
} }
@Override @Override
public ItemStack getStackInSlot(int slot) public ItemStack getStackInSlot(int slot)
{ {
if (slot == 0) if (slot == 0)
return filterItem; return filterItem;
else else
return null; return null;
} }
@Override @Override
public ItemStack decrStackSize(int slot, int amount) public ItemStack decrStackSize(int slot, int amount)
{ {
if (filterItem != null) if (filterItem != null)
{ {
ItemStack stack; ItemStack stack;
if (filterItem.stackSize <= amount) if (filterItem.stackSize <= amount)
{ {
stack = filterItem; stack = filterItem;
filterItem = null; filterItem = null;
return stack; return stack;
} }
else else
{ {
stack = filterItem.splitStack(amount); stack = filterItem.splitStack(amount);
if (filterItem.stackSize == 0) if (filterItem.stackSize == 0)
{ {
filterItem = null; filterItem = null;
} }
return stack; return stack;
} }
} }
else else
{ {
return null; return null;
} }
} }
@Override @Override
public ItemStack getStackInSlotOnClosing(int slot) public ItemStack getStackInSlotOnClosing(int slot)
{ {
if (filterItem != null) if (filterItem != null)
{ {
ItemStack stack = filterItem; ItemStack stack = filterItem;
filterItem = null; filterItem = null;
return stack; return stack;
} }
else else
{ {
return null; return null;
} }
} }
@Override @Override
public void setInventorySlotContents(int slot, ItemStack stack) public void setInventorySlotContents(int slot, ItemStack stack)
{ {
filterItem = stack; filterItem = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit()) if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{ {
stack.stackSize = this.getInventoryStackLimit(); stack.stackSize = this.getInventoryStackLimit();
} }
} }
@Override @Override
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
{ {
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D; return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D;
} }
@Override @Override
public void openChest() public void openChest()
{ {
} }
@Override @Override
public void closeChest() public void closeChest()
{ {
} }
@Override @Override
public void setFilter(ItemStack filter) public void setFilter(ItemStack filter)
{ {
this.setInventorySlotContents(0, filter); this.setInventorySlotContents(0, filter);
PacketManager.sendPacketToClients(getDescriptionPacket()); PacketManager.sendPacketToClients(getDescriptionPacket());
} }
@Override @Override
public ItemStack getFilter() public ItemStack getFilter()
{ {
return this.getStackInSlot(0); return this.getStackInSlot(0);
} }
@Override @Override
public ForgeDirection getDirection() public ForgeDirection getDirection()
{ {
return ForgeDirection.getOrientation(this.getBlockMetadata()); return ForgeDirection.getOrientation(this.getBlockMetadata());
} }
@Override @Override
public void setDirection(ForgeDirection facingDirection) public void setDirection(ForgeDirection facingDirection)
{ {
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, facingDirection.ordinal()); this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, facingDirection.ordinal());
} }
@Override @Override
public abstract String getInvName(); public abstract String getInvName();
@Override @Override
public int getInventoryStackLimit() public int getInventoryStackLimit()
{ {
return 1; return 1;
} }
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket()
{ {
Packet250CustomPayload packet = new Packet250CustomPayload(); Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = AssemblyLine.CHANNEL; packet.channel = AssemblyLine.CHANNEL;
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos); DataOutputStream dos = new DataOutputStream(bos);
try try
{ {
dos.writeInt(PacketType.TILEENTITY.ordinal()); dos.writeInt(PacketType.TILEENTITY.ordinal());
dos.writeInt(xCoord); dos.writeInt(xCoord);
dos.writeInt(yCoord); dos.writeInt(yCoord);
dos.writeInt(zCoord); dos.writeInt(zCoord);
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag); writeToNBT(tag);
PacketManager.writeNBTTagCompound(tag, dos); PacketManager.writeNBTTagCompound(tag, dos);
packet.data = bos.toByteArray(); packet.data = bos.toByteArray();
packet.length = bos.size(); packet.length = bos.size();
return packet; return packet;
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
@Override @Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{ {
ByteArrayInputStream bis = new ByteArrayInputStream(packet.data); ByteArrayInputStream bis = new ByteArrayInputStream(packet.data);
DataInputStream dis = new DataInputStream(bis); DataInputStream dis = new DataInputStream(bis);
int id, x, y, z; int id, x, y, z;
try try
{ {
id = dis.readInt(); id = dis.readInt();
x = dis.readInt(); x = dis.readInt();
y = dis.readInt(); y = dis.readInt();
z = dis.readInt(); z = dis.readInt();
NBTTagCompound tag = Packet.readNBTTagCompound(dis); NBTTagCompound tag = Packet.readNBTTagCompound(dis);
readFromNBT(tag); readFromNBT(tag);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override @Override
public void writeToNBT(NBTTagCompound nbt) public void writeToNBT(NBTTagCompound nbt)
{ {
super.writeToNBT(nbt); super.writeToNBT(nbt);
NBTTagCompound filter = new NBTTagCompound(); NBTTagCompound filter = new NBTTagCompound();
if (getFilter() != null) if (getFilter() != null)
getFilter().writeToNBT(filter); getFilter().writeToNBT(filter);
nbt.setTag("filter", filter); nbt.setTag("filter", filter);
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) public void readFromNBT(NBTTagCompound nbt)
{ {
super.readFromNBT(nbt); super.readFromNBT(nbt);
NBTTagCompound filter = nbt.getCompoundTag("filter"); NBTTagCompound filter = nbt.getCompoundTag("filter");
setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(filter)); setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(filter));
} }
} }