CustomContainer.java 2.0 KB

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