Skip to content

Commit

Permalink
add logging for item and block registering
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPlacentino committed Feb 3, 2023
1 parent 98cc285 commit 2b68c5c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 63 deletions.
38 changes: 3 additions & 35 deletions src/main/java/com/obsilab/mcsc/MCSC.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,10 @@ public class MCSC
// Define mod id in a common place for everything to reference
public static final String MOD_ID = "mcsc";
public static final String MODID = MOD_ID;
public static final String MCSC = MOD_ID; // 🤷‍♂️
//public static final String MCSC = MOD_ID; // 🤷‍♂️

// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();
/*
// Create a Deferred Register to hold Blocks which will all be registered under the "mcsc" namespace
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MOD_ID);
// Create a Deferred Register to hold Items which will all be registered under the "mcsc" namespace
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
// Creates a new Block with the id "mcsc:example_block", combining the namespace
// and path
public static final RegistryObject<Block> EXAMPLE_BLOCK = BLOCKS.register(
"example_block", () -> new Block(
BlockBehaviour.Properties.of(Material.STONE)));
// Creates a new BlockItem with the id "mcsc:example_block", combining the
// namespace and path
public static final RegistryObject<Item> EXAMPLE_BLOCK_ITEM = ITEMS.register(
"example_block", () -> new BlockItem(
EXAMPLE_BLOCK.get(), new Item.Properties()));
// SHOULD PUT THINGS IN SUB-PACKAGES
// Creates a new Item with the id "mcsc:empty_wafer", combining the namespace
// and path
public static final RegistryObject<Item> EMPTY_WAFER_ITEM = ITEMS.register(
"empty_wafer", () -> new Item(
new Item.Properties()));
// Creates a new Item with the id "mcsc:etched_wafer", combining the namespace
// and path
public static final RegistryObject<Item> ETCHED_WAFER_ITEM = ITEMS.register(
"etched_wafer", () -> new Item(
new Item.Properties()));
*/
public static final Logger LOGGER = LogUtils.getLogger();

public MCSC()
{
Expand Down Expand Up @@ -143,14 +114,11 @@ private void addCreative(CreativeModeTabEvent.BuildContents event) {
event.accept(new ItemStack(mod_item.get()));
}
for (RegistryObject<Block> mod_block : ModBlocksList) {
//check if the block is a crop block
if (mod_block.get() instanceof CrystalIngotBlock) { // if(mod_block.get().getName().equals("crystal_ingot"))
//continue; // remove crop block, prevents crashing
} else {
event.accept(new ItemStack(mod_block.get()));
}

//event.accept(mod_block.get());
}
}
}
Expand Down
23 changes: 9 additions & 14 deletions src/main/java/com/obsilab/mcsc/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,51 @@

import java.util.function.Supplier;

import static com.obsilab.mcsc.MCSC.LOGGER;

public class ModBlocks {
public static final DeferredRegister<Block> BLOCKS =
DeferredRegister.create(ForgeRegistries.BLOCKS, MCSC.MOD_ID);


public static final RegistryObject<Block> FOUP_STORAGE_BLOCK = registerBlock(
"foup_storage",
() -> new Block(BlockBehaviour.Properties
.of(Material.METAL)
.strength(6f)
.requiresCorrectToolForDrops()
));

public static final RegistryObject<Block> BORAX_ORE = registerBlock( // => boric acid => boron for p-type doping
"borax_ore",
() -> new DropExperienceBlock(BlockBehaviour.Properties
.of(Material.STONE)
.strength(3f)
.requiresCorrectToolForDrops(),
UniformInt.of(3,7)
UniformInt.of(2,4)
));


public static final RegistryObject<Block> PHOSPHATE_ORE = registerBlock(
"phosphate_ore",
() -> new DropExperienceBlock(BlockBehaviour.Properties
.of(Material.STONE)
.strength(3f)
.requiresCorrectToolForDrops(),
UniformInt.of(3,7)
UniformInt.of(2,4)
));

public static final RegistryObject<Block> TEST_BLOCK_BLOCK = registerBlock(
"test_block",
() -> new TestBlock(BlockBehaviour.Properties
.of(Material.METAL)
.strength(6f)
.lightLevel(state -> state.getValue(TestBlock.ACTIVE) ? 8 : 0) // light level of 8 if block's ACTIVE property is true, else light level of 0
));

public static final RegistryObject<LiquidBlock> TEST_FLUID_BLOCK = BLOCKS.register("test_fluid_block",
"test_fluid_block",
() -> new LiquidBlock(
ModFluids.SOURCE_TEST_FLUID,
BlockBehaviour.Properties
.copy(Blocks.WATER)
));

public static final RegistryObject<Block> CRYSTAL_INGOT_BLOCK = BLOCKS.register( // crop block, so not register BlockItem
"crystal_ingot",
() -> new CrystalIngotBlock(BlockBehaviour.Properties
.copy(Blocks.WHEAT)
Expand All @@ -81,16 +78,14 @@ public class ModBlocks {



private static <T extends Block> RegistryObject<T> registerBlock(String name, Supplier<T> block){//, CreativeModeTab tab) {
LOGGER.info("MCSC: Registering Block >> {} : {}", name, block.get()); //? .get() ?
RegistryObject<T> toReturn = BLOCKS.register(name, block);
registerBlockItem(name, toReturn);//, tab);
return toReturn;

//return BLOCKS.register(name, block);
}

private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block){//, CreativeModeTab tab) {
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties()));//.tab(tab)));
private static <T extends Block> RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block){
LOGGER.info("MCSC: Registering its blockItem >> {} : {}", name, block.get()); //? .get() ?
return ModItems.ITEMS.register(name, () -> new BlockItem(block.get(), new Item.Properties()));
}

public static void register(IEventBus eventBus) {
Expand Down
38 changes: 24 additions & 14 deletions src/main/java/com/obsilab/mcsc/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.function.Supplier;

import static com.obsilab.mcsc.MCSC.LOGGER;

public class ModItems {
// Create a Deferred Register to hold Items which will all be registered under the "mcsc" namespace
public static final DeferredRegister<Item> ITEMS =
Expand All @@ -20,29 +25,29 @@ public class ModItems {
/*
// ----- ITEMS : ------
*/
public static final RegistryObject<Item> SILICON_ITEM = ITEMS.register(
public static final RegistryObject<Item> SILICON_ITEM = registerItem(
"silicon", () -> new Item(
new Item.Properties()
//.stacksTo(1)

));

public static final RegistryObject<Item> EMPTY_WAFER_ITEM = ITEMS.register(
public static final RegistryObject<Item> EMPTY_WAFER_ITEM = registerItem(
"empty_wafer", () -> new Item(
new Item.Properties()
.durability(100)
//.stacksTo(1)
.setNoRepair()
));
public static final RegistryObject<Item> EXPOSED_WAFER_ITEM = ITEMS.register(
public static final RegistryObject<Item> EXPOSED_WAFER_ITEM = registerItem(
"exposed_wafer", () -> new Item(
new Item.Properties()
.durability(100)
//.stacksTo(1)
.setNoRepair()
));

public static final RegistryObject<Item> ETCHED_WAFER_ITEM = ITEMS.register(
public static final RegistryObject<Item> ETCHED_WAFER_ITEM = registerItem(
"etched_wafer", () -> new Item(
new Item.Properties()
.durability(100)
Expand All @@ -51,7 +56,7 @@ public class ModItems {

));

public static final RegistryObject<Item> MONOCRYSTALLINE_SILICON_BOULE_ITEM = ITEMS.register(
public static final RegistryObject<Item> MONOCRYSTALLINE_SILICON_BOULE_ITEM = registerItem(
"monocrystalline_silicon_boule", () -> new Item(
new Item.Properties()
.durability(100)
Expand All @@ -61,44 +66,44 @@ public class ModItems {
//.tab(ModCreativeModeTab.MCSC_TAB)
));

public static final RegistryObject<Item> WAFER_CASSETTE_ITEM = ITEMS.register(
public static final RegistryObject<Item> WAFER_CASSETTE_ITEM = registerItem(
"wafer_cassette", () -> new Item(
new Item.Properties()
.stacksTo(1)
//.group(MCSC.MCSC_GROUP)
//.tab(ModCreativeModeTab.MCSC_TAB)
));

public static final RegistryObject<Item> FOUP_ITEM = ITEMS.register(
public static final RegistryObject<Item> FOUP_ITEM = registerItem(
"foup", () -> new Item(
new Item.Properties()
.stacksTo(1)
//.group(MCSC.MCSC_GROUP)
//.tab(ModCreativeModeTab.MCSC_TAB)
));

public static final RegistryObject<Item> SILICON_CRYSTAL_SEED = ITEMS.register(
public static final RegistryObject<Item> SILICON_CRYSTAL_SEED = registerItem(
"silicon_crystal_seed", () -> new Item(
new Item.Properties()
//.group(MCSC.MCSC_GROUP)
//.tab(ModCreativeModeTab.MCSC_TAB)
));

public static final RegistryObject<Item> RAW_BORAX = ITEMS.register(
public static final RegistryObject<Item> RAW_BORAX = registerItem(
"raw_borax", () -> new Item(
new Item.Properties()
//.group(MCSC.MCSC_GROUP)
//.tab(ModCreativeModeTab.MCSC_TAB)
));

public static final RegistryObject<Item> RAW_PHOSPHATE = ITEMS.register(
public static final RegistryObject<Item> RAW_PHOSPHATE = registerItem(
"raw_phosphate", () -> new Item(
new Item.Properties()
//.group(MCSC.MCSC_GROUP)
//.tab(ModCreativeModeTab.MCSC_TAB)
));

public static final RegistryObject<Item> WRENCH_ITEM = ITEMS.register(
public static final RegistryObject<Item> WRENCH_ITEM = registerItem(
"wrench", () -> new ToolItem(
new ToolItem.Properties()
.stacksTo(1)
Expand All @@ -108,7 +113,7 @@ public class ModItems {
, true
));

public static final RegistryObject<Item> TOOLKIT_ITEM = ITEMS.register(
public static final RegistryObject<Item> TOOLKIT_ITEM = registerItem(
"toolkit", () -> new ToolItem(
new ToolItem.Properties()
.stacksTo(1)
Expand All @@ -118,7 +123,7 @@ public class ModItems {
, false
));

public static final RegistryObject<Item> TEST_ITEM_ITEM = ITEMS.register(
public static final RegistryObject<Item> TEST_ITEM_ITEM = registerItem(
"test_item", () -> new TestItem(
// new Item.Properties()
new TestItem.Properties()
Expand All @@ -127,7 +132,7 @@ public class ModItems {
//.tab(ModCreativeModeTab.MCSC_TAB)
));

public static final RegistryObject<Item> TEST_FLUID_BUCKET = ITEMS.register(
public static final RegistryObject<Item> TEST_FLUID_BUCKET = registerItem(
"test_fluid_bucket", () -> new BucketItem(
ModFluids.SOURCE_TEST_FLUID,
new Item.Properties()
Expand All @@ -137,6 +142,11 @@ public class ModItems {
//.tab(ModCreativeModeTab.MCSC_TAB)
));

private static <T extends Item> RegistryObject<T> registerItem(String name, Supplier<T> item){
LOGGER.info("MCSC: Registering Item >> {} : {}", name, item.get()); //? .get() ?
return ITEMS.register(name, item);
}

public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
}
Expand Down

0 comments on commit 2b68c5c

Please # to comment.