CustomContainer.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package me.km.inventory;
  2. import net.minecraft.entity.player.EntityPlayer;
  3. import net.minecraft.entity.player.EntityPlayerMP;
  4. import net.minecraft.inventory.ClickType;
  5. import net.minecraft.inventory.ContainerChest;
  6. import net.minecraft.inventory.IInventory;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.network.play.server.SPacketOpenWindow;
  9. public class CustomContainer extends ContainerChest
  10. {
  11. public CustomContainer(String title, int slotCount, EntityPlayer p)
  12. {
  13. super(p.inventory, new EntityInventory(title, slotCount, p), p);
  14. }
  15. public EntityInventory getShownInventory()
  16. {
  17. return (EntityInventory) this.getLowerChestInventory();
  18. }
  19. public void openForPlayer(EntityPlayerMP p)
  20. {
  21. if(p.openContainer != p.inventoryContainer)
  22. {
  23. p.closeScreen();
  24. }
  25. p.getNextWindowId();
  26. IInventory inv = this.getLowerChestInventory();
  27. p.connection.sendPacket(new SPacketOpenWindow(p.currentWindowId, "minecraft:container", inv.getDisplayName(), inv.getSizeInventory()));
  28. p.openContainer = this;
  29. p.openContainer.windowId = p.currentWindowId;
  30. p.openContainer.addListener(p);
  31. }
  32. public boolean noClicking()
  33. {
  34. return true;
  35. }
  36. @Override
  37. public final ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player)
  38. {
  39. if(noClicking())
  40. {
  41. onCanceledClick(slotId, dragType, clickTypeIn, player);
  42. return ItemStack.EMPTY;
  43. }
  44. return super.slotClick(slotId, dragType, clickTypeIn, player);
  45. }
  46. public void onCanceledClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player)
  47. {
  48. }
  49. }