Jump to content

Recommended Posts

Posted

EDIT: I fixed this by moving everything having to do with rendering the stair block in BlockStonebrickLightStairs to RandomBlocks.

 

I made a custom stair and I don't know why it's not working properly. I can see the block in game, fully rendered and textured, it's just in the inventory slot it's a no textured block. It also is a full-sized block in my hand while looking in third-person.

 

RandomBlocks:

package com.kansastoyou.mod.init;

import com.kansastoyou.mod.RandomMod;
import com.kansastoyou.mod.Reference;
import com.kansastoyou.mod.blocks.BlockCheese;
import com.kansastoyou.mod.blocks.BlockStonebrickLight;
import com.kansastoyou.mod.blocks.BlockStonebrickLightStairs;
import com.kansastoyou.mod.blocks.BlockStonebrickDark;

import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class RandomBlocks {

//Cheese Block
public static Block cheese_block;

//Light Stonebrick
public static Block stonebrick_light;

//Dark Stonebrick
public static Block stonebrick_dark;

//Light Stonebrick Stairs

public static BlockStairs stonebrick_light_stairs;


public static void init()
{
	cheese_block = new BlockCheese(Material.sponge).setUnlocalizedName("cheese_block").setCreativeTab(RandomMod.tabRandom);
	stonebrick_light = new BlockStonebrickLight(Material.rock).setUnlocalizedName("stonebrick_light").setCreativeTab(RandomMod.tabRandom);;
	stonebrick_dark = new BlockStonebrickDark(Material.rock).setUnlocalizedName("stonebrick_dark").setCreativeTab(RandomMod.tabRandom);;	
	stonebrick_light_stairs = new BlockStonebrickLightStairs(Material.rock, "stonebrick_light_stairs", 3.0F, 5.0F, RandomMod.tabRandom, BlockStonebrickLightStairs.HarvestToolEnum.PICKAXE, BlockStonebrickLightStairs.HarvestLevelEnum.STONE);

}

public static void register()
{
	GameRegistry.registerBlock(cheese_block, cheese_block.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(stonebrick_light, stonebrick_light.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(stonebrick_dark, stonebrick_dark.getUnlocalizedName().substring(5));		

}	

public static void registerRenders()
{
	registerRender(cheese_block);
	registerRender(stonebrick_light);
	registerRender(stonebrick_dark);

}

public static void registerRender(Block block)
{
	Item item = Item.getItemFromBlock(block);
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));		
}
}

 

BlockStonebrickLightStairs

package com.kansastoyou.mod.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;

import com.kansastoyou.mod.RandomMod;
import com.kansastoyou.mod.Reference;

public class BlockStonebrickLightStairs extends BlockStairs {

        
      private Item dropsOnHarvest;
      private int dropamountmax = 1;
      private int maxharvestEXP = 0;

       
      
       public BlockStonebrickLightStairs(Material material, String name, float hardness, float resistance, CreativeTabs creativetab, HarvestToolEnum harvesttool, HarvestLevelEnum harvestlevel)
       {
           super(Blocks.stone_brick_stairs.getStateFromMeta(0));
                        
            this.setUnlocalizedName(name);
            this.setHardness(hardness);
            this.setResistance(resistance);
            this.setStepSound(soundTypePiston);
            this.setCreativeTab(RandomMod.tabRandom);      
            this.setHarvestLevel(harvesttool, harvestlevel);
            this.useNeighborBrightness = true;
            
            GameRegistry.registerBlock(this, name);
            
            this.dropsOnHarvest = Item.getItemFromBlock(this);
           }
       public void RegisterRenderer(String modelName)
      {         
         Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(this), 0, new ModelResourceLocation(Reference.MOD_ID +":"+modelName, "inventory"));
      }      
       private void setHarvestLevel(HarvestToolEnum harvesttool,
            HarvestLevelEnum harvestlevel) {
          int level;
         String tool;
         
         switch(harvesttool)
         {
            case PICKAXE:
               tool = "pickaxe";
               break;
            case SHOVEL:
               tool = "shovel";
               break;
            case AXE:
               tool = "axe";
               break;
            default:
               tool = "pickaxe";
         }
         switch(harvestlevel)
         {
            case WOOD:
               level = 0;
               break;
            case STONE:
               level = 1;
               break;
            case IRON:
               level = 2;
               break;
            case DIAMOND:
               level = 3;
               break;
            case GOLD:
               level = 0;
               break;
            default:
               level = 0;
         }
         super.setHarvestLevel(tool, level);
       }   
      
      public static enum HarvestToolEnum
      {
         PICKAXE,
         SHOVEL,
         AXE;      
      }   
      public static enum HarvestLevelEnum
      {
         WOOD,
         STONE,
         IRON,
         DIAMOND,
         GOLD;
      }
      
      
      public void setMaxHarvestEXP(int expAmount)
      {
         maxharvestEXP = expAmount;
      }
      
      public void setDrops(Item drops)
      {
         this.dropsOnHarvest = drops;
      }
      public void setDrops(Block drops)
      {
         this.dropsOnHarvest = Item.getItemFromBlock(drops);
      }
      
      public void setDropMaxAmount(int dropamount)
      {
         this.dropamountmax = dropamount;
      }
      
      public Item getItemDropped(IBlockState state, Random rand, int fortune)
       {
          return this.dropsOnHarvest;
       }
      
      public int quantityDropped(Random random)
       {      
         int amount = random.nextInt(this.dropamountmax)+1;
           return amount;
       }
      
      public int getExpDrop(IBlockAccess world, BlockPos pos, int fortune)
       {
           IBlockState state = world.getBlockState(pos);
           Random rand = world instanceof World ? ((World)world).rand : new Random();
           if (this.getItemDropped(state, rand, fortune) != Item.getItemFromBlock(this))
           {
              return MathHelper.getRandomIntegerInRange(rand, 0, maxharvestEXP);
           }
           return 0;
       }
   }

 

I'm not sure if these classes have anything to do with the problem, but here they are anyway.

 

ClientProxy

package com.kansastoyou.mod.proxy;

import com.kansastoyou.mod.init.RandomBlocks;
import com.kansastoyou.mod.init.RandomItems;

public class ClientProxy extends CommonProxy{
@Override
public void registerRenders() {
	RandomBlocks.registerRenders();
	RandomItems.registerRenders();
}
}

 

CommonProxy

package com.kansastoyou.mod.proxy;

public class CommonProxy {
public void registerRenders() {

}
}

 

Screenshots of Problem:

 

w08TRGR.png

 

s3LObcH.png

 

I'm not that experienced in Forge modding, or modding in general, but any help is appreciated.

Posted

RandomMod

package com.kansastoyou.mod;

import com.kansastoyou.mod.init.RandomBlocks;
import com.kansastoyou.mod.init.RandomItems;
import com.kansastoyou.mod.proxy.CommonProxy;

import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class RandomMod {

@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;

public static final RandomTab tabRandom = new RandomTab("tabRandom");

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	RandomBlocks.init();
	RandomBlocks.register();
	RandomItems.init();
	RandomItems.register();
}

@EventHandler
public void init(FMLInitializationEvent event)
{
	proxy.registerRenders();

	//Cheese Item Crafting/Smelting Recipe
	GameRegistry.addShapelessRecipe(new ItemStack(RandomItems.cheese_item, 9), new Object[]{RandomBlocks.cheese_block});
	GameRegistry.addSmelting(new ItemStack(Items.milk_bucket), new ItemStack(RandomItems.cheese_item, 9), 0.5F);

	//Cheese Block Crafting Recipe
	GameRegistry.addRecipe(new ItemStack(RandomBlocks.cheese_block), new Object[]{"XXX", "XXX", "XXX", 'X', RandomItems.cheese_item});

	//Light Stone Bricks Crafting Recipe
	GameRegistry.addShapelessRecipe(new ItemStack(RandomBlocks.stonebrick_light, 1), new Object[]{new ItemStack(Items.dye, 1, 15), Blocks.stonebrick});

	//Dark Stone Bricks Crafting Recipe
	GameRegistry.addShapelessRecipe(new ItemStack(RandomBlocks.stonebrick_dark, 1), new Object[]{new ItemStack(Items.coal, 1, 1), Blocks.stonebrick});
	GameRegistry.addShapelessRecipe(new ItemStack(RandomBlocks.stonebrick_dark, 1), new Object[]{new ItemStack(Items.coal), Blocks.stonebrick});

	//Light Stone Brick Stairs Crafting Recipe
	GameRegistry.addRecipe(new ItemStack(RandomBlocks.stonebrick_light_stairs), new Object[]{"X  ", "XX ", "XXX", 'X', RandomBlocks.stonebrick_light});
	GameRegistry.addRecipe(new ItemStack(RandomBlocks.stonebrick_light_stairs), new Object[]{"XXX", " XX", "  X", 'X', RandomBlocks.stonebrick_light});

}

@EventHandler
public void postInit(FMLPostInitializationEvent event)
{

}
}

Posted

stonebrick_light_stairs.json

{
    "parent": "rm:block/stonebrick_light_stairs",
    "display": {
        "thirdperson": {
            "rotation": [ 10, -45, 170 ],
            "translation": [ 0, 1.5, -2.75 ],
            "scale": [ 0.375, 0.375, 0.375 ]
        },
        "gui": {
            "rotation": [ 0, 180, 0 ]
        }
    }
}

Posted

I think the problem is that in

 

RandomBlocks

package com.kansastoyou.mod.init;

import com.kansastoyou.mod.RandomMod;
import com.kansastoyou.mod.Reference;
import com.kansastoyou.mod.blocks.BlockCheese;
import com.kansastoyou.mod.blocks.BlockStonebrickLight;
import com.kansastoyou.mod.blocks.BlockStonebrickLightStairs;
import com.kansastoyou.mod.blocks.BlockStonebrickDark;

import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class RandomBlocks {

//Cheese Block
public static Block cheese_block;

//Light Stonebrick
public static Block stonebrick_light;

//Dark Stonebrick
public static Block stonebrick_dark;

//Light Stonebrick Stairs

public static BlockStairs stonebrick_light_stairs;


public static void init()
{
	cheese_block = new BlockCheese(Material.sponge).setUnlocalizedName("cheese_block").setCreativeTab(RandomMod.tabRandom);
	stonebrick_light = new BlockStonebrickLight(Material.rock).setUnlocalizedName("stonebrick_light").setCreativeTab(RandomMod.tabRandom);;
	stonebrick_dark = new BlockStonebrickDark(Material.rock).setUnlocalizedName("stonebrick_dark").setCreativeTab(RandomMod.tabRandom);;	
	stonebrick_light_stairs = new BlockStonebrickLightStairs(Material.rock, "stonebrick_light_stairs", 3.0F, 5.0F, RandomMod.tabRandom, BlockStonebrickLightStairs.HarvestToolEnum.PICKAXE, BlockStonebrickLightStairs.HarvestLevelEnum.STONE);

}

public static void register()
{
	GameRegistry.registerBlock(cheese_block, cheese_block.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(stonebrick_light, stonebrick_light.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(stonebrick_dark, stonebrick_dark.getUnlocalizedName().substring(5));		

}	

public static void registerRenders()
{
	registerRender(cheese_block);
	registerRender(stonebrick_light);
	registerRender(stonebrick_dark);

}

public static void registerRender(Block block)
{
	Item item = Item.getItemFromBlock(block);
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));		
}
}

 

I didn't register the stairs in public static void register() or public static void registerRenders(), but every time I try to, my game crashes.

Here's what It looks like when I add it to those two locations.

 

package com.kansastoyou.mod.init;

import com.kansastoyou.mod.RandomMod;
import com.kansastoyou.mod.Reference;
import com.kansastoyou.mod.blocks.BlockCheese;
import com.kansastoyou.mod.blocks.BlockStonebrickLight;
import com.kansastoyou.mod.blocks.BlockStonebrickLightStairs;
import com.kansastoyou.mod.blocks.BlockStonebrickDark;

import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class RandomBlocks {

//Cheese Block
public static Block cheese_block;

//Light Stonebrick
public static Block stonebrick_light;

//Dark Stonebrick
public static Block stonebrick_dark;

//Light Stonebrick Stairs

public static BlockStairs stonebrick_light_stairs;


public static void init()
{
	cheese_block = new BlockCheese(Material.sponge).setUnlocalizedName("cheese_block").setCreativeTab(RandomMod.tabRandom);
	stonebrick_light = new BlockStonebrickLight(Material.rock).setUnlocalizedName("stonebrick_light").setCreativeTab(RandomMod.tabRandom);;
	stonebrick_dark = new BlockStonebrickDark(Material.rock).setUnlocalizedName("stonebrick_dark").setCreativeTab(RandomMod.tabRandom);;	
	stonebrick_light_stairs = new BlockStonebrickLightStairs(Material.rock, "stonebrick_light_stairs", 3.0F, 5.0F, RandomMod.tabRandom, BlockStonebrickLightStairs.HarvestToolEnum.PICKAXE, BlockStonebrickLightStairs.HarvestLevelEnum.STONE);

}

public static void register()
{
	GameRegistry.registerBlock(cheese_block, cheese_block.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(stonebrick_light, stonebrick_light.getUnlocalizedName().substring(5));
	GameRegistry.registerBlock(stonebrick_dark, stonebrick_dark.getUnlocalizedName().substring(5));	
                GameRegistry.registerBlock(stonebrick_light_stairs, stonebrick_light_stairs.getUnlocalizedName().substring(5));	

}	

public static void registerRenders()
{
	registerRender(cheese_block);
	registerRender(stonebrick_light);
	registerRender(stonebrick_dark);
                registerRender(stonebrick_light_stairs);

}

public static void registerRender(Block block)
{
	Item item = Item.getItemFromBlock(block);
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));		
}
}

 

And here's the crash report:

 

---- Minecraft Crash Report ----
// I'm sorry, Dave.

Time: 7/13/15 9:03 PM
Description: There was a severe problem during mod loading that has caused the game to fail

net.minecraftforge.fml.common.LoaderException: java.lang.IllegalStateException: Can't free registry slot 198 occupied by net.minecraft.item.ItemBlock@43945480
at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:231)
at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:188)
at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:177)
at com.kansastoyou.mod.init.RandomBlocks.register(RandomBlocks.java:48)
at com.kansastoyou.mod.RandomMod.preInit(RandomMod.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:212)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
at com.google.common.eventbus.EventBus.post(EventBus.java:275)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:119)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:550)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:249)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:446)
at net.minecraft.client.Minecraft.run(Minecraft.java:356)
at net.minecraft.client.main.Main.main(Main.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)
Caused by: java.lang.IllegalStateException: Can't free registry slot 198 occupied by net.minecraft.item.ItemBlock@43945480
at net.minecraftforge.fml.common.registry.GameData.freeSlot(GameData.java:876)
at net.minecraftforge.fml.common.registry.GameData.registerItem(GameData.java:776)
at net.minecraftforge.fml.common.registry.GameData.registerItem(GameData.java:745)
at net.minecraftforge.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:223)
... 43 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_05, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 877193408 bytes (836 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.10 FML v8.0.99.99 Minecraft Forge 11.14.3.1487 4 mods loaded, 4 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCH	mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) 
UCH	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1487.jar) 
UCH	Forge{11.14.3.1487} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1487.jar) 
UCE	rm{1.0} [Random Mod] (bin) 
Loaded coremods (and transformers): 
GL info: ' Vendor: 'ATI Technologies Inc.' Version: '4.3.12618 Compatibility Profile Context 13.251.9001.1001' Renderer: 'AMD Radeon HD 7400M Series'

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I know that this may be a basic question, but I am very new to modding. I am trying to have it so that I can create modified Vanilla loot tables that use a custom enchantment as a condition (i.e. enchantment present = item). However, I am having trouble trying to implement this; the LootItemRandomChanceWithEnchantedBonusCondition constructor needs a Holder<Enchantment> and I am unable to use the getOrThrow() method on the custom enchantment declared in my mod's enchantments class. Here is what I have so far in the GLM:   protected void start(HolderLookup.Provider registries) { HolderLookup.RegistryLookup<Enchantment> registrylookup = registries.lookupOrThrow(Registries.ENCHANTMENT); LootItemRandomChanceWithEnchantedBonusCondition lootItemRandomChanceWithEnchantedBonusCondition = new LootItemRandomChanceWithEnchantedBonusCondition(0.0f, LevelBasedValue.perLevel(0.07f), registrylookup.getOrThrow(*enchantment here*)); this.add("nebu_from_deepslate", new AddItemModifier(new LootItemCondition[]{ LootItemBlockStatePropertyCondition.hasBlockStateProperties(Blocks.DEEPSLATE).build(), LootItemRandomChanceCondition.randomChance(0.25f).build(), lootItemRandomChanceWithEnchantedBonusCondition }, OrichalcumItems.NEBU.get())); }   Inserting Enchantments.[vanilla enchantment here] actually works but trying to declare an enchantment from my custom enchantments class as [mod enchantment class].[custom enchantment] does not work even though they are both a ResourceKey and are registered in Registries.ENCHANTMENT. Basically, how would I go about making it so that a custom enchantment declared as a ResourceKey<Enchantment> of value ResourceKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath([modid], [name])), declared in a seperate enchantments class, can be used in the LootItemRandomChanceWithEnchantedBonusCondition constructor as a Holder? I can't use getOrThrow() because there is no level or block entity/entity in the start() method and it is running as datagen. It's driving me nuts.
    • Hi here is an update. I was able to fix the code so my mod does not crash Minecraft. Please understand that I am new to modding but I honestly am having a hard time understanding how anyone can get this to work without having extensive programming and debugging experience as well as searching across the Internet, multiple gen AI bots (claude, grok, openai), and examining source code hidden in the gradle directory and in various github repositories. I guess I am wrong because clearly there are thousands of mods so maybe I am just a newbie. Ok, rant over, here is a step by step summary so others can save the 3 days it took me to figure this out.   1. First, I am using forge 54.1.0 and Minecraft 1.21.4 2. I am creating a mod to add a shotgun to Minecraft 3. After creating the mod and compiling it, I installed the .jar file to the proper directory in Minecraft and used 1.21.4-forge-54.1.0 4. The mod immediately crashed with the error: Caused by: java.lang.NullPointerException: Item id not set 5. Using the stack trace, I determined that the Exception was being thrown from the net.minecraft.world.item.Item.Properties class 6. It seems that there are no javadocs for this class, so I used IntelliJ which was able to provide a decompiled version of the class, which I then examined to see the source of the error. Side question: Are there javadocs? 7. This method, specifically, was the culprit: protected String effectiveDescriptionId() {      return this.descriptionId.get(Objects.requireNonNull(this.id, "Item id not set"));  } 8. Now my quest was to determine how to set this.id. Looking at the same source file, I determined there was another method:  public Item.Properties setId(ResourceKey<Item> pId) {             this.id = pId;             return this;   } 9. So now, I need to figure out how to call setId(). This required working backwards a bit. Starting from the constructor, I stubbed out the variable p which is of type Item.Properties public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); Rather than putting this all on one line, I split it up for readability like this: private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); Here is was the missing function, setId(), which takes a type of ResourceKey<Item>. My next problem is that due to the apparent lack of documentation (I tried searching the docs on this site) I could not determine the full import path to ResourceKey. I did some random searching on the Internet and stumbled across a Github repository which gave two clues: import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; Then I created the rk variable like this: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); And now putting it all together in order: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); This compiled and the mod no longer crashes. I still have more to do on it, but hopefully this will save someone hours. I welcome any feedback and if I missed some obvious modding resource or tutorial that has this information. If not, I might suggest we add it somewhere for people trying to write a mod that doesn't crash. Thank you !!!  
    • I will keep adding to this thread with more information in case anyone can help, or at the very least I can keep my troubleshooting organized. I decided to downgrade to 54.1.0 in the hopes that this would fix the issue but it didn't. At least now I am on a "recommended" version. The crash report did confirm my earlier post that the Exception is coming from effectiveDescriptionId(). I'll continue to see if I can find a way to set the ID manually.   Caused by: java.lang.NullPointerException: Item id not set         at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item$Properties.effectiveDescriptionId(Item.java:465) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item.<init>(Item.java:111) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ShotgunItem.<init>(ShotgunItem.java:19) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ModItems.lambda$static$0(ModItems.java:15) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.lambda$handleEvent      
    • It just randomly stop working after a rebooted my dedicated server PLEASE HELP!   com.google.gson   Failed to start the minecraft server com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $  
  • Topics

×
×
  • Create New...

Important Information

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