net.minecraftforge.registries.ForgeRegistries Java Examples
The following examples show how to use
net.minecraftforge.registries.ForgeRegistries.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientPacketHandler.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
@SuppressWarnings ("unchecked") private void handleOpenContainer(PacketCustom packet, Minecraft mc) { ContainerType<?> rawType = packet.readRegistryIdUnsafe(ForgeRegistries.CONTAINERS); int windowId = packet.readVarInt(); ITextComponent name = packet.readTextComponent(); if (rawType instanceof ICCLContainerType<?>) { ICCLContainerType<?> type = (ICCLContainerType<?>) rawType; ScreenManager.getScreenFactory(rawType, mc, windowId, name)// .map(e -> (ScreenManager.IScreenFactory<Container, ?>) e)// .ifPresent(screenFactory -> { Container container = type.create(windowId, Minecraft.getInstance().player.inventory, packet); Screen screen = screenFactory.create(container, mc.player.inventory, name); mc.player.openContainer = ((IHasContainer<?>) screen).getContainer(); mc.displayGuiScreen(screen); }); } }
Example #2
Source File: ServerUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public static void openContainer(ServerPlayerEntity player, INamedContainerProvider containerProvider, Consumer<MCDataOutput> packetConsumer) { if (player.world.isRemote()) { return; } player.closeContainer(); player.getNextWindowId(); int containerId = player.currentWindowId; Container container = containerProvider.createMenu(containerId, player.inventory, player); ContainerType<?> type = container.getType(); PacketCustom packet = new PacketCustom(CCLNetwork.NET_CHANNEL, C_OPEN_CONTAINER); packet.writeRegistryIdUnsafe(ForgeRegistries.CONTAINERS, type); packet.writeVarInt(containerId); packet.writeTextComponent(containerProvider.getDisplayName()); packetConsumer.accept(packet); packet.sendToPlayer(player); player.openContainer = container; player.openContainer.addListener(player); MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, container)); }
Example #3
Source File: ChoppingRecipe.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public ChoppingRecipe read(ResourceLocation recipeId, JsonObject json) { String group = JSONUtils.getString(json, "group", ""); JsonElement jsonelement = JSONUtils.isJsonArray(json, "ingredient") ? JSONUtils.getJsonArray(json, "ingredient") : JSONUtils.getJsonObject(json, "ingredient"); Ingredient ingredient = Ingredient.deserialize(jsonelement); String s1 = JSONUtils.getString(json, "result"); ResourceLocation resourcelocation = new ResourceLocation(s1); ItemStack itemstack = new ItemStack(Optional.ofNullable(ForgeRegistries.ITEMS.getValue(resourcelocation)).orElseThrow(() -> new IllegalStateException("Item: " + s1 + " does not exist"))); double outputMultiplier = JSONUtils.getFloat(json, "output_multiplier", 1.0f); double hitCountMultiplier = JSONUtils.getFloat(json, "hit_count_multiplier", 1.0f); int maxOutput = JSONUtils.getInt(json, "max_output", 0); int sawingTime = JSONUtils.getInt(json, "sawing_time", 200); return new ChoppingRecipe(recipeId, group, ingredient, itemstack, outputMultiplier, hitCountMultiplier, maxOutput, sawingTime); }
Example #4
Source File: GameBlockStore.java From XRay-Mod with GNU General Public License v3.0 | 6 votes |
/** * This method is used to fill the store as we do not intend to update this after * it has been populated, it's a singleton by nature but we still need some * amount of control over when it is populated. */ public void populate() { // Avoid doing the logic again unless repopulate is called if( this.store.size() != 0 ) return; for ( Item item : ForgeRegistries.ITEMS ) { if( !(item instanceof net.minecraft.item.BlockItem) ) continue; Block block = Block.getBlockFromItem(item); if ( item == Items.AIR || block == Blocks.AIR || Controller.blackList.contains(block) ) continue; // avoids troubles store.add(new BlockWithItemStack(block, new ItemStack(item))); } }
Example #5
Source File: DryingRecipe.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public DryingRecipe read(ResourceLocation recipeId, JsonObject json) { String group = JSONUtils.getString(json, "group", ""); JsonElement jsonelement = JSONUtils.isJsonArray(json, "ingredient") ? JSONUtils.getJsonArray(json, "ingredient") : JSONUtils.getJsonObject(json, "ingredient"); Ingredient ingredient = Ingredient.deserialize(jsonelement); String s1 = JSONUtils.getString(json, "result"); ResourceLocation resourcelocation = new ResourceLocation(s1); ItemStack itemstack = new ItemStack(Optional.ofNullable(ForgeRegistries.ITEMS.getValue(resourcelocation)).orElseThrow(() -> new IllegalStateException("Item: " + s1 + " does not exist"))); int dryingTime = JSONUtils.getInt(json, "dryingTime", 200); return new DryingRecipe(recipeId, group, ingredient, itemstack, dryingTime); }
Example #6
Source File: SurvivalistData.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected Iterable<Block> getKnownBlocks() { return ForgeRegistries.BLOCKS.getValues().stream() .filter(b -> b.getRegistryName().getNamespace().equals(SurvivalistMod.MODID)) .collect(Collectors.toList()); }
Example #7
Source File: RegSitter.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
public <T extends Block> RegistryObject<T> block(String name) { return RegistryObject.of(new ResourceLocation(modId, name), ForgeRegistries.BLOCKS); }
Example #8
Source File: RegSitter.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
public <T extends Item> RegistryObject<T> item(String name) { return RegistryObject.of(new ResourceLocation(modId, name), ForgeRegistries.ITEMS); }
Example #9
Source File: RegSitter.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
public <T extends TileEntity> RegistryObject<TileEntityType<T>> tileEntity(String name) { return RegistryObject.of(new ResourceLocation(modId, name), ForgeRegistries.TILE_ENTITIES); }