| 1 | package net.minecraft.client.gui.inventory;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.io.IOException;
|
| 5 | import java.util.Iterator;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Map;
|
| 8 | import net.minecraft.client.gui.GuiButton;
|
| 9 | import net.minecraft.client.gui.GuiTextField;
|
| 10 | import net.minecraft.client.gui.achievement.GuiAchievements;
|
| 11 | import net.minecraft.client.gui.achievement.GuiStats;
|
| 12 | import net.minecraft.client.renderer.GlStateManager;
|
| 13 | import net.minecraft.client.renderer.InventoryEffectRenderer;
|
| 14 | import net.minecraft.client.renderer.RenderHelper;
|
| 15 | import net.minecraft.client.resources.I18n;
|
| 16 | import net.minecraft.client.settings.GameSettings;
|
| 17 | import net.minecraft.creativetab.CreativeTabs;
|
| 18 | import net.minecraft.enchantment.Enchantment;
|
| 19 | import net.minecraft.enchantment.EnchantmentHelper;
|
| 20 | import net.minecraft.entity.player.EntityPlayer;
|
| 21 | import net.minecraft.entity.player.InventoryPlayer;
|
| 22 | import net.minecraft.init.Items;
|
| 23 | import net.minecraft.inventory.Container;
|
| 24 | import net.minecraft.inventory.IInventory;
|
| 25 | import net.minecraft.inventory.InventoryBasic;
|
| 26 | import net.minecraft.inventory.Slot;
|
| 27 | import net.minecraft.item.Item;
|
| 28 | import net.minecraft.item.ItemStack;
|
| 29 | import net.minecraft.util.EnumChatFormatting;
|
| 30 | import net.minecraft.util.MathHelper;
|
| 31 | import net.minecraft.util.ResourceLocation;
|
| 32 | import org.lwjgl.input.Keyboard;
|
| 33 | import org.lwjgl.input.Mouse;
|
| 34 |
|
| 35 | public class GuiContainerCreative extends InventoryEffectRenderer
|
| 36 | {
|
| 37 | /** The location of the creative inventory tabs texture */
|
| 38 | private static final ResourceLocation creativeInventoryTabs = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
|
| 39 | private static InventoryBasic field_147060_v = new InventoryBasic("tmp", true, 45);
|
| 40 |
|
| 41 | /** Currently selected creative inventory tab index. */
|
| 42 | private static int selectedTabIndex = CreativeTabs.tabBlock.getTabIndex();
|
| 43 |
|
| 44 | /** Amount scrolled in Creative mode inventory (0 = top, 1 = bottom) */
|
| 45 | private float currentScroll;
|
| 46 |
|
| 47 | /** True if the scrollbar is being dragged */
|
| 48 | private boolean isScrolling;
|
| 49 |
|
| 50 | /**
|
| 51 | * True if the left mouse button was held down last time drawScreen was called.
|
| 52 | */
|
| 53 | private boolean wasClicking;
|
| 54 | private GuiTextField searchField;
|
| 55 | private List<Slot> field_147063_B;
|
| 56 | private Slot field_147064_C;
|
| 57 | private boolean field_147057_D;
|
| 58 | private CreativeCrafting field_147059_E;
|
| 59 |
|
| 60 | public GuiContainerCreative(EntityPlayer p_i1088_1_)
|
| 61 | {
|
| 62 | super(new GuiContainerCreative.ContainerCreative(p_i1088_1_));
|
| 63 | p_i1088_1_.openContainer = this.inventorySlots;
|
| 64 | this.allowUserInput = true;
|
| 65 | this.ySize = 136;
|
| 66 | this.xSize = 195;
|
| 67 | }
|
| 68 |
|
| 69 | /**
|
| 70 | * Called from the main game loop to update the screen.
|
| 71 | */
|
| 72 | public void updateScreen()
|
| 73 | {
|
| 74 | if (!this.mc.playerController.isInCreativeMode())
|
| 75 | {
|
| 76 | this.mc.displayGuiScreen(new GuiInventory(this.mc.thePlayer));
|
| 77 | }
|
| 78 |
|
| 79 | this.updateActivePotionEffects();
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Called when the mouse is clicked over a slot or outside the gui.
|
| 84 | */
|
| 85 | protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType)
|
| 86 | {
|
| 87 | this.field_147057_D = true;
|
| 88 | boolean flag = clickType == 1;
|
| 89 | clickType = slotId == -999 && clickType == 0 ? 4 : clickType;
|
| 90 |
|
| 91 | if (slotIn == null && selectedTabIndex != CreativeTabs.tabInventory.getTabIndex() && clickType != 5)
|
| 92 | {
|
| 93 | InventoryPlayer inventoryplayer1 = this.mc.thePlayer.inventory;
|
| 94 |
|
| 95 | if (inventoryplayer1.getItemStack() != null)
|
| 96 | {
|
| 97 | if (clickedButton == 0)
|
| 98 | {
|
| 99 | this.mc.thePlayer.dropPlayerItemWithRandomChoice(inventoryplayer1.getItemStack(), true);
|
| 100 | this.mc.playerController.sendPacketDropItem(inventoryplayer1.getItemStack());
|
| 101 | inventoryplayer1.setItemStack((ItemStack)null);
|
| 102 | }
|
| 103 |
|
| 104 | if (clickedButton == 1)
|
| 105 | {
|
| 106 | ItemStack itemstack5 = inventoryplayer1.getItemStack().splitStack(1);
|
| 107 | this.mc.thePlayer.dropPlayerItemWithRandomChoice(itemstack5, true);
|
| 108 | this.mc.playerController.sendPacketDropItem(itemstack5);
|
| 109 |
|
| 110 | if (inventoryplayer1.getItemStack().stackSize == 0)
|
| 111 | {
|
| 112 | inventoryplayer1.setItemStack((ItemStack)null);
|
| 113 | }
|
| 114 | }
|
| 115 | }
|
| 116 | }
|
| 117 | else if (slotIn == this.field_147064_C && flag)
|
| 118 | {
|
| 119 | for (int j = 0; j < this.mc.thePlayer.inventoryContainer.getInventory().size(); ++j)
|
| 120 | {
|
| 121 | this.mc.playerController.sendSlotPacket((ItemStack)null, j);
|
| 122 | }
|
| 123 | }
|
| 124 | else if (selectedTabIndex == CreativeTabs.tabInventory.getTabIndex())
|
| 125 | {
|
| 126 | if (slotIn == this.field_147064_C)
|
| 127 | {
|
| 128 | this.mc.thePlayer.inventory.setItemStack((ItemStack)null);
|
| 129 | }
|
| 130 | else if (clickType == 4 && slotIn != null && slotIn.getHasStack())
|
| 131 | {
|
| 132 | ItemStack itemstack = slotIn.decrStackSize(clickedButton == 0 ? 1 : slotIn.getStack().getMaxStackSize());
|
| 133 | this.mc.thePlayer.dropPlayerItemWithRandomChoice(itemstack, true);
|
| 134 | this.mc.playerController.sendPacketDropItem(itemstack);
|
| 135 | }
|
| 136 | else if (clickType == 4 && this.mc.thePlayer.inventory.getItemStack() != null)
|
| 137 | {
|
| 138 | this.mc.thePlayer.dropPlayerItemWithRandomChoice(this.mc.thePlayer.inventory.getItemStack(), true);
|
| 139 | this.mc.playerController.sendPacketDropItem(this.mc.thePlayer.inventory.getItemStack());
|
| 140 | this.mc.thePlayer.inventory.setItemStack((ItemStack)null);
|
| 141 | }
|
| 142 | else
|
| 143 | {
|
| 144 | this.mc.thePlayer.inventoryContainer.slotClick(slotIn == null ? slotId : ((GuiContainerCreative.CreativeSlot)slotIn).slot.slotNumber, clickedButton, clickType, this.mc.thePlayer);
|
| 145 | this.mc.thePlayer.inventoryContainer.detectAndSendChanges();
|
| 146 | }
|
| 147 | }
|
| 148 | else if (clickType != 5 && slotIn.inventory == field_147060_v)
|
| 149 | {
|
| 150 | InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;
|
| 151 | ItemStack itemstack1 = inventoryplayer.getItemStack();
|
| 152 | ItemStack itemstack2 = slotIn.getStack();
|
| 153 |
|
| 154 | if (clickType == 2)
|
| 155 | {
|
| 156 | if (itemstack2 != null && clickedButton >= 0 && clickedButton < 9)
|
| 157 | {
|
| 158 | ItemStack itemstack7 = itemstack2.copy();
|
| 159 | itemstack7.stackSize = itemstack7.getMaxStackSize();
|
| 160 | this.mc.thePlayer.inventory.setInventorySlotContents(clickedButton, itemstack7);
|
| 161 | this.mc.thePlayer.inventoryContainer.detectAndSendChanges();
|
| 162 | }
|
| 163 |
|
| 164 | return;
|
| 165 | }
|
| 166 |
|
| 167 | if (clickType == 3)
|
| 168 | {
|
| 169 | if (inventoryplayer.getItemStack() == null && slotIn.getHasStack())
|
| 170 | {
|
| 171 | ItemStack itemstack6 = slotIn.getStack().copy();
|
| 172 | itemstack6.stackSize = itemstack6.getMaxStackSize();
|
| 173 | inventoryplayer.setItemStack(itemstack6);
|
| 174 | }
|
| 175 |
|
| 176 | return;
|
| 177 | }
|
| 178 |
|
| 179 | if (clickType == 4)
|
| 180 | {
|
| 181 | if (itemstack2 != null)
|
| 182 | {
|
| 183 | ItemStack itemstack3 = itemstack2.copy();
|
| 184 | itemstack3.stackSize = clickedButton == 0 ? 1 : itemstack3.getMaxStackSize();
|
| 185 | this.mc.thePlayer.dropPlayerItemWithRandomChoice(itemstack3, true);
|
| 186 | this.mc.playerController.sendPacketDropItem(itemstack3);
|
| 187 | }
|
| 188 |
|
| 189 | return;
|
| 190 | }
|
| 191 |
|
| 192 | if (itemstack1 != null && itemstack2 != null && itemstack1.isItemEqual(itemstack2))
|
| 193 | {
|
| 194 | if (clickedButton == 0)
|
| 195 | {
|
| 196 | if (flag)
|
| 197 | {
|
| 198 | itemstack1.stackSize = itemstack1.getMaxStackSize();
|
| 199 | }
|
| 200 | else if (itemstack1.stackSize < itemstack1.getMaxStackSize())
|
| 201 | {
|
| 202 | ++itemstack1.stackSize;
|
| 203 | }
|
| 204 | }
|
| 205 | else if (itemstack1.stackSize <= 1)
|
| 206 | {
|
| 207 | inventoryplayer.setItemStack((ItemStack)null);
|
| 208 | }
|
| 209 | else
|
| 210 | {
|
| 211 | --itemstack1.stackSize;
|
| 212 | }
|
| 213 | }
|
| 214 | else if (itemstack2 != null && itemstack1 == null)
|
| 215 | {
|
| 216 | inventoryplayer.setItemStack(ItemStack.copyItemStack(itemstack2));
|
| 217 | itemstack1 = inventoryplayer.getItemStack();
|
| 218 |
|
| 219 | if (flag)
|
| 220 | {
|
| 221 | itemstack1.stackSize = itemstack1.getMaxStackSize();
|
| 222 | }
|
| 223 | }
|
| 224 | else
|
| 225 | {
|
| 226 | inventoryplayer.setItemStack((ItemStack)null);
|
| 227 | }
|
| 228 | }
|
| 229 | else
|
| 230 | {
|
| 231 | this.inventorySlots.slotClick(slotIn == null ? slotId : slotIn.slotNumber, clickedButton, clickType, this.mc.thePlayer);
|
| 232 |
|
| 233 | if (Container.getDragEvent(clickedButton) == 2)
|
| 234 | {
|
| 235 | for (int i = 0; i < 9; ++i)
|
| 236 | {
|
| 237 | this.mc.playerController.sendSlotPacket(this.inventorySlots.getSlot(45 + i).getStack(), 36 + i);
|
| 238 | }
|
| 239 | }
|
| 240 | else if (slotIn != null)
|
| 241 | {
|
| 242 | ItemStack itemstack4 = this.inventorySlots.getSlot(slotIn.slotNumber).getStack();
|
| 243 | this.mc.playerController.sendSlotPacket(itemstack4, slotIn.slotNumber - this.inventorySlots.inventorySlots.size() + 9 + 36);
|
| 244 | }
|
| 245 | }
|
| 246 | }
|
| 247 |
|
| 248 | protected void updateActivePotionEffects()
|
| 249 | {
|
| 250 | int i = this.guiLeft;
|
| 251 | super.updateActivePotionEffects();
|
| 252 |
|
| 253 | if (this.searchField != null && this.guiLeft != i)
|
| 254 | {
|
| 255 | this.searchField.xPosition = this.guiLeft + 82;
|
| 256 | }
|
| 257 | }
|
| 258 |
|
| 259 | /**
|
| 260 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 261 | * window resizes, the buttonList is cleared beforehand.
|
| 262 | */
|
| 263 | public void initGui()
|
| 264 | {
|
| 265 | if (this.mc.playerController.isInCreativeMode())
|
| 266 | {
|
| 267 | super.initGui();
|
| 268 | this.buttonList.clear();
|
| 269 | Keyboard.enableRepeatEvents(true);
|
| 270 | this.searchField = new GuiTextField(0, this.fontRendererObj, this.guiLeft + 82, this.guiTop + 6, 89, this.fontRendererObj.FONT_HEIGHT);
|
| 271 | this.searchField.setMaxStringLength(15);
|
| 272 | this.searchField.setEnableBackgroundDrawing(false);
|
| 273 | this.searchField.setVisible(false);
|
| 274 | this.searchField.setTextColor(16777215);
|
| 275 | int i = selectedTabIndex;
|
| 276 | selectedTabIndex = -1;
|
| 277 | this.setCurrentCreativeTab(CreativeTabs.creativeTabArray[i]);
|
| 278 | this.field_147059_E = new CreativeCrafting(this.mc);
|
| 279 | this.mc.thePlayer.inventoryContainer.onCraftGuiOpened(this.field_147059_E);
|
| 280 | }
|
| 281 | else
|
| 282 | {
|
| 283 | this.mc.displayGuiScreen(new GuiInventory(this.mc.thePlayer));
|
| 284 | }
|
| 285 | }
|
| 286 |
|
| 287 | /**
|
| 288 | * Called when the screen is unloaded. Used to disable keyboard repeat events
|
| 289 | */
|
| 290 | public void onGuiClosed()
|
| 291 | {
|
| 292 | super.onGuiClosed();
|
| 293 |
|
| 294 | if (this.mc.thePlayer != null && this.mc.thePlayer.inventory != null)
|
| 295 | {
|
| 296 | this.mc.thePlayer.inventoryContainer.removeCraftingFromCrafters(this.field_147059_E);
|
| 297 | }
|
| 298 |
|
| 299 | Keyboard.enableRepeatEvents(false);
|
| 300 | }
|
| 301 |
|
| 302 | /**
|
| 303 | * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
|
| 304 | * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
|
| 305 | */
|
| 306 | protected void keyTyped(char typedChar, int keyCode) throws IOException
|
| 307 | {
|
| 308 | if (selectedTabIndex != CreativeTabs.tabAllSearch.getTabIndex())
|
| 309 | {
|
| 310 | if (GameSettings.isKeyDown(this.mc.gameSettings.keyBindChat))
|
| 311 | {
|
| 312 | this.setCurrentCreativeTab(CreativeTabs.tabAllSearch);
|
| 313 | }
|
| 314 | else
|
| 315 | {
|
| 316 | super.keyTyped(typedChar, keyCode);
|
| 317 | }
|
| 318 | }
|
| 319 | else
|
| 320 | {
|
| 321 | if (this.field_147057_D)
|
| 322 | {
|
| 323 | this.field_147057_D = false;
|
| 324 | this.searchField.setText("");
|
| 325 | }
|
| 326 |
|
| 327 | if (!this.checkHotbarKeys(keyCode))
|
| 328 | {
|
| 329 | if (this.searchField.textboxKeyTyped(typedChar, keyCode))
|
| 330 | {
|
| 331 | this.updateCreativeSearch();
|
| 332 | }
|
| 333 | else
|
| 334 | {
|
| 335 | super.keyTyped(typedChar, keyCode);
|
| 336 | }
|
| 337 | }
|
| 338 | }
|
| 339 | }
|
| 340 |
|
| 341 | private void updateCreativeSearch()
|
| 342 | {
|
| 343 | GuiContainerCreative.ContainerCreative guicontainercreative$containercreative = (GuiContainerCreative.ContainerCreative)this.inventorySlots;
|
| 344 | guicontainercreative$containercreative.itemList.clear();
|
| 345 |
|
| 346 | for (Item item : Item.itemRegistry)
|
| 347 | {
|
| 348 | if (item != null && item.getCreativeTab() != null)
|
| 349 | {
|
| 350 | item.getSubItems(item, (CreativeTabs)null, guicontainercreative$containercreative.itemList);
|
| 351 | }
|
| 352 | }
|
| 353 |
|
| 354 | for (Enchantment enchantment : Enchantment.enchantmentsBookList)
|
| 355 | {
|
| 356 | if (enchantment != null && enchantment.type != null)
|
| 357 | {
|
| 358 | Items.enchanted_book.getAll(enchantment, guicontainercreative$containercreative.itemList);
|
| 359 | }
|
| 360 | }
|
| 361 |
|
| 362 | Iterator<ItemStack> iterator = guicontainercreative$containercreative.itemList.iterator();
|
| 363 | String s1 = this.searchField.getText().toLowerCase();
|
| 364 |
|
| 365 | while (iterator.hasNext())
|
| 366 | {
|
| 367 | ItemStack itemstack = (ItemStack)iterator.next();
|
| 368 | boolean flag = false;
|
| 369 |
|
| 370 | for (String s : itemstack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips))
|
| 371 | {
|
| 372 | if (EnumChatFormatting.getTextWithoutFormattingCodes(s).toLowerCase().contains(s1))
|
| 373 | {
|
| 374 | flag = true;
|
| 375 | break;
|
| 376 | }
|
| 377 | }
|
| 378 |
|
| 379 | if (!flag)
|
| 380 | {
|
| 381 | iterator.remove();
|
| 382 | }
|
| 383 | }
|
| 384 |
|
| 385 | this.currentScroll = 0.0F;
|
| 386 | guicontainercreative$containercreative.scrollTo(0.0F);
|
| 387 | }
|
| 388 |
|
| 389 | /**
|
| 390 | * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
|
| 391 | */
|
| 392 | protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
| 393 | {
|
| 394 | CreativeTabs creativetabs = CreativeTabs.creativeTabArray[selectedTabIndex];
|
| 395 |
|
| 396 | if (creativetabs.drawInForegroundOfTab())
|
| 397 | {
|
| 398 | GlStateManager.disableBlend();
|
| 399 | this.fontRendererObj.drawString(I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]), 8, 6, 4210752);
|
| 400 | }
|
| 401 | }
|
| 402 |
|
| 403 | /**
|
| 404 | * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
|
| 405 | */
|
| 406 | protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
|
| 407 | {
|
| 408 | if (mouseButton == 0)
|
| 409 | {
|
| 410 | int i = mouseX - this.guiLeft;
|
| 411 | int j = mouseY - this.guiTop;
|
| 412 |
|
| 413 | for (CreativeTabs creativetabs : CreativeTabs.creativeTabArray)
|
| 414 | {
|
| 415 | if (this.func_147049_a(creativetabs, i, j))
|
| 416 | {
|
| 417 | return;
|
| 418 | }
|
| 419 | }
|
| 420 | }
|
| 421 |
|
| 422 | super.mouseClicked(mouseX, mouseY, mouseButton);
|
| 423 | }
|
| 424 |
|
| 425 | /**
|
| 426 | * Called when a mouse button is released. Args : mouseX, mouseY, releaseButton
|
| 427 | */
|
| 428 | protected void mouseReleased(int mouseX, int mouseY, int state)
|
| 429 | {
|
| 430 | if (state == 0)
|
| 431 | {
|
| 432 | int i = mouseX - this.guiLeft;
|
| 433 | int j = mouseY - this.guiTop;
|
| 434 |
|
| 435 | for (CreativeTabs creativetabs : CreativeTabs.creativeTabArray)
|
| 436 | {
|
| 437 | if (this.func_147049_a(creativetabs, i, j))
|
| 438 | {
|
| 439 | this.setCurrentCreativeTab(creativetabs);
|
| 440 | return;
|
| 441 | }
|
| 442 | }
|
| 443 | }
|
| 444 |
|
| 445 | super.mouseReleased(mouseX, mouseY, state);
|
| 446 | }
|
| 447 |
|
| 448 | /**
|
| 449 | * returns (if you are not on the inventoryTab) and (the flag isn't set) and (you have more than 1 page of items)
|
| 450 | */
|
| 451 | private boolean needsScrollBars()
|
| 452 | {
|
| 453 | return selectedTabIndex != CreativeTabs.tabInventory.getTabIndex() && CreativeTabs.creativeTabArray[selectedTabIndex].shouldHidePlayerInventory() && ((GuiContainerCreative.ContainerCreative)this.inventorySlots).func_148328_e();
|
| 454 | }
|
| 455 |
|
| 456 | private void setCurrentCreativeTab(CreativeTabs p_147050_1_)
|
| 457 | {
|
| 458 | int i = selectedTabIndex;
|
| 459 | selectedTabIndex = p_147050_1_.getTabIndex();
|
| 460 | GuiContainerCreative.ContainerCreative guicontainercreative$containercreative = (GuiContainerCreative.ContainerCreative)this.inventorySlots;
|
| 461 | this.dragSplittingSlots.clear();
|
| 462 | guicontainercreative$containercreative.itemList.clear();
|
| 463 | p_147050_1_.displayAllReleventItems(guicontainercreative$containercreative.itemList);
|
| 464 |
|
| 465 | if (p_147050_1_ == CreativeTabs.tabInventory)
|
| 466 | {
|
| 467 | Container container = this.mc.thePlayer.inventoryContainer;
|
| 468 |
|
| 469 | if (this.field_147063_B == null)
|
| 470 | {
|
| 471 | this.field_147063_B = guicontainercreative$containercreative.inventorySlots;
|
| 472 | }
|
| 473 |
|
| 474 | guicontainercreative$containercreative.inventorySlots = Lists.<Slot>newArrayList();
|
| 475 |
|
| 476 | for (int j = 0; j < container.inventorySlots.size(); ++j)
|
| 477 | {
|
| 478 | Slot slot = new GuiContainerCreative.CreativeSlot((Slot)container.inventorySlots.get(j), j);
|
| 479 | guicontainercreative$containercreative.inventorySlots.add(slot);
|
| 480 |
|
| 481 | if (j >= 5 && j < 9)
|
| 482 | {
|
| 483 | int j1 = j - 5;
|
| 484 | int k1 = j1 / 2;
|
| 485 | int l1 = j1 % 2;
|
| 486 | slot.xDisplayPosition = 9 + k1 * 54;
|
| 487 | slot.yDisplayPosition = 6 + l1 * 27;
|
| 488 | }
|
| 489 | else if (j >= 0 && j < 5)
|
| 490 | {
|
| 491 | slot.yDisplayPosition = -2000;
|
| 492 | slot.xDisplayPosition = -2000;
|
| 493 | }
|
| 494 | else if (j < container.inventorySlots.size())
|
| 495 | {
|
| 496 | int k = j - 9;
|
| 497 | int l = k % 9;
|
| 498 | int i1 = k / 9;
|
| 499 | slot.xDisplayPosition = 9 + l * 18;
|
| 500 |
|
| 501 | if (j >= 36)
|
| 502 | {
|
| 503 | slot.yDisplayPosition = 112;
|
| 504 | }
|
| 505 | else
|
| 506 | {
|
| 507 | slot.yDisplayPosition = 54 + i1 * 18;
|
| 508 | }
|
| 509 | }
|
| 510 | }
|
| 511 |
|
| 512 | this.field_147064_C = new Slot(field_147060_v, 0, 173, 112);
|
| 513 | guicontainercreative$containercreative.inventorySlots.add(this.field_147064_C);
|
| 514 | }
|
| 515 | else if (i == CreativeTabs.tabInventory.getTabIndex())
|
| 516 | {
|
| 517 | guicontainercreative$containercreative.inventorySlots = this.field_147063_B;
|
| 518 | this.field_147063_B = null;
|
| 519 | }
|
| 520 |
|
| 521 | if (this.searchField != null)
|
| 522 | {
|
| 523 | if (p_147050_1_ == CreativeTabs.tabAllSearch)
|
| 524 | {
|
| 525 | this.searchField.setVisible(true);
|
| 526 | this.searchField.setCanLoseFocus(false);
|
| 527 | this.searchField.setFocused(true);
|
| 528 | this.searchField.setText("");
|
| 529 | this.updateCreativeSearch();
|
| 530 | }
|
| 531 | else
|
| 532 | {
|
| 533 | this.searchField.setVisible(false);
|
| 534 | this.searchField.setCanLoseFocus(true);
|
| 535 | this.searchField.setFocused(false);
|
| 536 | }
|
| 537 | }
|
| 538 |
|
| 539 | this.currentScroll = 0.0F;
|
| 540 | guicontainercreative$containercreative.scrollTo(0.0F);
|
| 541 | }
|
| 542 |
|
| 543 | /**
|
| 544 | * Handles mouse input.
|
| 545 | */
|
| 546 | public void handleMouseInput() throws IOException
|
| 547 | {
|
| 548 | super.handleMouseInput();
|
| 549 | int i = Mouse.getEventDWheel();
|
| 550 |
|
| 551 | if (i != 0 && this.needsScrollBars())
|
| 552 | {
|
| 553 | int j = ((GuiContainerCreative.ContainerCreative)this.inventorySlots).itemList.size() / 9 - 5;
|
| 554 |
|
| 555 | if (i > 0)
|
| 556 | {
|
| 557 | i = 1;
|
| 558 | }
|
| 559 |
|
| 560 | if (i < 0)
|
| 561 | {
|
| 562 | i = -1;
|
| 563 | }
|
| 564 |
|
| 565 | this.currentScroll = (float)((double)this.currentScroll - (double)i / (double)j);
|
| 566 | this.currentScroll = MathHelper.clamp_float(this.currentScroll, 0.0F, 1.0F);
|
| 567 | ((GuiContainerCreative.ContainerCreative)this.inventorySlots).scrollTo(this.currentScroll);
|
| 568 | }
|
| 569 | }
|
| 570 |
|
| 571 | /**
|
| 572 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 573 | */
|
| 574 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 575 | {
|
| 576 | boolean flag = Mouse.isButtonDown(0);
|
| 577 | int i = this.guiLeft;
|
| 578 | int j = this.guiTop;
|
| 579 | int k = i + 175;
|
| 580 | int l = j + 18;
|
| 581 | int i1 = k + 14;
|
| 582 | int j1 = l + 112;
|
| 583 |
|
| 584 | if (!this.wasClicking && flag && mouseX >= k && mouseY >= l && mouseX < i1 && mouseY < j1)
|
| 585 | {
|
| 586 | this.isScrolling = this.needsScrollBars();
|
| 587 | }
|
| 588 |
|
| 589 | if (!flag)
|
| 590 | {
|
| 591 | this.isScrolling = false;
|
| 592 | }
|
| 593 |
|
| 594 | this.wasClicking = flag;
|
| 595 |
|
| 596 | if (this.isScrolling)
|
| 597 | {
|
| 598 | this.currentScroll = ((float)(mouseY - l) - 7.5F) / ((float)(j1 - l) - 15.0F);
|
| 599 | this.currentScroll = MathHelper.clamp_float(this.currentScroll, 0.0F, 1.0F);
|
| 600 | ((GuiContainerCreative.ContainerCreative)this.inventorySlots).scrollTo(this.currentScroll);
|
| 601 | }
|
| 602 |
|
| 603 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 604 |
|
| 605 | for (CreativeTabs creativetabs : CreativeTabs.creativeTabArray)
|
| 606 | {
|
| 607 | if (this.renderCreativeInventoryHoveringText(creativetabs, mouseX, mouseY))
|
| 608 | {
|
| 609 | break;
|
| 610 | }
|
| 611 | }
|
| 612 |
|
| 613 | if (this.field_147064_C != null && selectedTabIndex == CreativeTabs.tabInventory.getTabIndex() && this.isPointInRegion(this.field_147064_C.xDisplayPosition, this.field_147064_C.yDisplayPosition, 16, 16, mouseX, mouseY))
|
| 614 | {
|
| 615 | this.drawCreativeTabHoveringText(I18n.format("inventory.binSlot", new Object[0]), mouseX, mouseY);
|
| 616 | }
|
| 617 |
|
| 618 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 619 | GlStateManager.disableLighting();
|
| 620 | }
|
| 621 |
|
| 622 | protected void renderToolTip(ItemStack stack, int x, int y)
|
| 623 | {
|
| 624 | if (selectedTabIndex == CreativeTabs.tabAllSearch.getTabIndex())
|
| 625 | {
|
| 626 | List<String> list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
|
| 627 | CreativeTabs creativetabs = stack.getItem().getCreativeTab();
|
| 628 |
|
| 629 | if (creativetabs == null && stack.getItem() == Items.enchanted_book)
|
| 630 | {
|
| 631 | Map<Integer, Integer> map = EnchantmentHelper.getEnchantments(stack);
|
| 632 |
|
| 633 | if (map.size() == 1)
|
| 634 | {
|
| 635 | Enchantment enchantment = Enchantment.getEnchantmentById(((Integer)map.keySet().iterator().next()).intValue());
|
| 636 |
|
| 637 | for (CreativeTabs creativetabs1 : CreativeTabs.creativeTabArray)
|
| 638 | {
|
| 639 | if (creativetabs1.hasRelevantEnchantmentType(enchantment.type))
|
| 640 | {
|
| 641 | creativetabs = creativetabs1;
|
| 642 | break;
|
| 643 | }
|
| 644 | }
|
| 645 | }
|
| 646 | }
|
| 647 |
|
| 648 | if (creativetabs != null)
|
| 649 | {
|
| 650 | list.add(1, "" + EnumChatFormatting.BOLD + EnumChatFormatting.BLUE + I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]));
|
| 651 | }
|
| 652 |
|
| 653 | for (int i = 0; i < list.size(); ++i)
|
| 654 | {
|
| 655 | if (i == 0)
|
| 656 | {
|
| 657 | list.set(i, stack.getRarity().rarityColor + (String)list.get(i));
|
| 658 | }
|
| 659 | else
|
| 660 | {
|
| 661 | list.set(i, EnumChatFormatting.GRAY + (String)list.get(i));
|
| 662 | }
|
| 663 | }
|
| 664 |
|
| 665 | this.drawHoveringText(list, x, y);
|
| 666 | }
|
| 667 | else
|
| 668 | {
|
| 669 | super.renderToolTip(stack, x, y);
|
| 670 | }
|
| 671 | }
|
| 672 |
|
| 673 | /**
|
| 674 | * Args : renderPartialTicks, mouseX, mouseY
|
| 675 | */
|
| 676 | protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
|
| 677 | {
|
| 678 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 679 | RenderHelper.enableGUIStandardItemLighting();
|
| 680 | CreativeTabs creativetabs = CreativeTabs.creativeTabArray[selectedTabIndex];
|
| 681 |
|
| 682 | for (CreativeTabs creativetabs1 : CreativeTabs.creativeTabArray)
|
| 683 | {
|
| 684 | this.mc.getTextureManager().bindTexture(creativeInventoryTabs);
|
| 685 |
|
| 686 | if (creativetabs1.getTabIndex() != selectedTabIndex)
|
| 687 | {
|
| 688 | this.func_147051_a(creativetabs1);
|
| 689 | }
|
| 690 | }
|
| 691 |
|
| 692 | this.mc.getTextureManager().bindTexture(new ResourceLocation("textures/gui/container/creative_inventory/tab_" + creativetabs.getBackgroundImageName()));
|
| 693 | this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
| 694 | this.searchField.drawTextBox();
|
| 695 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 696 | int i = this.guiLeft + 175;
|
| 697 | int j = this.guiTop + 18;
|
| 698 | int k = j + 112;
|
| 699 | this.mc.getTextureManager().bindTexture(creativeInventoryTabs);
|
| 700 |
|
| 701 | if (creativetabs.shouldHidePlayerInventory())
|
| 702 | {
|
| 703 | this.drawTexturedModalRect(i, j + (int)((float)(k - j - 17) * this.currentScroll), 232 + (this.needsScrollBars() ? 0 : 12), 0, 12, 15);
|
| 704 | }
|
| 705 |
|
| 706 | this.func_147051_a(creativetabs);
|
| 707 |
|
| 708 | if (creativetabs == CreativeTabs.tabInventory)
|
| 709 | {
|
| 710 | GuiInventory.drawEntityOnScreen(this.guiLeft + 43, this.guiTop + 45, 20, (float)(this.guiLeft + 43 - mouseX), (float)(this.guiTop + 45 - 30 - mouseY), this.mc.thePlayer);
|
| 711 | }
|
| 712 | }
|
| 713 |
|
| 714 | protected boolean func_147049_a(CreativeTabs p_147049_1_, int p_147049_2_, int p_147049_3_)
|
| 715 | {
|
| 716 | int i = p_147049_1_.getTabColumn();
|
| 717 | int j = 28 * i;
|
| 718 | int k = 0;
|
| 719 |
|
| 720 | if (i == 5)
|
| 721 | {
|
| 722 | j = this.xSize - 28 + 2;
|
| 723 | }
|
| 724 | else if (i > 0)
|
| 725 | {
|
| 726 | j += i;
|
| 727 | }
|
| 728 |
|
| 729 | if (p_147049_1_.isTabInFirstRow())
|
| 730 | {
|
| 731 | k = k - 32;
|
| 732 | }
|
| 733 | else
|
| 734 | {
|
| 735 | k = k + this.ySize;
|
| 736 | }
|
| 737 |
|
| 738 | return p_147049_2_ >= j && p_147049_2_ <= j + 28 && p_147049_3_ >= k && p_147049_3_ <= k + 32;
|
| 739 | }
|
| 740 |
|
| 741 | /**
|
| 742 | * Renders the creative inventory hovering text if mouse is over it. Returns true if did render or false otherwise.
|
| 743 | * Params: current creative tab to be checked, current mouse x position, current mouse y position.
|
| 744 | */
|
| 745 | protected boolean renderCreativeInventoryHoveringText(CreativeTabs p_147052_1_, int p_147052_2_, int p_147052_3_)
|
| 746 | {
|
| 747 | int i = p_147052_1_.getTabColumn();
|
| 748 | int j = 28 * i;
|
| 749 | int k = 0;
|
| 750 |
|
| 751 | if (i == 5)
|
| 752 | {
|
| 753 | j = this.xSize - 28 + 2;
|
| 754 | }
|
| 755 | else if (i > 0)
|
| 756 | {
|
| 757 | j += i;
|
| 758 | }
|
| 759 |
|
| 760 | if (p_147052_1_.isTabInFirstRow())
|
| 761 | {
|
| 762 | k = k - 32;
|
| 763 | }
|
| 764 | else
|
| 765 | {
|
| 766 | k = k + this.ySize;
|
| 767 | }
|
| 768 |
|
| 769 | if (this.isPointInRegion(j + 3, k + 3, 23, 27, p_147052_2_, p_147052_3_))
|
| 770 | {
|
| 771 | this.drawCreativeTabHoveringText(I18n.format(p_147052_1_.getTranslatedTabLabel(), new Object[0]), p_147052_2_, p_147052_3_);
|
| 772 | return true;
|
| 773 | }
|
| 774 | else
|
| 775 | {
|
| 776 | return false;
|
| 777 | }
|
| 778 | }
|
| 779 |
|
| 780 | protected void func_147051_a(CreativeTabs p_147051_1_)
|
| 781 | {
|
| 782 | boolean flag = p_147051_1_.getTabIndex() == selectedTabIndex;
|
| 783 | boolean flag1 = p_147051_1_.isTabInFirstRow();
|
| 784 | int i = p_147051_1_.getTabColumn();
|
| 785 | int j = i * 28;
|
| 786 | int k = 0;
|
| 787 | int l = this.guiLeft + 28 * i;
|
| 788 | int i1 = this.guiTop;
|
| 789 | int j1 = 32;
|
| 790 |
|
| 791 | if (flag)
|
| 792 | {
|
| 793 | k += 32;
|
| 794 | }
|
| 795 |
|
| 796 | if (i == 5)
|
| 797 | {
|
| 798 | l = this.guiLeft + this.xSize - 28;
|
| 799 | }
|
| 800 | else if (i > 0)
|
| 801 | {
|
| 802 | l += i;
|
| 803 | }
|
| 804 |
|
| 805 | if (flag1)
|
| 806 | {
|
| 807 | i1 = i1 - 28;
|
| 808 | }
|
| 809 | else
|
| 810 | {
|
| 811 | k += 64;
|
| 812 | i1 = i1 + (this.ySize - 4);
|
| 813 | }
|
| 814 |
|
| 815 | GlStateManager.disableLighting();
|
| 816 | this.drawTexturedModalRect(l, i1, j, k, 28, j1);
|
| 817 | this.zLevel = 100.0F;
|
| 818 | this.itemRender.zLevel = 100.0F;
|
| 819 | l = l + 6;
|
| 820 | i1 = i1 + 8 + (flag1 ? 1 : -1);
|
| 821 | GlStateManager.enableLighting();
|
| 822 | GlStateManager.enableRescaleNormal();
|
| 823 | ItemStack itemstack = p_147051_1_.getIconItemStack();
|
| 824 | this.itemRender.renderItemAndEffectIntoGUI(itemstack, l, i1);
|
| 825 | this.itemRender.renderItemOverlays(this.fontRendererObj, itemstack, l, i1);
|
| 826 | GlStateManager.disableLighting();
|
| 827 | this.itemRender.zLevel = 0.0F;
|
| 828 | this.zLevel = 0.0F;
|
| 829 | }
|
| 830 |
|
| 831 | /**
|
| 832 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 833 | */
|
| 834 | protected void actionPerformed(GuiButton button) throws IOException
|
| 835 | {
|
| 836 | if (button.id == 0)
|
| 837 | {
|
| 838 | this.mc.displayGuiScreen(new GuiAchievements(this, this.mc.thePlayer.getStatFileWriter()));
|
| 839 | }
|
| 840 |
|
| 841 | if (button.id == 1)
|
| 842 | {
|
| 843 | this.mc.displayGuiScreen(new GuiStats(this, this.mc.thePlayer.getStatFileWriter()));
|
| 844 | }
|
| 845 | }
|
| 846 |
|
| 847 | public int getSelectedTabIndex()
|
| 848 | {
|
| 849 | return selectedTabIndex;
|
| 850 | }
|
| 851 |
|
| 852 | static class ContainerCreative extends Container
|
| 853 | {
|
| 854 | public List<ItemStack> itemList = Lists.<ItemStack>newArrayList();
|
| 855 |
|
| 856 | public ContainerCreative(EntityPlayer p_i1086_1_)
|
| 857 | {
|
| 858 | InventoryPlayer inventoryplayer = p_i1086_1_.inventory;
|
| 859 |
|
| 860 | for (int i = 0; i < 5; ++i)
|
| 861 | {
|
| 862 | for (int j = 0; j < 9; ++j)
|
| 863 | {
|
| 864 | this.addSlotToContainer(new Slot(GuiContainerCreative.field_147060_v, i * 9 + j, 9 + j * 18, 18 + i * 18));
|
| 865 | }
|
| 866 | }
|
| 867 |
|
| 868 | for (int k = 0; k < 9; ++k)
|
| 869 | {
|
| 870 | this.addSlotToContainer(new Slot(inventoryplayer, k, 9 + k * 18, 112));
|
| 871 | }
|
| 872 |
|
| 873 | this.scrollTo(0.0F);
|
| 874 | }
|
| 875 |
|
| 876 | public boolean canInteractWith(EntityPlayer playerIn)
|
| 877 | {
|
| 878 | return true;
|
| 879 | }
|
| 880 |
|
| 881 | public void scrollTo(float p_148329_1_)
|
| 882 | {
|
| 883 | int i = (this.itemList.size() + 9 - 1) / 9 - 5;
|
| 884 | int j = (int)((double)(p_148329_1_ * (float)i) + 0.5D);
|
| 885 |
|
| 886 | if (j < 0)
|
| 887 | {
|
| 888 | j = 0;
|
| 889 | }
|
| 890 |
|
| 891 | for (int k = 0; k < 5; ++k)
|
| 892 | {
|
| 893 | for (int l = 0; l < 9; ++l)
|
| 894 | {
|
| 895 | int i1 = l + (k + j) * 9;
|
| 896 |
|
| 897 | if (i1 >= 0 && i1 < this.itemList.size())
|
| 898 | {
|
| 899 | GuiContainerCreative.field_147060_v.setInventorySlotContents(l + k * 9, (ItemStack)this.itemList.get(i1));
|
| 900 | }
|
| 901 | else
|
| 902 | {
|
| 903 | GuiContainerCreative.field_147060_v.setInventorySlotContents(l + k * 9, (ItemStack)null);
|
| 904 | }
|
| 905 | }
|
| 906 | }
|
| 907 | }
|
| 908 |
|
| 909 | public boolean func_148328_e()
|
| 910 | {
|
| 911 | return this.itemList.size() > 45;
|
| 912 | }
|
| 913 |
|
| 914 | protected void retrySlotClick(int slotId, int clickedButton, boolean mode, EntityPlayer playerIn)
|
| 915 | {
|
| 916 | }
|
| 917 |
|
| 918 | public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
|
| 919 | {
|
| 920 | if (index >= this.inventorySlots.size() - 9 && index < this.inventorySlots.size())
|
| 921 | {
|
| 922 | Slot slot = (Slot)this.inventorySlots.get(index);
|
| 923 |
|
| 924 | if (slot != null && slot.getHasStack())
|
| 925 | {
|
| 926 | slot.putStack((ItemStack)null);
|
| 927 | }
|
| 928 | }
|
| 929 |
|
| 930 | return null;
|
| 931 | }
|
| 932 |
|
| 933 | public boolean canMergeSlot(ItemStack stack, Slot slotIn)
|
| 934 | {
|
| 935 | return slotIn.yDisplayPosition > 90;
|
| 936 | }
|
| 937 |
|
| 938 | public boolean canDragIntoSlot(Slot p_94531_1_)
|
| 939 | {
|
| 940 | return p_94531_1_.inventory instanceof InventoryPlayer || p_94531_1_.yDisplayPosition > 90 && p_94531_1_.xDisplayPosition <= 162;
|
| 941 | }
|
| 942 | }
|
| 943 |
|
| 944 | class CreativeSlot extends Slot
|
| 945 | {
|
| 946 | private final Slot slot;
|
| 947 |
|
| 948 | public CreativeSlot(Slot p_i46313_2_, int p_i46313_3_)
|
| 949 | {
|
| 950 | super(p_i46313_2_.inventory, p_i46313_3_, 0, 0);
|
| 951 | this.slot = p_i46313_2_;
|
| 952 | }
|
| 953 |
|
| 954 | public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack)
|
| 955 | {
|
| 956 | this.slot.onPickupFromSlot(playerIn, stack);
|
| 957 | }
|
| 958 |
|
| 959 | public boolean isItemValid(ItemStack stack)
|
| 960 | {
|
| 961 | return this.slot.isItemValid(stack);
|
| 962 | }
|
| 963 |
|
| 964 | public ItemStack getStack()
|
| 965 | {
|
| 966 | return this.slot.getStack();
|
| 967 | }
|
| 968 |
|
| 969 | public boolean getHasStack()
|
| 970 | {
|
| 971 | return this.slot.getHasStack();
|
| 972 | }
|
| 973 |
|
| 974 | public void putStack(ItemStack stack)
|
| 975 | {
|
| 976 | this.slot.putStack(stack);
|
| 977 | }
|
| 978 |
|
| 979 | public void onSlotChanged()
|
| 980 | {
|
| 981 | this.slot.onSlotChanged();
|
| 982 | }
|
| 983 |
|
| 984 | public int getSlotStackLimit()
|
| 985 | {
|
| 986 | return this.slot.getSlotStackLimit();
|
| 987 | }
|
| 988 |
|
| 989 | public int getItemStackLimit(ItemStack stack)
|
| 990 | {
|
| 991 | return this.slot.getItemStackLimit(stack);
|
| 992 | }
|
| 993 |
|
| 994 | public String getSlotTexture()
|
| 995 | {
|
| 996 | return this.slot.getSlotTexture();
|
| 997 | }
|
| 998 |
|
| 999 | public ItemStack decrStackSize(int amount)
|
| 1000 | {
|
| 1001 | return this.slot.decrStackSize(amount);
|
| 1002 | }
|
| 1003 |
|
| 1004 | public boolean isHere(IInventory inv, int slotIn)
|
| 1005 | {
|
| 1006 | return this.slot.isHere(inv, slotIn);
|
| 1007 | }
|
| 1008 | }
|
| 1009 | }
|
| 1010 |
|