Hello everyone. So i am very new to Java and Javascript and I am trying to learn how to code by making my own mod. I managed to get custom items but when I tried to maker custom blocks it would not show in game but didnt give any errors in IntelliJ. I can show the code if needed, but what does it mean if you dont have any critical errors in the code but no blocks show up, even by using the /give command?
#Help with Custom Blocks
267 messages · Page 1 of 1 (latest)
It sounds like you didn't register an item for your block
I used the register one in the ModBlocks but it didnt workj
Does your block show up with /setblock?
it doesnt even show up in give
Yes but did you try setblock?
want me to send the code for the ModBlocks file? Lemme check the place rq
Does that register an item?
I could be very wrong in how i coded it. But there werent any errors on my end. Only small stuff but nothing red
^ can you check this first
Okay so yeah, your right. It does appear in the setblock
but not in the give command
Okay yeah you don't have an item for your block
Everything in the inventory is technically an item, not a block
So most blocks have an associated item
but this isn't created automatically
So you need to do that part
i thought i did that in the ModBlocks file
import com.renegade.TimeAgain;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import java.sql.Time;
public class ModBlocks {
public static final Block TIME_STONE = registerBlock("time_stone",
new Block(FabricBlockSettings.copyOf(Blocks.STONE).sounds(SoundType.METAL)));
private static Block registerBlock(String name, Block block) {
return Registry.register(BuiltInRegistries.BLOCK, ResourceKey.create(Registries.BLOCK, new ResourceLocation(TimeAgain.MOD_ID, name)), block);
}
private static Item registerBlockItem(String name, Block block) {
return Registry.register(BuiltInRegistries.ITEM, ResourceKey.create(Registries.ITEM, new ResourceLocation(TimeAgain.MOD_ID, name)),
new BlockItem(block, new FabricItemSettings()));
}
public static void registerModBlocks() {
TimeAgain.LOGGER.info("Registering Mod Blocks for " + TimeAgain.MOD_ID);
}
}
thats in modblocks
Where did you call registerBlockItem?
that could be the reason, i added this to the .java file
import com.renegade.block.ModBlocks;
import com.renegade.item.ModItemGroups;
import com.renegade.item.ModItems;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TimeAgain implements ModInitializer {
public static final String MOD_ID = "time-again";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
ModItems.registerModItems();
ModItemGroups.registerItemGroups();
ModBlocks.registerModBlocks();
}
}```
was i supposed to add another register for blockitem?
which part should go in the items class?
registering the blockitem
so which part of the first code that i sent should be in ModItems?
the registerBlockItem function
and then you register a new item using that function and your block
so should it be ModItems.registerBlockItem?
why would that go in the ModItems class and not the main class?
Because it deals with items
I can't vc right now
okay, well i tried adding it to the ModItems using the public void onInitialize but it doesnt seem to work
Show your moditems?
import com.renegade.TimeAgain;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import org.intellij.lang.annotations.Identifier;
@Override
public void onInitialize() {
ModItems.registerBlockItem
}
public class ModItems {
public static final Item ASTRO_LAB = registerItem("astro_lab", new Item(new Item.Properties()));
public static final Item CODE_BREAKER = registerItem("code_breaker", new Item(new Item.Properties()));
public static final Item CHRONODIAL = registerItem("chronodial", new Item(new Item.Properties()));
public static final Item DIM_CRACKER = registerItem("dim_cracker", new Item(new Item.Properties()));
public static final Item DIMENSION_SHIFTER = registerItem("dimension_shifter", new Item(new Item.Properties()));
public static final Item FREQUENCY_MODULATOR = registerItem("frequency_modulator", new Item(new Item.Properties()));
public static final Item STAR_PHASER = registerItem("star_phased", new Item(new Item.Properties()));
public static final Item TIME_PHASE_ARRAY = registerItem("time_phase_array", new Item(new Item.Properties()));
public static final Item TIME_ANOMALY = registerItem("time_anomaly", new Item(new Item.Properties()));
public static final Item TIME_ANOMALY_ANALYZER = registerItem("time_anomaly_analyzer", new Item(new Item.Properties()));
private static Item registerItem(String name, Item item) {
return Registry.register(BuiltInRegistries.ITEM, ResourceKey.create(Registries.ITEM, new ResourceLocation(TimeAgain.MOD_ID, name)), item);
}
public static void registerModItems() {
TimeAgain.LOGGER.info("Registering Mod Items for " + TimeAgain.MOD_ID);
}
}```
You just need to register your blockitem
if im way off im sorry in advance i really am trying looll
you mean through the private static ?
Oh wait why do you have a method outside the class
whatcha mean?
onInitialize seems to be outside ModItems
it is?
Cause i have an onInitialize in the timeagain class where i registered the others
import com.renegade.block.ModBlocks;
import com.renegade.item.ModItemGroups;
import com.renegade.item.ModItems;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TimeAgain implements ModInitializer {
public static final String MOD_ID = "time-again";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
ModItems.registerModItems();
ModItemGroups.registerItemGroups();
ModBlocks.registerModBlocks();
ModItems.registerBlockItem();
}
}```
ohh i added that when you said i needed to add BlockItem
I deleted it but im just trying to figure out how to do what you asked
I meant move the function registerBlockItem from ModBlocks to ModItems
so it's after registerItem
this one? private static Item registerBlockItem(String name, Block block) { return Registry.register(BuiltInRegistries.ITEM, ResourceKey.create(Registries.ITEM, new ResourceLocation(TimeAgain.MOD_ID, name)), new BlockItem(block, new FabricItemSettings())); }
Yep that whole thing
why wouldnt it be called in the ModBlocks?
Because it creates an item and items usually go in the items class
So anything that registers an Item goes in the ModItems class?
Typically
Even if it is in regard to a block?:
lets hope it works
but if you really want you can put the item in your ModBlocks class
i tried it, but when i tried the onInitialize it gave me an error
this error to be exact error: method registerBlockItem in class ModItems cannot be applied to given types; ModItems.registerBlockItem(); ^ required: String,Block found: no arguments reason: actual and formal argument lists differ in length
You have to call it with your name and block as parameters
Where did you call it?
It should be called to create an Item field the same way registerItem is
registerBlockItem(String name, Block block)
thats in the ModItems folder, is that what you mean?
folder?
what do you mean folder? do you wanna see the mod folder?
What do you mean by ModItems folder? Isn't ModItems a file?
it is yeah
heres the path
or this one if it helps java/com/renegade/item/ModItems.java
Okay so you meant file here?
Ah ok got it
Where is this code?
the error code? its in the TimeAgain.java
where the onInitialize is originally
import com.renegade.block.ModBlocks;
import com.renegade.item.ModItemGroups;
import com.renegade.item.ModItems;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TimeAgain implements ModInitializer {
public static final String MOD_ID = "time-again";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
ModItems.registerModItems();
ModItemGroups.registerItemGroups();
ModBlocks.registerModBlocks();
ModItems.registerBlockItem();
}
}```
do you have an example on what you mean?
You see how in ModItems each item is a field set to the result of registerItem?
yeah
so kinda like this? ``` public static final Item TIME_STONE = registerBlockItem("time-stone", new Item(new Item.Properties()));
Yes except instead of new Item(new Item.Properties()), the second parameter should be your block
Since registerBlockItem expects Block as the second parameter
so what should the syntax be instead? is it this new Item(block.Properties()));
No, the way you access your block is ModBlocks.TIME_STONE
what you mean by second parameter, you mean the new Item.Properties() part correct? or are you referring to another part?
The second parameter to registerBlockItem is currently set to new Item(new Item.Properties()) but it should be ModBlocks.TIME_STONE
The first parameter is set to "time-stone"
so you replace the current thing to ModBlocks.TIME_STONE
Yeah
``` like that?
Yes
ohhhh
If you look at the definition of registerBlockItem it says the first parameter should be a String and the second parameter should be a Block
Since ModBlocks.TIME_STONE is a Block it can be used for that parameter, but new Item(...) is not a Block
that makes so much more sense. So where would you go to read up on those definitions?
ahh okay
let me test in game and see if it works
okay. so the block appeared in game, the textures just busted
so that part did work, it did register
That's expected if you didn't define a model(s)
Wait were you following a tutorial for adding blocks an items? There should have been a section on block items
i did? I have it undr the models/blocks folder
Item model
I was following a tutorial, but the method he used and a method another guy that helped me use was different
cause i have one in the models/item folder
Oh okay that should be correct
Yeah that sounds correct
do i need to include another png in the item texture even if i have it in the block texture?
time-stone
its time-stone.json
i also have it in the block model folder also
thats the part i copied from the tutorial\
What's the name of the block model file?
time-stone.json
your hyphens and underscores are probably mismatched somewhere
I'd recommend making them all underscores
i meanty time_stone.json, mb
its heres the full thing if you wanna see it
resources/assets/time-again/models/block/time_stone.json
What does it look like in the menu? Is it a magenta and black square or a magenta and black cube?
want a screenshot?
Sure
hey, so im sorry if im asking so many dumb questions. I only have the most bare bone experience with java. i know it was stupid to make a mod on minimal experience, and its probably annoying for you
No it's fine this is part of the learning process
i was told not to do it by a mod developer
The only way to learn is to do
hm ok can you your latest.log via https://mclo.gs
Easily paste your Minecraft logs to share and analyse them.
not sure how to find those logs with this but let me check
They're in run/logs
okay so i sent it through mclo?
It should give you a link you can send here
it didnt give a link, it just posted it
Did it change the url?
Ah yeah that's it
okie\
the other texture based errors from the items besides time-stone are because i didnt make them yet, so thats why
Huh it says it couldn't find models/item/time-stone.json
Did you restart/reload textures after adding it?
Ah it has an underscore but the item has a hyphen
Again I'd suggest using underscores everywhere
where did i add that hyphen?
ohhh
now i see it
lemme relog and see if it fixed
also, do you by chance happen to know any good tutorials for creating the inventory stuff for the items and blocks?
As in the creative inventory tabs?
yeah
the tutorial i found didnt have the same structure as the layout my friend taught me
Well the principles should be the same, just where the code goes might be different
the friend i used to help make the code for the items said that the tutorial i was watching was old and outdated
Well the version you're on is pretty old so that's not unexpected tbh
yeah
heres the video if you wanna see what i mean
Fabric Modding Tutorial - Minecraft 1.20: Custom Items & Creative Mode Tab | #2 by Modding by Kaupenjoe
do you mind if i try it and come back here if it doesnt work?
Sure
This thread is fine
apparently ItemGroup aint a thing
i tried to import it into the ModItemGroups.java and one doesnt exist
Oh wait is the tutorial using yarn instead of mojmap?
Okay that is a bit of an issue
Do you know what mappings are?
kinda
but apparently the friend of mine said that yarn wasnt being utilized in intelliJ anymore
It should still be usable on versions <26.1
They didn't remove support for it or anything
so what should i do?
You can either use https://mappings.dev/ or https://linkie.shedaniel.dev/mappings to translate everything in the tutorial, or find a mojmap tutorial
the mappings apparently came to an end
in 26.1+ but they still exist for lower versions
thats what the mappings website says
ius there a way to see which version im on now
Should be in gradle.properties
0.18.4
minecraft_version not loader_version
1.20.1
something that has to be on 1.20.1
Okay makes sense
i dont know enough to try and model on anything other than .1
Block/item models haven't changed much, item model overrides were replaced though
When they use a class in the tutorial, look it up in the search (make sure it's labeled Yarn) then in the page look for the Mojang version
e.g. ItemGroup
so i use that instead ?
the tutrorial still breaks tho ;c
I'm not sure if there are any tutorials for fabric 1.20.1 in mojmap
yeah..
cause apparently the tutorial uses Identifiers and that didnt work, so my friend used BuiltInRegistries instead
Those are different things but ok
Yarn still works perfectly fine below 26.1 I think that might be easiest for you as a beginner
want to see what i have?
For what?
in the ModItemsGroup thats busted
Oh sure
Okay look up Registries and Identifier in the mappings
That's the same because it's part of fabric not Minecraft
so if its not showing up then its a fabric issue on my end?
Oh wait you meant in the code not in the mappings site right?
both
i searched the package and it wasnt there, and builder never showed up in the code either when i tried to use tab
Huh ok
cause he used FabricItemGroup.builder() but the fabricItemGroup shows up but not the builder part after
isnt it shift and hover to see def
I would highly recommend watching kaupenjoes modding videos, it gives some structure and allows you to learn how the code works after copying it. I’d also recommend making some separate java projects to familiarize yourself with the syntax.
And one other thing never use AI it codes in a confusing way that can be difficult for beginners to read.
I did watch the tutorial. The tutorial doesn’t work properly right now so that’s why I am here asking for help on it lol
Kaupenjoe is in yarn but they're using mojmap
Use 1.22
*21
I would, but the problem is that I am still a novice so its hard for me to figure this out
I think it'd be easiest for you to use yarn instead of mojmap since the tutorials are likely all yarn and it doesn't sound like you've written too much code to migrate yet
Or wait until the 26.1 update where yarn doesn't exist anymore
^
Also you'd have to wait for tutorials to come out
So it’s a relatively new thing switching over to Mojmaps?