Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. private static final Map<ResourceLocation, Supplier<BiFunction<InventoryPlayer, BlockPos, GuiScreen>>> GUISUPPLIERS = new HashMap<>();
  2.  
  3.     public static void registerGuiScreens()
  4.     {
  5.         registerGui("crate_gui", () -> (playerInv, pos) -> new GuiCrate(new ContainerCrate(playerInv, (TileEntityCrate)playerInv.player.world.getTileEntity(pos)), playerInv));
  6.         registerGui("large_chest_gui", () -> (playerInv, pos) -> new GuiLargeChest(new ContainerLargeChest(playerInv, (TileEntityLargeChest)playerInv.player.world.getTileEntity(pos)), playerInv));
  7.         registerGui("carpenters_table_gui", () -> (playerInv, pos) -> new GuiCarpentersTable(playerInv, playerInv.player.world, pos));
  8.         registerGui("bookshelf_cabinet_gui", () -> (playerInv, pos) -> new GuiBookshelf(new ContainerBookshelfCabinet(playerInv, (TileEntityBookshelf.Cabinet)playerInv.player.world.getTileEntity(pos)), playerInv));
  9.     }
  10.  
  11.     private static void registerGui(String id, Supplier<BiFunction<InventoryPlayer, BlockPos, GuiScreen>> returnSupplier)
  12.     {
  13.         ResourceLocation resourceId = new ResourceLocation(Constants.MODID, id);
  14.  
  15.         if (!GUISUPPLIERS.containsKey(resourceId))
  16.         {
  17.             GUISUPPLIERS.put(resourceId, returnSupplier);
  18.         }
  19.         else
  20.         {
  21.             MinecraftExtended.LOGGER.error("Tried to register GuiScreen Supplier multiple times.");
  22.         }
  23.     }
  24.  
  25.     public static GuiScreen handleGuiRequest(FMLPlayMessages.OpenContainer openContainer)
  26.     {
  27.         ResourceLocation id = openContainer.getId();
  28.  
  29.         if (GUISUPPLIERS.containsKey(id))
  30.         {
  31.             Supplier<BiFunction<InventoryPlayer, BlockPos, GuiScreen>> returnSupplier = GUISUPPLIERS.get(id);
  32.             EntityPlayerSP player = Minecraft.getInstance().player;
  33.             BlockPos pos = openContainer.getAdditionalData().readBlockPos();
  34.  
  35.             if (returnSupplier != null && returnSupplier.get() != null)
  36.             {
  37.                 return returnSupplier.get().apply(player.inventory, pos);
  38.             }
  39.         }
  40.  
  41.         return null;
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement