Skip to content

Commit

Permalink
safer creative tab api
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Oct 15, 2023
1 parent b733930 commit 120ce09
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main/java/net/frozenblock/lib/item/api/FrozenCreativeTabs.java
Original file line number Diff line number Diff line change
@@ -45,8 +45,9 @@ private FrozenCreativeTabs() {
}

public static void add(ItemLike item, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (item == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
ItemGroupEvents.modifyEntriesEvent(tab).register((entries) -> {
ItemGroupEvents.modifyEntriesEvent(tab).register(entries -> {
var stack = new ItemStack(item);
stack.setCount(1);
entries.accept(stack);
@@ -67,11 +68,12 @@ public static void addBefore(ItemLike comparedItem, ItemLike item, ResourceKey<C
* @param item The item that is going to be added
*/
public static void addBefore(ItemLike comparedItem, ItemLike item, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (comparedItem == null || item == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
var stack = new ItemStack(item);
stack.setCount(1);
List<ItemStack> list = List.of(stack);
ItemGroupEvents.modifyEntriesEvent(tab).register((entries) -> entries.addBefore(comparedItem, list, tabVisibility));
ItemGroupEvents.modifyEntriesEvent(tab).register(entries -> entries.addBefore(comparedItem, list, tabVisibility));
}
}

@@ -80,6 +82,7 @@ public static void addBefore(ItemLike comparedItem, ItemLike item, CreativeModeT
* @param item The item that is going to be added
*/
public static void addBefore(ItemLike comparedItem, ItemLike item, String path, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (comparedItem == null || item == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
var stack = new ItemStack(item);
stack.setCount(1);
@@ -104,6 +107,7 @@ public static void addAfter(ItemLike comparedItem, ItemLike item, ResourceKey<Cr
* @param item The item that is going to be added
*/
public static void addAfter(ItemLike comparedItem, ItemLike item, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (comparedItem == null || item == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
var stack = new ItemStack(item);
stack.setCount(1);
@@ -117,6 +121,7 @@ public static void addAfter(ItemLike comparedItem, ItemLike item, CreativeModeTa
* @param item The item that is going to be added
*/
public static void addAfter(ItemLike comparedItem, ItemLike item, String path, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (comparedItem == null || item == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
var stack = new ItemStack(item);
stack.setCount(1);
@@ -129,6 +134,7 @@ public static void addAfter(ItemLike comparedItem, ItemLike item, String path, C
}

public static void addInstrument(Item instrument, TagKey<Instrument> tagKey, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (instrument == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
ItemGroupEvents.modifyEntriesEvent(tab).register((entries) -> {
for (Holder<Instrument> holder : BuiltInRegistries.INSTRUMENT.getTagOrEmpty(tagKey)) {
@@ -144,9 +150,10 @@ public static void addInstrument(Item instrument, TagKey<Instrument> tagKey, Cre
* @param comparedItem The item that the added item is compared to
* @param instrument The instrument that is going to be added
*/
public static void addInstrumentBefore(Item comparedItem, Item instrument, TagKey<Instrument> tagKey, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
public static void addInstrumentBefore(ItemLike comparedItem, Item instrument, TagKey<Instrument> tagKey, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (comparedItem == null || instrument == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
ItemGroupEvents.modifyEntriesEvent(tab).register((entries) -> {
ItemGroupEvents.modifyEntriesEvent(tab).register(entries -> {
List<ItemStack> list = new ArrayList<>();
for (Holder<Instrument> holder : BuiltInRegistries.INSTRUMENT.getTagOrEmpty(tagKey)) {
var stack = InstrumentItem.create(instrument, holder);
@@ -163,6 +170,7 @@ public static void addInstrumentBefore(Item comparedItem, Item instrument, TagKe
* @param instrument The instrument that is going to be added
*/
public static void addInstrumentAfter(Item comparedItem, Item instrument, TagKey<Instrument> tagKey, CreativeModeTab.TabVisibility tabVisibility, ResourceKey<CreativeModeTab> @NotNull ... tabs) {
if (comparedItem == null || instrument == null) return;
for (ResourceKey<CreativeModeTab> tab : tabs) {
ItemGroupEvents.modifyEntriesEvent(tab).register((entries) -> {
List<ItemStack> list = new ArrayList<>();

0 comments on commit 120ce09

Please sign in to comment.