#Help with Custom Blocks

267 messages · Page 1 of 1 (latest)

winter token
#

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?

tidal elm
#

It sounds like you didn't register an item for your block

winter token
#

I used the register one in the ModBlocks but it didnt workj

tidal elm
#

Does your block show up with /setblock?

winter token
#

it doesnt even show up in give

tidal elm
#

Yes but did you try setblock?

winter token
#

want me to send the code for the ModBlocks file? Lemme check the place rq

tidal elm
winter token
#

I could be very wrong in how i coded it. But there werent any errors on my end. Only small stuff but nothing red

tidal elm
winter token
#

Okay so yeah, your right. It does appear in the setblock

#

but not in the give command

tidal elm
#

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

winter token
#

i thought i did that in the ModBlocks file

tidal elm
#

You registered an item in ModBlocks?

#

Okay now show the code then

winter token
#

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

tidal elm
#

Where did you call registerBlockItem?

winter token
#

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?

tidal elm
#

Yes otherwise the code never runs

#

although usually that goes in the items class

winter token
#

which part should go in the items class?

tidal elm
#

registering the blockitem

winter token
#

so which part of the first code that i sent should be in ModItems?

tidal elm
#

the registerBlockItem function

#

and then you register a new item using that function and your block

winter token
#

so should it be ModItems.registerBlockItem?

tidal elm
#

Yeah

#

It's not required but it's better for organization I'd say

winter token
#

why would that go in the ModItems class and not the main class?

tidal elm
#

Because it deals with items

winter token
#

ahhh

#

would it be easier for you to see it in vc

tidal elm
#

I can't vc right now

winter token
#

okay, well i tried adding it to the ModItems using the public void onInitialize but it doesnt seem to work

tidal elm
#

Show your moditems?

winter token
#

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);
    }
}```
tidal elm
#

You just need to register your blockitem

winter token
#

if im way off im sorry in advance i really am trying looll

#

you mean through the private static ?

tidal elm
#

Oh wait why do you have a method outside the class

winter token
#

whatcha mean?

tidal elm
#

onInitialize seems to be outside ModItems

winter token
#

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();

    }
}```
tidal elm
#

That one's fine

#

I'm talking about the one in your ModItems file

winter token
#

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

tidal elm
#

I meant move the function registerBlockItem from ModBlocks to ModItems

#

so it's after registerItem

winter token
#

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())); }

tidal elm
#

Yep that whole thing

winter token
#

why wouldnt it be called in the ModBlocks?

tidal elm
#

Because it creates an item and items usually go in the items class

winter token
#

So anything that registers an Item goes in the ModItems class?

tidal elm
#

Typically

winter token
#

Even if it is in regard to a block?:

tidal elm
#

Yes

#

At least that's how I've seen it

winter token
#

lets hope it works

tidal elm
#

but if you really want you can put the item in your ModBlocks class

winter token
#

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

tidal elm
#

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

winter token
#

registerBlockItem(String name, Block block)

#

thats in the ModItems folder, is that what you mean?

tidal elm
#

folder?

winter token
#

what do you mean folder? do you wanna see the mod folder?

tidal elm
#

What do you mean by ModItems folder? Isn't ModItems a file?

winter token
#

it is yeah

#

heres the path

#

or this one if it helps java/com/renegade/item/ModItems.java

tidal elm
winter token
#

Yeah mb

#

it was the ModItems.java class in the Items folder

tidal elm
#

Ah ok got it

winter token
#

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();
    }
}```
tidal elm
#

Okay that's not how registerBlockItem is meant to be used

#

It's like registerItem

winter token
#

do you have an example on what you mean?

tidal elm
#

You see how in ModItems each item is a field set to the result of registerItem?

winter token
#

yeah

tidal elm
#

You want to do the same but with registerBlockItem

#

and remove it from onInitialize

winter token
#

so kinda like this? ``` public static final Item TIME_STONE = registerBlockItem("time-stone", new Item(new Item.Properties()));

tidal elm
#

Yes except instead of new Item(new Item.Properties()), the second parameter should be your block

#

Since registerBlockItem expects Block as the second parameter

winter token
#

so what should the syntax be instead? is it this new Item(block.Properties()));

tidal elm
#

No, the way you access your block is ModBlocks.TIME_STONE

winter token
#

what you mean by second parameter, you mean the new Item.Properties() part correct? or are you referring to another part?

tidal elm
#

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"

winter token
#

so you replace the current thing to ModBlocks.TIME_STONE

tidal elm
#

Yeah

winter token
#
``` like that?
tidal elm
#

Yes

winter token
#

ohhhh

tidal elm
#

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

winter token
#

that makes so much more sense. So where would you go to read up on those definitions?

tidal elm
#

Definitions?

#

Oh you can ctrl+click on an element to go to its definition

winter token
#

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

tidal elm
#

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

winter token
#

i did? I have it undr the models/blocks folder

tidal elm
#

Item model

winter token
tidal elm
#

I see

#

Well see if the tutorial has a section on item models

winter token
#

cause i have one in the models/item folder

tidal elm
#

Oh okay that should be correct

winter token
#

this is whats in it

#
  "parent": "time-again:block/time_stone"
}```
tidal elm
#

Yeah that sounds correct

winter token
#

do i need to include another png in the item texture even if i have it in the block texture?

tidal elm
#

Nope

#

What's the file name?

winter token
#

time-stone

#

its time-stone.json

#

i also have it in the block model folder also

#

thats the part i copied from the tutorial\

tidal elm
#

What's the name of the block model file?

winter token
#

time-stone.json

tidal elm
#

your hyphens and underscores are probably mismatched somewhere

#

I'd recommend making them all underscores

winter token
#

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

tidal elm
#

What does it look like in the menu? Is it a magenta and black square or a magenta and black cube?

winter token
#

want a screenshot?

tidal elm
#

Sure

winter token
#

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

tidal elm
#

No it's fine this is part of the learning process

winter token
#

i was told not to do it by a mod developer

tidal elm
#

The only way to learn is to do

winter token
tidal elm
winter token
#

not sure how to find those logs with this but let me check

tidal elm
#

They're in run/logs

winter token
#

okay so i sent it through mclo?

tidal elm
#

It should give you a link you can send here

winter token
#

it didnt give a link, it just posted it

tidal elm
#

Did it change the url?

winter token
tidal elm
#

Ah yeah that's it

winter token
#

okie\

#

the other texture based errors from the items besides time-stone are because i didnt make them yet, so thats why

tidal elm
#

Huh it says it couldn't find models/item/time-stone.json

#

Did you restart/reload textures after adding it?

winter token
#

yeah

#

ity was already there when i started it

#

proof that its there

tidal elm
#

Ah it has an underscore but the item has a hyphen

#

Again I'd suggest using underscores everywhere

winter token
#

where did i add that hyphen?

tidal elm
#

In ModItems

#

"time-stone"

winter token
#

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?

tidal elm
#

As in the creative inventory tabs?

winter token
#

yeah

#

the tutorial i found didnt have the same structure as the layout my friend taught me

tidal elm
#

Well the principles should be the same, just where the code goes might be different

winter token
#

the friend i used to help make the code for the items said that the tutorial i was watching was old and outdated

tidal elm
#

Well the version you're on is pretty old so that's not unexpected tbh

winter token
#

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

tidal elm
#

That sounds fine

#

I haven't seen the video but

winter token
#

do you mind if i try it and come back here if it doesnt work?

tidal elm
#

Sure

winter token
#

or should i make a new thread

#

which do you prefer\

tidal elm
#

This thread is fine

winter token
#

apparently ItemGroup aint a thing

#

i tried to import it into the ModItemGroups.java and one doesnt exist

tidal elm
#

Oh wait is the tutorial using yarn instead of mojmap?

#

Okay that is a bit of an issue

#

Do you know what mappings are?

winter token
#

kinda

#

but apparently the friend of mine said that yarn wasnt being utilized in intelliJ anymore

tidal elm
#

It should still be usable on versions <26.1

#

They didn't remove support for it or anything

winter token
#

so what should i do?

tidal elm
winter token
#

the mappings apparently came to an end

tidal elm
#

in 26.1+ but they still exist for lower versions

winter token
#

thats what the mappings website says

#

ius there a way to see which version im on now

tidal elm
#

Should be in gradle.properties

winter token
#

0.18.4

tidal elm
#

minecraft_version not loader_version

winter token
#

1.20.1

tidal elm
#

Yep

#

Are you modding for a specific server or something that has to be on 1.20.1?

winter token
#

something that has to be on 1.20.1

tidal elm
#

Okay makes sense

winter token
#

i dont know enough to try and model on anything other than .1

tidal elm
#

Block/item models haven't changed much, item model overrides were replaced though

winter token
#

so what should i do then?

#

which part of the mapping should i look at?

tidal elm
#

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

winter token
#

so i use that instead ?

tidal elm
#

Yep

#

and for functions they're all listed in the class page

winter token
#

the tutrorial still breaks tho ;c

tidal elm
#

I'm not sure if there are any tutorials for fabric 1.20.1 in mojmap

winter token
#

yeah..

#

cause apparently the tutorial uses Identifiers and that didnt work, so my friend used BuiltInRegistries instead

tidal elm
#

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

winter token
#

want to see what i have?

tidal elm
#

For what?

winter token
#

in the ModItemsGroup thats busted

tidal elm
#

Oh sure

winter token
#

apparently this has four errors

tidal elm
#

Okay look up Registries and Identifier in the mappings

winter token
#

apparently FabricItemGroups.builder is also not present

#

so ill try and look it up

tidal elm
#

That's the same because it's part of fabric not Minecraft

winter token
#

so if its not showing up then its a fabric issue on my end?

tidal elm
#

Oh wait you meant in the code not in the mappings site right?

winter token
#

both

#

i searched the package and it wasnt there, and builder never showed up in the code either when i tried to use tab

tidal elm
#

Huh ok

winter token
#

cause he used FabricItemGroup.builder() but the fabricItemGroup shows up but not the builder part after

tidal elm
#

Huh it should be there

#

What do you see for the definition of FabricItemGroup?

winter token
#

isnt it shift and hover to see def

tidal elm
#

No it's ctrl+click

#

Or F12 I think

wintry sable
#

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.

winter token
#

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

tidal elm
winter token
#

I would, but the problem is that I am still a novice so its hard for me to figure this out

tidal elm
#

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

wintry shard
tidal elm
#

Also you'd have to wait for tutorials to come out

winter token
#

So it’s a relatively new thing switching over to Mojmaps?