Skip to content

Commit

Permalink
Fixed NeoForge not loading via proper Supplier use
Browse files Browse the repository at this point in the history
Suppliers can not be provided an already created object instance. It must created within the Supplier.
  • Loading branch information
anthonymendez committed Aug 11, 2024
1 parent a5dc058 commit 8beb42f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

import com.anthonymendez.init.ModItemGroups;
import com.anthonymendez.init.ModItems;
import com.google.common.base.Suppliers;
import dev.architectury.registry.registries.RegistrarManager;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public final class ToekneeSimpleTools {
public static final String MOD_ID = "toeknees_simple_tools";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

/** Registry manager for handling anything relating to the Minecraft registry. */
public static final Supplier<RegistrarManager> MANAGER =
Suppliers.memoize(() -> RegistrarManager.get(MOD_ID));

/** Initializes the mod. */
public static void init() {
LOGGER.info("Initializing Toeknee's Simple Tools :)");
Expand Down
36 changes: 21 additions & 15 deletions common/src/main/java/com/anthonymendez/init/ModItemGroups.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.anthonymendez.ToekneeSimpleTools;
import com.anthonymendez.items.SimpleTools;
import com.google.common.base.Suppliers;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import java.util.function.Supplier;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
Expand All @@ -17,22 +19,26 @@ public final class ModItemGroups {
public static final DeferredRegister<ItemGroup> ITEM_GROUPS =
DeferredRegister.create(ToekneeSimpleTools.MOD_ID, RegistryKeys.ITEM_GROUP);

public static RegistrySupplier<ItemGroup> register(ItemGroup itemGroup, String name) {
return ITEM_GROUPS.register(name, () -> itemGroup);
/** Registers the given {@link ItemGroup} to the Simple Tools tab. */
public static RegistrySupplier<ItemGroup> register(
Supplier<ItemGroup> itemGroupSupplier, String name) {
return ITEM_GROUPS.register(name, itemGroupSupplier);
}

public static final ItemGroup SIMPLE_TOOLS_ITEM_GROUP =
new ItemGroup.Builder(null, -1)
.displayName(Text.of(CREATIVE_TAB_DISPLAY_NAME))
.icon(() -> new ItemStack(SimpleTools.EMERALD_PICKAXE))
.entries(
(displayContext, entries) -> {
for (Item item : SimpleTools.ALL_TOOLS) {
entries.add(item);
}
})
.build();
public static final Supplier<ItemGroup> SIMPLE_TOOLS_ITEM_GROUP_SUPPLIER =
Suppliers.memoize(
() ->
new ItemGroup.Builder(null, -1)
.displayName(Text.of(CREATIVE_TAB_DISPLAY_NAME))
.icon(() -> new ItemStack(ModItems.EMERALD_PICKAXE_SUPPLIER.get()))
.entries(
(displayContext, entries) -> {
for (Supplier<Item> s : SimpleTools.ALL_TOOLS) {
entries.add(s.get());
}
})
.build());

public static final RegistrySupplier<ItemGroup> SIMPLE_TOOLS_ITEM_GROUP_SUPPLIER =
register(SIMPLE_TOOLS_ITEM_GROUP, ITEM_GROUP_NAME);
public static final RegistrySupplier<ItemGroup> SIMPLE_TOOLS_ITEM_GROUP_SUPPLIER_REGISTERED =
register(SIMPLE_TOOLS_ITEM_GROUP_SUPPLIER, ITEM_GROUP_NAME);
}
10 changes: 6 additions & 4 deletions common/src/main/java/com/anthonymendez/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.anthonymendez.items.SimpleTools;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import java.util.function.Supplier;
import net.minecraft.item.Item;
import net.minecraft.registry.RegistryKeys;

Expand All @@ -12,13 +13,14 @@ public final class ModItems {
public static final DeferredRegister<Item> ITEMS =
DeferredRegister.create(ToekneeSimpleTools.MOD_ID, RegistryKeys.ITEM);

public static RegistrySupplier<Item> register(Item item, String name) {
return ITEMS.register(name, () -> item);
/** Registers the given {@link Item} to the deferred mod registry. */
public static RegistrySupplier<Item> register(Supplier<Item> itemSupplier, String name) {
return ITEMS.register(name, itemSupplier);
}

public static final RegistrySupplier<Item> EMERALD_PICKAXE_SUPPLIER =
register(SimpleTools.EMERALD_PICKAXE, "emerald_pickaxe");

public static final RegistrySupplier<Item> NETHER_QUARTZ_PICKAXE =
register(SimpleTools.NETHER_QUARTZ_PICKAXE, "nether_quartz_pickaxe");
public static final RegistrySupplier<Item> QUARTZ_PICKAXE_SUPPLIER =
register(SimpleTools.QUARTZ_PICKAXE, "quartz_pickaxe");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ToolMaterial;
import net.minecraft.item.ToolMaterials;

/** Extension of {@link PickaxeItem} to allow for more customization and behaviour in the future. */
public class SimplePickaxeTool extends PickaxeItem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.anthonymendez.items;

import com.google.common.base.Suppliers;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Supplier;
import net.minecraft.block.Block;
import net.minecraft.item.*;
import net.minecraft.recipe.Ingredient;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.ItemTags;
import net.minecraft.registry.tag.TagKey;

import java.util.Arrays;
import java.util.Objects;
import java.util.function.Supplier;

/**
* Enum describing {@link ToolMaterial}s. Similar in structure to {@link
* net.minecraft.item.ToolMaterials}.
Expand All @@ -27,7 +25,7 @@ public enum SimpleToolMaterials implements ToolMaterial {
25,
createRepairIngredientSupplier(Items.EMERALD)),
// Faster and more durable than iron.
NETHER_QUARTZ(
QUARTZ(
BlockTags.INCORRECT_FOR_IRON_TOOL,
750,
7F,
Expand All @@ -42,7 +40,7 @@ public enum SimpleToolMaterials implements ToolMaterial {
private final int enchantability;
private final Supplier<Ingredient> repairIngredient;

private SimpleToolMaterials(
SimpleToolMaterials(
final TagKey<Block> inverseTag,
final int itemDurability,
final float miningSpeed,
Expand Down Expand Up @@ -87,6 +85,6 @@ public int getEnchantability() {
}

public Ingredient getRepairIngredient() {
return (Ingredient) this.repairIngredient.get();
return this.repairIngredient.get();
}
}
21 changes: 13 additions & 8 deletions common/src/main/java/com/anthonymendez/items/SimpleTools.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.anthonymendez.items;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.function.Supplier;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;

public class SimpleTools {
public static final SimplePickaxeTool EMERALD_PICKAXE =
new SimplePickaxeTool(SimpleToolMaterials.EMERALD);
public static final SimplePickaxeTool NETHER_QUARTZ_PICKAXE =
new SimplePickaxeTool(SimpleToolMaterials.NETHER_QUARTZ);
public static final Supplier<Item> EMERALD_PICKAXE =
Suppliers.memoize(() -> new SimplePickaxeTool(SimpleToolMaterials.EMERALD));

/** Contains a list of all {@link SimpleTools}. */
public static final Item[] ALL_TOOLS = {EMERALD_PICKAXE, NETHER_QUARTZ_PICKAXE};
public static final Supplier<Item> QUARTZ_PICKAXE =
Suppliers.memoize(() -> new SimplePickaxeTool(SimpleToolMaterials.QUARTZ));

/** Contains a list of all {@link SimpleTools}. */
public static final List<Supplier<Item>> ALL_TOOLS =
ImmutableList.<Supplier<Item>>builder()
.add(EMERALD_PICKAXE)
.add(QUARTZ_PICKAXE)
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import com.anthonymendez.ToekneeSimpleTools;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.IModBusEvent;

@Mod(ToekneeSimpleTools.MOD_ID)
public final class ToekneeSimpleToolsNeoForge {

public ToekneeSimpleToolsNeoForge() {
// Run our common setup.
ToekneeSimpleTools.init();

}
}

0 comments on commit 8beb42f

Please sign in to comment.