Jump to content

Maxi07

Members
  • Posts

    107
  • Joined

  • Last visited

Posts posted by Maxi07

  1. 14 minutes ago, poopoodice said:
    
    RegistryObject.of(new ResourceLocation(OresCores.MODID, "telerite_ore"), ForgeRegistries.BLOCKS);

    is null when you call it there

     

    14 minutes ago, poopoodice said:

    call it

    .get() or

    RegistryObject.of(new ResourceLocation(OresCores.MODID, "telerite_ore"), ForgeRegistries.BLOCKS);

    ?

  2. 9 hours ago, Draco18s said:

    do not store the result of get(), just call get() when you need the block/item/etc.

    Now it is crashing again, but a bit differently:

    debug.log

     

    RegisterBlocks.java:

    package maxi.ores_cores.init;
    
    @EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
    public class RegisterBlocks {
    
    	@SubscribeEvent
    	public static void registerBlock(Register<Block> event) {
    		
    	  event.getRegistry().registerAll(
    				
    		new SimpleBlock(OresCores.MODID, "emoulrite_block", Properties.create(Material.IRON, MaterialColor.GOLD).sound(SoundType.METAL).hardnessAndResistance(5f, 6f).harvestTool(ToolType.PICKAXE).harvestLevel(2)),
    		new SimpleOreBlock(OresCores.MODID, "emoulrite_ore", Properties.create(Material.ROCK, MaterialColor.STONE).sound(SoundType.STONE).hardnessAndResistance(3f, 3f).harvestTool(ToolType.PICKAXE).harvestLevel(2)),
    		new SimpleBlock(OresCores.MODID, "telerite_block", Properties.create(Material.IRON, MaterialColor.PURPLE).sound(SoundType.METAL).hardnessAndResistance(5f, 6f).harvestTool(ToolType.PICKAXE).harvestLevel(2)),
    		new SimpleOreBlock(OresCores.MODID, "telerite_ore", Properties.create(Material.ROCK, MaterialColor.SAND).sound(SoundType.STONE).hardnessAndResistance(4f, 9f).harvestTool(ToolType.PICKAXE).harvestLevel(2))
    		
    	  );
    	}
    	
    	@SubscribeEvent
    	public static void registerItem(Register<Item> event) {
    		
    	  event.getRegistry().registerAll(
    		
    		new SimpleBlockItem(Blocks.EMOULRITE_BLOCK.get(), ItemGroup.BUILDING_BLOCKS),
    		new SimpleBlockItem(Blocks.EMOULRITE_ORE.get(), ItemGroup.BUILDING_BLOCKS),
    		new SimpleBlockItem(Blocks.TELERITE_BLOCK.get(), ItemGroup.BUILDING_BLOCKS),
    		new SimpleBlockItem(Blocks.TELERITE_ORE.get(), ItemGroup.BUILDING_BLOCKS)
    		
    	  );
    	}
    }

     

    Blocks.java:

    package maxi.ores_cores.blocks;
    
    public class Blocks {
    	
    	public static final RegistryObject<Block> EMOULRITE_BLOCK = RegistryObject.of(new ResourceLocation(OresCores.MODID, "emoulrite_block"), ForgeRegistries.BLOCKS);
    	public static final RegistryObject<Block> EMOULRITE_ORE = RegistryObject.of(new ResourceLocation(OresCores.MODID, "emoulrite_ore"), ForgeRegistries.BLOCKS);
    	public static final RegistryObject<Block> TELERITE_BLOCK = RegistryObject.of(new ResourceLocation(OresCores.MODID, "telerite_block"), ForgeRegistries.BLOCKS);
    	public static final RegistryObject<Block> TELERITE_ORE = RegistryObject.of(new ResourceLocation(OresCores.MODID, "telerite_ore"), ForgeRegistries.BLOCKS);
    }

     

  3. After I remade my registration system again (for causes see my comments at [1.16.1] The Book of Minecraft Modding - complete guide for beginners), 

    the game now crashes with the main problem: java.lang.NullPointerException: Registry Object not present: ores_cores:emoulrite_block

     

    debug.log:

    debug.log

     

    I cut out the imports in the source code

     

    RegisterBlocks.java:

    package maxi.ores_cores.init;
    
    @EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
    public class RegisterBlocks {
    
    	@SubscribeEvent
    	public static void registerBlock(Register<Block> event) {
    		
    	  event.getRegistry().registerAll(
    				
    		new SimpleBlock(OresCores.MODID, "emoulrite_block", Properties.create(Material.IRON, MaterialColor.GOLD).sound(SoundType.METAL).hardnessAndResistance(5f, 6f).harvestTool(ToolType.PICKAXE).harvestLevel(2)),
    		new SimpleOreBlock(OresCores.MODID, "emoulrite_ore", Properties.create(Material.ROCK, MaterialColor.STONE).sound(SoundType.STONE).hardnessAndResistance(3f, 3f).harvestTool(ToolType.PICKAXE).harvestLevel(2)),
    		new SimpleBlock(OresCores.MODID, "telerite_block", Properties.create(Material.IRON, MaterialColor.PURPLE).sound(SoundType.METAL).hardnessAndResistance(5f, 6f).harvestTool(ToolType.PICKAXE).harvestLevel(2)),
    		new SimpleOreBlock(OresCores.MODID, "telerite_ore", Properties.create(Material.ROCK, MaterialColor.SAND).sound(SoundType.STONE).hardnessAndResistance(4f, 9f).harvestTool(ToolType.PICKAXE).harvestLevel(2))
    		
    	  );
    	}
    	
    	@SubscribeEvent
    	public static void registerItem(Register<Item> event) {
    		
    	  event.getRegistry().registerAll(
    		
    		new SimpleBlockItem(Blocks.EMOULRITE_BLOCK, ItemGroup.BUILDING_BLOCKS),
    		new SimpleBlockItem(Blocks.EMOULRITE_ORE, ItemGroup.BUILDING_BLOCKS),
    		new SimpleBlockItem(Blocks.TELERITE_BLOCK, ItemGroup.BUILDING_BLOCKS),
    		new SimpleBlockItem(Blocks.TELERITE_ORE, ItemGroup.BUILDING_BLOCKS)
    		
    	  );
    	}
    }

     

    SimpleBlock.java (SimpleOreBlock is similar):

    package maxi.ores_cores.blocks;
    
    public class SimpleBlock extends Block {
    
    	public SimpleBlock(Properties properties) {
    		super(properties);
    	}
    	
    	public SimpleBlock(String modid, String name, Properties properties) {
    		super(properties);
    		this.setRegistryName(modid, name);
    	}
    	
    }

     

    Blocks.java:

    package maxi.ores_cores.blocks;
    
    public class Blocks {
    	
    	public static final Block EMOULRITE_BLOCK = RegistryObject.of(new ResourceLocation(OresCores.MODID, "emoulrite_block"), ForgeRegistries.BLOCKS).get();
    	public static final Block EMOULRITE_ORE = RegistryObject.of(new ResourceLocation(OresCores.MODID, "emoulrite_ore"), ForgeRegistries.BLOCKS).get();
    	public static final Block TELERITE_BLOCK = RegistryObject.of(new ResourceLocation(OresCores.MODID, "telerite_block"), ForgeRegistries.BLOCKS).get();
    	public static final Block TELERITE_ORE = RegistryObject.of(new ResourceLocation(OresCores.MODID, "telerite_ore"), ForgeRegistries.BLOCKS).get();
    
    }

     

    SimpleBlockItem.java:

    package maxi.ores_cores.items;
    
    public class SimpleBlockItem extends BlockItem {
    
    	public SimpleBlockItem(Block block, ItemGroup group) {
    		super(block, new Properties().group(group));
    		this.setRegistryName(block.getRegistryName());
    	}
    
    }

     

    My guess is that the static fields at Blocks.java are initialized before the block registry event is fired, therefore the blocks that I try to get doesn´t exist.

  4. Now it finally works! Every tutorial I've seen used static initializers. What are the problems, why I should avoid them (I know you said something about timing above)? And by the way, is my code now finally not bad?

    @EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
    public class RegisterBlocks {
    
    	@SubscribeEvent
    	public static void registerBlock(Register<Block> event) {
    		
    		final Block EXAMPLE_BLOCK = new Block(Properties.create(Material.ROCK, MaterialColor.STONE).sound(SoundType.STONE).hardnessAndResistance(3, 3).harvestTool(ToolType.PICKAXE).harvestLevel(2));
    		
    		final IForgeRegistry<Block> registry = event.getRegistry();
    		registry.register(EXAMPLE_BLOCK.setRegistryName(OresCores.MODID, "example_block"));
    	}
    	
    	@SubscribeEvent
    	public static void registerItem(Register<Item> event) {
    		final IForgeRegistry<Item> registry = event.getRegistry();
    		registry.register(new BasicBlockItem(Blocks.EXAMPLE_BLOCK, ItemGroup.BUILDING_BLOCKS));
    	}
    }

    Blocks.java:

    @ObjectHolder(value = OresCores.MODID)
    public class Blocks {
    
    	public static final Block EXAMPLE_BLOCK = null;
    	
    }

     

  5. So will this already work?

    package maxi.ores_cores.init;
    
    import maxi.ores_cores.OresCores;
    import maxi.ores_cores.items.BasicBlockItem;
    import net.minecraft.block.Block;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.Block.Properties;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.material.MaterialColor;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemGroup;
    import net.minecraftforge.common.ToolType;
    import net.minecraftforge.event.RegistryEvent.Register;
    import net.minecraftforge.eventbus.api.SubscribeEvent;
    import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
    import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
    import net.minecraftforge.registries.IForgeRegistry;
    import net.minecraftforge.registries.ObjectHolder;
    
    @EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
    @ObjectHolder(value = OresCores.MODID)
    public class RegisterBlocks {
    
    	public static final Block EXAMPLE_BLOCK = new Block(Properties.create(Material.ROCK, MaterialColor.STONE).sound(SoundType.STONE).hardnessAndResistance(3, 3).harvestTool(ToolType.PICKAXE).harvestLevel(2));
    	
    	@SubscribeEvent
    	public static void registerBlock(Register<Block> event) {
    		final IForgeRegistry<Block> registry = event.getRegistry();
    		registry.register(EXAMPLE_BLOCK.setRegistryName(OresCores.MODID, "emoulrite_block"));
    	}
    	
    	@SubscribeEvent
    	public static void registerItem(Register<Item> event) {
    		final IForgeRegistry<Item> registry = event.getRegistry();
    		registry.register(new BasicBlockItem(EXAMPLE_BLOCK, ItemGroup.BUILDING_BLOCKS));
    	}
    }

     

  6. On 7/4/2020 at 4:11 AM, ChampionAsh5357 said:

    Please use object holder to "hold" the block and item instances when registering or use deferred register if you're going to statically initialize anything.

    Okay, now I am finally continue with modding. I am changing my whole registration system and how I add blocks and items. I dont want the static intializer problem, but I dont want to use DefferedRegisries either (please dont ask why). So I looked at the minecraft classes net.minecraft.block.Blocks and net.minecraft.item.Items where the minecraft blocks and items are registered. I want to do this similar. I should use ObjectHolders. I searched how they work but I couldn't find something that could help me. And now I am asking here. And please say if you have an idea how i could make my registration system without DefferedRegisries and problems.

    Thanks!

  7. You need to change to change the forge version and the mappings in your build.gradle (look at the build.gradle of the 1.16 MDK). And you also need to change a few values in your mod.toml to make FML able to load your mod.

  8. 6 hours ago, ChampionAsh5357 said:

    Please use object holder to "hold" the block and item instances when registering or use deferred register if you're going to statically initialize anything. What you have written for custom blocks is just wrong.

    I register my items and blocks similar:

     

    RegisterBlocks.java

    package maxi.ores_cores.init;
    
    import maxi.ores_cores.OresCores;
    import maxi.ores_cores.blocks.*;
    import maxi.ores_cores.items.BasicBlockItem;
    import net.minecraft.block.Block;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemGroup;
    import net.minecraftforge.event.RegistryEvent.Register;
    import net.minecraftforge.eventbus.api.SubscribeEvent;
    import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
    import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
    import net.minecraftforge.registries.IForgeRegistry;
    
    @EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
    public class RegisterBlocks {
    
    	@SubscribeEvent
    	public static void registerBlock(Register<Block> event) {
    		final IForgeRegistry<Block> registry = event.getRegistry();
    		registry.register(MetalBlock.EMOULRITE_BLOCK.setRegistryName(OresCores.MODID, "emoulrite_block"));
    		registry.register(Ore.EMOULRITE_ORE.setRegistryName(OresCores.MODID, "emoulrite_ore"));
    		registry.register(MetalBlock.TELERITE_BLOCK.setRegistryName(OresCores.MODID, "telerite_block"));
    		registry.register(Ore.TELERITE_ORE.setRegistryName(OresCores.MODID, "telerite_ore"));
    	}
    	
    	@SubscribeEvent
    	public static void registerItem(Register<Item> event) {
    		final IForgeRegistry<Item> registry = event.getRegistry();
    		registry.register(new BasicBlockItem(MetalBlock.EMOULRITE_BLOCK, ItemGroup.BUILDING_BLOCKS));
    		registry.register(new BasicBlockItem(Ore.EMOULRITE_ORE, ItemGroup.BUILDING_BLOCKS));
    		registry.register(new BasicBlockItem(MetalBlock.TELERITE_BLOCK, ItemGroup.BUILDING_BLOCKS));
    		registry.register(new BasicBlockItem(Ore.TELERITE_ORE, ItemGroup.BUILDING_BLOCKS));
    	}
    }

     

    MetalBlock.java (Ore.java is similar)

    package maxi.ores_cores.blocks;
    
    import net.minecraft.block.SoundType;
    import net.minecraft.block.Block;
    import net.minecraft.block.Block.Properties;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.material.MaterialColor;
    import net.minecraftforge.common.ToolType;
    
    public class MetalBlock {
    	
    	public static final Block EMOULRITE_BLOCK = new Block(Properties
    								.create(Material.IRON, MaterialColor.GOLD).sound(SoundType.METAL)
    								.hardnessAndResistance(5, 6)
    								.harvestTool(ToolType.PICKAXE).harvestLevel(2));
    	
    	public static final Block TELERITE_BLOCK = new Block(Properties
    								.create(Material.IRON, MaterialColor.PURPLE).sound(SoundType.METAL)
    								.hardnessAndResistance(5, 6)
    								.harvestTool(ToolType.PICKAXE).harvestLevel(2));
    	
    }

     

    BasicBlockItem.java

    package maxi.ores_cores.items;
    
    import net.minecraft.block.Block;
    import net.minecraft.item.BlockItem;
    import net.minecraft.item.ItemGroup;
    
    public class BasicBlockItem extends BlockItem {
    
    	public BasicBlockItem(Block block, ItemGroup group) {
    		super(block, new Properties().group(group));
    		setRegistryName(block.getRegistryName());
    	}
    
    }

     

    Whats bad about this? I am new to modding and I appreciate every suggestion for improvement that I get

  9. On 6/27/2020 at 12:10 AM, Curle said:

    MCP is outdated and isn't used any more. We have a newer system in place.

    See the Discord/IRC.

    But now, the newest mappings are from mcpbot, right? And when mcpbot has 1.16 mappings I should prefer them, if I want newer mappings, right?

  10. Is this right? My IDE marks all as warnings because DeferredWorkQueue is deprecated. Should I just use @SuppressWarnings("deprecation")?

    package maxi.ores_cores.init;
    
    import maxi.ores_cores.OresCores;
    import maxi.ores_cores.world.gen.*;
    import net.minecraftforge.eventbus.api.SubscribeEvent;
    import net.minecraftforge.fml.DeferredWorkQueue;
    import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
    import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
    import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
    
    @EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
    public class RegisterWorldGen {
    
    	@SubscribeEvent
    	public static void registerWorldGen(FMLCommonSetupEvent event) {
    		DeferredWorkQueue.runLater(new Runnable() {
    			@Override
    			public void run() {
    				
    				EmoulriteOreGen.generateOre();
    				TeleriteOreGen.generateOre();
    				
    			}
    		});
    	}
    	
    }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.