Java源码示例:net.minecraftforge.registries.ForgeRegistries

示例1
@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);
                });

    }
}
 
示例2
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));
}
 
示例3
@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);
}
 
示例4
/**
 * 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)));
    }
}
 
示例5
@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);
}
 
示例6
@Override
protected Iterable<Block> getKnownBlocks()
{
    return ForgeRegistries.BLOCKS.getValues().stream()
            .filter(b -> b.getRegistryName().getNamespace().equals(SurvivalistMod.MODID))
            .collect(Collectors.toList());
}
 
示例7
public <T extends Block> RegistryObject<T> block(String name)
{
    return RegistryObject.of(new ResourceLocation(modId, name), ForgeRegistries.BLOCKS);
}
 
示例8
public <T extends Item> RegistryObject<T> item(String name)
{
    return RegistryObject.of(new ResourceLocation(modId, name), ForgeRegistries.ITEMS);
}
 
示例9
public <T extends TileEntity> RegistryObject<TileEntityType<T>> tileEntity(String name)
{
    return RegistryObject.of(new ResourceLocation(modId, name), ForgeRegistries.TILE_ENTITIES);
}