Guest User

Untitled

a guest
Jan 5th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.15 KB | None | 0 0
  1. package com.gugu42.rcmod.gui;
  2.  
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.DataOutputStream;
  5.  
  6. import org.lwjgl.opengl.GL11;
  7.  
  8. import com.gugu42.rcmod.ContainerVendor;
  9. import com.gugu42.rcmod.RcMod;
  10. import com.gugu42.rcmod.bolts.ExtendedPlayerBolt;
  11. import com.gugu42.rcmod.tileentity.TileEntityVendor;
  12. import com.gugu42.rcmod.items.ItemRcWeap;
  13.  
  14. import cpw.mods.fml.common.network.PacketDispatcher;
  15. import cpw.mods.fml.relauncher.Side;
  16. import cpw.mods.fml.relauncher.SideOnly;
  17.  
  18. import net.minecraft.client.gui.GuiButton;
  19. import net.minecraft.client.gui.inventory.GuiContainer;
  20. import net.minecraft.client.renderer.Tessellator;
  21. import net.minecraft.client.resources.I18n;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.entity.player.InventoryPlayer;
  24. import net.minecraft.network.packet.Packet;
  25. import net.minecraft.network.packet.Packet250CustomPayload;
  26. import net.minecraft.util.ResourceLocation;
  27. import net.minecraft.util.StatCollector;
  28.  
  29. @SideOnly(Side.CLIENT)
  30. public class GuiVendor extends GuiContainer {
  31.  
  32.     private static final ResourceLocation texturepath = new ResourceLocation(
  33.             "rcmod", "textures/gui/vendor.png");
  34.  
  35.     private GuiButton ammoBtn;
  36.     private TileEntityVendor tileEntity;
  37.     private EntityPlayer player;
  38.  
  39.     public GuiVendor(InventoryPlayer inventoryPlayer,
  40.             TileEntityVendor tileEntity, EntityPlayer player) {
  41.         super(new ContainerVendor(inventoryPlayer, tileEntity));
  42.         this.tileEntity = tileEntity;
  43.         this.player = player;
  44.         this.xSize = 176;
  45.         this.ySize = 222;
  46.     }
  47.  
  48.     @Override
  49.     public void initGui() {
  50.         super.initGui();
  51.         this.buttonList.clear();
  52.         int posX = (this.width - xSize) / 2;
  53.         int posY = (this.height - ySize) / 2;
  54.         this.buttonList.add(this.ammoBtn = new GuiButton(0, posX + 13,
  55.                 posY + 35, 33, 20, "Refill"));
  56.  
  57.         if (this.tileEntity.getStackInSlot(1) != null) {
  58.             this.ammoBtn.enabled = this.tileEntity.getStackInSlot(1).getItem() instanceof ItemRcWeap;
  59.            
  60.         } else {
  61.             this.ammoBtn.enabled = false;
  62.             this.updateScreen();
  63.         }
  64.  
  65.     }
  66.  
  67.     public void actionPerformed(GuiButton button) {
  68.         switch (button.id) {
  69.         case 0:
  70.             if (tileEntity.getStackInSlot(1) != null
  71.                     && tileEntity.getStackInSlot(1).getItem() instanceof ItemRcWeap) {
  72.                 int damage = tileEntity.getStackInSlot(1).getItemDamage();
  73.                 ExtendedPlayerBolt props = ExtendedPlayerBolt.get(player);
  74.                 if (props.getCurrentBolt() > damage) {
  75.                     ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
  76.                     DataOutputStream dataoutputstream = new DataOutputStream(
  77.                             bytearrayoutputstream);
  78.                     try {
  79.                         Packet.writeItemStack(tileEntity.getStackInSlot(1),
  80.                                 dataoutputstream);
  81.                         PacketDispatcher
  82.                                 .sendPacketToServer(new Packet250CustomPayload(
  83.                                         "RCMD|vend", bytearrayoutputstream
  84.                                                 .toByteArray()));
  85.                     } catch (Exception exception) {
  86.                         exception.printStackTrace();
  87.                     }
  88.                 }
  89.  
  90.             }
  91.             break;
  92.         default:
  93.         }
  94.     }
  95.  
  96.     @Override
  97.     protected void drawGuiContainerForegroundLayer(int param1, int param2) {
  98.         // draw text and stuff here
  99.         // the parameters for drawString are: string, x, y, color
  100.         fontRenderer.drawString("Vendor", 8, 6, 4210752);
  101.         // draws "Inventory" or your regional equivalent
  102.         fontRenderer.drawString(
  103.                 StatCollector.translateToLocal("container.inventory"), 8,
  104.                 ySize - 96 + 2, 4210752);
  105.     }
  106.  
  107.     @Override
  108.     protected void drawGuiContainerBackgroundLayer(float par1, int par2,
  109.             int par3) {
  110.         GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  111.         this.mc.renderEngine.bindTexture(texturepath);
  112.         int x = (width - xSize) / 2;
  113.         int y = (height - ySize) / 2;
  114.         this.drawTexturedQuadFit(x, y, 256, 256, 0);
  115.     }
  116.  
  117.     @SideOnly(Side.CLIENT)
  118.     public static void drawTexturedQuadFit(double x, double y, double width,
  119.             double height, double zLevel) {
  120.         Tessellator tessellator = Tessellator.instance;
  121.         tessellator.startDrawingQuads();
  122.         tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
  123.         tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
  124.         tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
  125.         tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
  126.         tessellator.draw();
  127.     }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment