Skip to content

Commit

Permalink
Add the tabs back
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Jun 29, 2023
1 parent 9222594 commit 56ecb84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
17 changes: 10 additions & 7 deletions src/main/java/com/fusionflux/portalcubed/PortalTabsLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import it.unimi.dsi.fastutil.Pair;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.TagParser;
Expand All @@ -31,6 +32,8 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import static com.fusionflux.portalcubed.PortalCubed.id;

public class PortalTabsLoader {
private static final Map<String, Function<JsonObject, Predicate<CreativeModeTab.ItemDisplayParameters>>> CONDITION_TYPES = Map.of(
"and", o -> GsonHelper.getAsJsonArray(o, "conditions")
Expand Down Expand Up @@ -60,19 +63,19 @@ public class PortalTabsLoader {
);

public static void load(ModContainer mod) {
final JsonArray jsonArray;
final JsonObject jsonObject;
try (Reader reader = Files.newBufferedReader(mod.getPath("portal_tabs.json"))) {
jsonArray = GsonHelper.parseArray(reader);
jsonObject = GsonHelper.parse(reader);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
load(jsonArray);
load(jsonObject);
}

private static void load(JsonArray jsonArray) {
for (final var entry : jsonArray) {
private static void load(JsonObject jsonObject) {
for (final var entry : jsonObject.entrySet()) {
final CreativeModeTab.Builder builder = FabricItemGroup.builder();
final JsonObject entryData = GsonHelper.convertToJsonObject(entry, "tab");
final JsonObject entryData = GsonHelper.convertToJsonObject(entry.getValue(), "tab");
if (entryData.has("title")) {
builder.title(Component.Serializer.fromJson(entryData.get("title")));
}
Expand Down Expand Up @@ -113,7 +116,7 @@ private static void load(JsonArray jsonArray) {
}
});
}
builder.build();
Registry.register(BuiltInRegistries.CREATIVE_MODE_TAB, id(entry.getKey()), builder.build());
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/resources/portal_tabs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{
{
"main_testing_elements": {
"title": {
"translate": "itemGroup.portalcubed.main_testing_elements"
},
Expand Down Expand Up @@ -54,7 +54,7 @@
"portalcubed:excursion_funnel_emitter"
]
},
{
"other_testing_elements": {
"title": {
"translate": "itemGroup.portalcubed.other_testing_elements"
},
Expand Down Expand Up @@ -90,8 +90,7 @@
"portalcubed:lil_pineapple"
]
},

{
"portal_blocks": {
"title": {
"translate": "itemGroup.portalcubed.portal_blocks"
},
Expand Down Expand Up @@ -284,4 +283,4 @@

]
}
]
}

0 comments on commit 56ecb84

Please sign in to comment.