Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. package com.TheRPGAdventurer.ROTD.client.gui;
  2.  
  3. import com.TheRPGAdventurer.ROTD.DragonMounts;
  4. import com.TheRPGAdventurer.ROTD.client.inventory.ContainerDragon;
  5. import com.TheRPGAdventurer.ROTD.server.entity.EntityTameableDragon;
  6. import com.TheRPGAdventurer.ROTD.server.network.MessageDragonGui;
  7. import com.TheRPGAdventurer.ROTD.server.network.MessageDragonLock;
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.client.gui.GuiButton;
  10. import net.minecraft.client.gui.inventory.GuiContainer;
  11. import net.minecraft.client.gui.inventory.GuiInventory;
  12. import net.minecraft.client.renderer.GlStateManager;
  13. import net.minecraft.client.resources.I18n;
  14. import net.minecraft.entity.player.EntityPlayer;
  15. import net.minecraft.inventory.IInventory;
  16. import net.minecraft.util.ResourceLocation;
  17. import net.minecraftforge.fml.relauncher.Side;
  18. import net.minecraftforge.fml.relauncher.SideOnly;
  19. import org.lwjgl.input.Keyboard;
  20.  
  21. import java.io.IOException;
  22.  
  23. @SideOnly(Side.CLIENT)
  24. public class GuiDragon extends GuiContainer {
  25.  
  26. private static final ResourceLocation texture = new ResourceLocation(DragonMounts.MODID, "textures/gui/dragon.png");
  27. private IInventory playerInventory;
  28. private IInventory dragonInv;
  29. private EntityTameableDragon dragon;
  30. private float mousePosX;
  31. private float mousePosY;
  32. private LockButton lock;
  33. private GuiButton sit;
  34. public static ResourceLocation lockOpen;
  35. public static ResourceLocation lockLocked;
  36. private EntityPlayer player;
  37.  
  38. public GuiDragon(IInventory playerInv, EntityTameableDragon dragon) {
  39. super(new ContainerDragon(dragon, Minecraft.getMinecraft().player));
  40. this.playerInventory = playerInv;
  41. this.dragonInv = dragon.dragonInv;
  42. this.player = Minecraft.getMinecraft().player;
  43. this.dragon = dragon;
  44. this.allowUserInput = false;
  45. this.ySize = 214;
  46. this.xSize = 176;
  47. lockLocked = new ResourceLocation(DragonMounts.MODID, "textures/gui/lock_2.png");
  48. lockOpen = new ResourceLocation(DragonMounts.MODID, "textures/gui/lock_1.png");
  49.  
  50. }
  51.  
  52. /**
  53. * Draw the foreground layer for the GuiContainer (everything in front of the
  54. * items)
  55. */
  56. protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
  57. this.fontRenderer.drawString(dragon.hasCustomName() ? dragon.getCustomNameTag() : "Dragon Inventory", 8, 6, dragon.getBreed().getColor());
  58. this.fontRenderer.drawString(dragon.isMale() ? "M" : "FM", 160, 6, dragon.isMale() ? 0x0079be : 0Xff8b8b);
  59. }
  60.  
  61. @Override
  62. protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
  63. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  64. this.mc.getTextureManager().bindTexture(texture);
  65. int x = (this.width - this.xSize) / 2;
  66. int y = (this.height - this.ySize) / 2;
  67. this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize);
  68. if (dragon.isChested()) {
  69. this.drawTexturedModalRect(x + 0, y + 73, 0, 130, 170, 55);
  70. }
  71. GuiInventory.drawEntityOnScreen(x + 80, y + 65, (int) (13 / dragon.getScale()), x + 51 - this.mousePosX, y + 75 - 50 - this.mousePosY,
  72. this.dragon);
  73. }
  74.  
  75. @Override
  76. public void initGui() {
  77. this.buttonList.clear();
  78. Keyboard.enableRepeatEvents(true);
  79.  
  80. lock = new LockButton(0, width / 2 + 68, height / 2 - 54, 16, 16, I18n.format("gui.allowothers", new Object[0]), dragon);
  81. sit = new GuiButton(1, width / 2 + 47, height / 2 - 53, 18, 14, "SIT");
  82.  
  83. buttonList.add(lock);
  84. buttonList.add(sit);
  85. super.initGui();
  86. }
  87.  
  88. @Override
  89. protected void actionPerformed(GuiButton button) throws IOException {
  90. boolean sit = (button == this.sit);
  91. boolean lock = (button == this.lock);
  92.  
  93. if (sit) {
  94. DragonMounts.NETWORK_WRAPPER.sendToServer(new MessageDragonGui(dragon.getEntityId()));
  95. } else if (lock) {
  96. DragonMounts.NETWORK_WRAPPER.sendToServer(new MessageDragonLock(dragon.getEntityId()));
  97. }
  98.  
  99. }
  100.  
  101. public void updateScreen() {
  102. lock.enable = (player == dragon.getOwner());
  103. }
  104.  
  105. @Override
  106. public void drawScreen(int mouseX, int mouseY, float partialTicks) {
  107. this.drawDefaultBackground();
  108. // this.mousePosX = mouseX;
  109. // this.mousePosY = mouseY;
  110. super.drawScreen(mouseX, mouseY, partialTicks);
  111. this.renderHoveredToolTip(mouseX, mouseY);
  112. }
  113.  
  114. static class LockButton extends GuiButton {
  115.  
  116. private boolean enable;
  117. private EntityTameableDragon dragon;
  118.  
  119. public LockButton(int buttonId, int x, int y, int i, int j, String buttonText, EntityTameableDragon dragon) {
  120. super(buttonId, x, y, i, j, buttonText);
  121. this.dragon = dragon;
  122. }
  123.  
  124. @Override
  125. public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
  126. return enable && super.mousePressed(mc, mouseX, mouseY);
  127. }
  128.  
  129. /**
  130. * Draws this button to the screen.
  131. */
  132. @Override
  133. public void drawButton(Minecraft mc, int parX, int parY, float partialTicks) {
  134. if (visible) {
  135. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  136.  
  137. if (dragon.allowedOtherPlayers()) {
  138. mc.getTextureManager().bindTexture(lockOpen);
  139. } else if (!dragon.allowedOtherPlayers()) {
  140. mc.getTextureManager().bindTexture(lockLocked);
  141. }
  142. drawModalRectWithCustomSizedTexture(x, y, 0.0F, 0.0F, 16, 16, 16, 16);
  143. }
  144. }
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement