Guest User

Untitled

a guest
Nov 27th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. package panda.glassworks.gui;
  2.  
  3. import io.netty.buffer.Unpooled;
  4.  
  5. import java.io.IOException;
  6. import java.util.List;
  7. import java.util.Map;
  8.  
  9. import com.google.common.collect.Lists;
  10.  
  11. import panda.glassworks.init.Recipes;
  12. import panda.glassworks.util.GlassBlowingRecipes;
  13. import net.minecraft.client.Minecraft;
  14. import net.minecraft.client.audio.SoundHandler;
  15. import net.minecraft.client.gui.GuiButton;
  16. import net.minecraft.client.gui.GuiMerchant;
  17. import net.minecraft.client.gui.inventory.GuiContainer;
  18. import net.minecraft.client.renderer.GlStateManager;
  19. import net.minecraft.client.resources.I18n;
  20. import net.minecraft.entity.player.InventoryPlayer;
  21. import net.minecraft.inventory.ContainerMerchant;
  22. import net.minecraft.inventory.ContainerWorkbench;
  23. import net.minecraft.item.ItemStack;
  24. import net.minecraft.network.PacketBuffer;
  25. import net.minecraft.network.play.client.CPacketCustomPayload;
  26. import net.minecraft.util.ResourceLocation;
  27. import net.minecraft.util.math.BlockPos;
  28. import net.minecraft.village.MerchantRecipeList;
  29. import net.minecraft.world.World;
  30. import net.minecraftforge.fml.relauncher.Side;
  31. import net.minecraftforge.fml.relauncher.SideOnly;
  32.  
  33. @SideOnly(Side.CLIENT)
  34. public class GuiBlowpipe extends GuiContainer
  35. {
  36. private static final ResourceLocation BLOWPIPE_GUI_TEXTURES = new ResourceLocation("glassworks:textures/gui/blowpipe.png");
  37.  
  38. /** The button which proceeds to the next available merchant recipe. */
  39. private GuiBlowpipe.Button nextButton;
  40. /** Returns to the previous Merchant recipe if one is applicable. */
  41. private GuiBlowpipe.Button previousButton;
  42.  
  43. private int selectedRecipe;
  44.  
  45. public GuiBlowpipe(InventoryPlayer playerInv, World worldIn)
  46. {
  47. this(playerInv, worldIn, BlockPos.ORIGIN);
  48.  
  49. }
  50.  
  51. @Override
  52. public void initGui() {
  53. super.initGui();
  54. this.nextButton = new GuiBlowpipe.Button(1, guiLeft + 136, guiTop +4, true);
  55. this.previousButton = new GuiBlowpipe.Button(2, guiLeft + 136, guiTop +44, false);
  56.  
  57.  
  58. this.buttonList.add(nextButton);
  59. this.buttonList.add(previousButton);
  60. }
  61.  
  62. public GuiBlowpipe(InventoryPlayer playerInv, World worldIn, BlockPos blockPosition)
  63. {
  64. super(new ContainerBlowpipe(playerInv, worldIn, blockPosition));
  65. this.xSize = 176;
  66. this.ySize = 140;
  67. this.guiLeft = Math.abs((this.width - this.xSize) / 2);
  68. this.guiTop = Math.abs((this.height - this.ySize) / 2);
  69. this.selectedRecipe = 0;
  70.  
  71. }
  72.  
  73. @Override
  74. public void updateScreen() {
  75. super.updateScreen();
  76.  
  77. if(hasInput()){
  78. List<ItemStack> recipelist = GlassBlowingRecipes.getGlassBlowingResultList(inputStack());
  79. if (recipelist != null)
  80. {
  81. this.nextButton.enabled = this.selectedRecipe < recipelist.size()-1;
  82. this.previousButton.enabled = this.selectedRecipe > 0;
  83. }
  84. }else{
  85. this.nextButton.enabled = false;
  86. this.previousButton.enabled = false;
  87. this.selectedRecipe = 0;
  88.  
  89. }
  90.  
  91. ((ContainerBlowpipe)this.inventorySlots).onCraftMatrixChanged();
  92. }
  93.  
  94. boolean hasInput(){
  95. return ((ContainerBlowpipe)this.inventorySlots).getInventory().get(0) != null;
  96. }
  97.  
  98. ItemStack inputStack(){
  99. return ((ContainerBlowpipe)this.inventorySlots).getInventory().get(0);
  100. }
  101.  
  102.  
  103.  
  104. @Override
  105. protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
  106.  
  107. super.mouseClicked(mouseX, mouseY, mouseButton);
  108.  
  109. }
  110.  
  111.  
  112. //Button Calls
  113. @Override
  114. protected void actionPerformed(GuiButton button) throws IOException
  115. {
  116. boolean flag = false;
  117. //System.out.println("TOP BUTTON PRESSED");
  118. if (button.id ==1)
  119. {
  120.  
  121. if(hasInput()){
  122.  
  123. ++this.selectedRecipe;
  124.  
  125. List<ItemStack> recipelist = GlassBlowingRecipes.getGlassBlowingResultList(inputStack());
  126. if (recipelist != null )
  127. {
  128. if(!recipelist.isEmpty()){
  129.  
  130. if(this.selectedRecipe > GlassBlowingRecipes.getGlassBlowingResultList(inputStack()).size()-1){
  131. this.selectedRecipe = GlassBlowingRecipes.getGlassBlowingResultList(inputStack()).size();
  132. }
  133. }
  134. }
  135. }else{
  136. this.selectedRecipe = 0;
  137. }
  138.  
  139. flag = true;
  140. }
  141. else if (button.id ==2)
  142. {
  143. if(hasInput()){
  144. --this.selectedRecipe;
  145. if (this.selectedRecipe < 0)
  146. {
  147. this.selectedRecipe = 0;
  148. }
  149. }else{
  150. this.selectedRecipe = 0;
  151. }
  152. //System.out.println("BOTTOM BUTTON PRESSED");
  153.  
  154.  
  155. flag = true;
  156. }
  157. System.out.println(selectedRecipe);
  158.  
  159. if (flag)
  160. {
  161. ((ContainerBlowpipe)this.inventorySlots).setCurrentRecipeIndex(this.selectedRecipe);
  162. PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
  163. packetbuffer.writeInt(this.selectedRecipe);
  164. this.mc.getConnection().sendPacket(new CPacketCustomPayload("GB|CrSel", packetbuffer));
  165. }
  166.  
  167. }
  168.  
  169. /**
  170. * Draw the foreground layer for the GuiContainer (everything in front of the items)
  171. */
  172. protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
  173. {
  174. this.fontRendererObj.drawString(I18n.format("container.crafting", new Object[0]), 9, 9, 4210752);
  175. this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize -95, 4210752);
  176. }
  177.  
  178. /**
  179. * Draws the background layer of this container (behind the items).
  180. */
  181. protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
  182. {
  183. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  184. this.mc.getTextureManager().bindTexture(BLOWPIPE_GUI_TEXTURES);
  185. this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
  186. }
  187.  
  188. @SideOnly(Side.CLIENT)
  189. static class Button extends GuiButton
  190. {
  191. private final boolean up;
  192.  
  193. public Button(int buttonID, int x, int y, boolean isUp)
  194. {
  195. super(buttonID, x, y, 13, 9, "");
  196. this.width = 19;
  197. this.height = 12;
  198. this.up = isUp;
  199. }
  200.  
  201. @Override
  202. public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
  203.  
  204. return super.mousePressed(mc, mouseX, mouseY);
  205. }
  206.  
  207. @Override
  208. public void playPressSound(SoundHandler soundHandlerIn) {
  209. // TODO Auto-generated method stub
  210. super.playPressSound(soundHandlerIn);
  211. }
  212.  
  213. /**
  214. * Draws this button to the screen.
  215. */
  216. public void drawButton(Minecraft mc, int mouseX, int mouseY)
  217. {
  218.  
  219. if (this.visible)
  220. {
  221. mc.getTextureManager().bindTexture(BLOWPIPE_GUI_TEXTURES);
  222. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  223. boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
  224. int j = 0;
  225. int i = 176;
  226. int hOffset = this.xPosition; //136;
  227. int vOffset = this.yPosition;//4;
  228.  
  229.  
  230. if (!this.enabled) //disabled button
  231. {
  232. j += this.height * 2;
  233. //System.out.println((mouseX >= this.xPosition )+","+(mouseY >= this.yPosition)+","+(mouseX < this.xPosition + this.width)+","+(mouseY < this.yPosition + this.height));
  234. }
  235. else
  236. if (flag)//mouse hover
  237. {
  238. j += this.height;
  239.  
  240.  
  241. }
  242.  
  243. if (!this.up)
  244. {
  245. i += this.width;
  246. }
  247.  
  248. if(this.up){
  249. this.drawTexturedModalRect(hOffset, vOffset, i, j, this.width, this.height);
  250. }else{
  251. this.drawTexturedModalRect(hOffset, vOffset, i, j, this.width, this.height);
  252. }
  253. }
  254. }
  255. }
  256. }
Add Comment
Please, Sign In to add comment