Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gugu42.rcmod.gui;
- import java.io.ByteArrayOutputStream;
- import java.io.DataOutputStream;
- import org.lwjgl.opengl.GL11;
- import com.gugu42.rcmod.ContainerVendor;
- import com.gugu42.rcmod.RcMod;
- import com.gugu42.rcmod.bolts.ExtendedPlayerBolt;
- import com.gugu42.rcmod.tileentity.TileEntityVendor;
- import com.gugu42.rcmod.items.ItemRcWeap;
- import cpw.mods.fml.common.network.PacketDispatcher;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- import net.minecraft.client.gui.GuiButton;
- import net.minecraft.client.gui.inventory.GuiContainer;
- import net.minecraft.client.renderer.Tessellator;
- import net.minecraft.client.resources.I18n;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.network.packet.Packet;
- import net.minecraft.network.packet.Packet250CustomPayload;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.StatCollector;
- @SideOnly(Side.CLIENT)
- public class GuiVendor extends GuiContainer {
- private static final ResourceLocation texturepath = new ResourceLocation(
- "rcmod", "textures/gui/vendor.png");
- private GuiButton ammoBtn;
- private TileEntityVendor tileEntity;
- private EntityPlayer player;
- public GuiVendor(InventoryPlayer inventoryPlayer,
- TileEntityVendor tileEntity, EntityPlayer player) {
- super(new ContainerVendor(inventoryPlayer, tileEntity));
- this.tileEntity = tileEntity;
- this.player = player;
- this.xSize = 176;
- this.ySize = 222;
- }
- @Override
- public void initGui() {
- super.initGui();
- this.buttonList.clear();
- int posX = (this.width - xSize) / 2;
- int posY = (this.height - ySize) / 2;
- this.buttonList.add(this.ammoBtn = new GuiButton(0, posX + 13,
- posY + 35, 33, 20, "Refill"));
- if (this.tileEntity.getStackInSlot(1) != null) {
- this.ammoBtn.enabled = this.tileEntity.getStackInSlot(1).getItem() instanceof ItemRcWeap;
- } else {
- this.ammoBtn.enabled = false;
- this.updateScreen();
- }
- }
- public void actionPerformed(GuiButton button) {
- switch (button.id) {
- case 0:
- if (tileEntity.getStackInSlot(1) != null
- && tileEntity.getStackInSlot(1).getItem() instanceof ItemRcWeap) {
- int damage = tileEntity.getStackInSlot(1).getItemDamage();
- ExtendedPlayerBolt props = ExtendedPlayerBolt.get(player);
- if (props.getCurrentBolt() > damage) {
- ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
- DataOutputStream dataoutputstream = new DataOutputStream(
- bytearrayoutputstream);
- try {
- Packet.writeItemStack(tileEntity.getStackInSlot(1),
- dataoutputstream);
- PacketDispatcher
- .sendPacketToServer(new Packet250CustomPayload(
- "RCMD|vend", bytearrayoutputstream
- .toByteArray()));
- } catch (Exception exception) {
- exception.printStackTrace();
- }
- }
- }
- break;
- default:
- }
- }
- @Override
- protected void drawGuiContainerForegroundLayer(int param1, int param2) {
- // draw text and stuff here
- // the parameters for drawString are: string, x, y, color
- fontRenderer.drawString("Vendor", 8, 6, 4210752);
- // draws "Inventory" or your regional equivalent
- fontRenderer.drawString(
- StatCollector.translateToLocal("container.inventory"), 8,
- ySize - 96 + 2, 4210752);
- }
- @Override
- protected void drawGuiContainerBackgroundLayer(float par1, int par2,
- int par3) {
- GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- this.mc.renderEngine.bindTexture(texturepath);
- int x = (width - xSize) / 2;
- int y = (height - ySize) / 2;
- this.drawTexturedQuadFit(x, y, 256, 256, 0);
- }
- @SideOnly(Side.CLIENT)
- public static void drawTexturedQuadFit(double x, double y, double width,
- double height, double zLevel) {
- Tessellator tessellator = Tessellator.instance;
- tessellator.startDrawingQuads();
- tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
- tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
- tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
- tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
- tessellator.draw();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment