Jump to content

[1.7.10] ItemBlock constructor args for custom slab?


Eternaldoom

Recommended Posts

Hi,

 

I'm trying to create a custom slab, but I can't figure out how to register the ItemBlock. I'm using the vanilla ItemSlab class as the ItemBlock. How do you pass arguments to the ItemBlock's constructor? Here's what I have so far:

 

public BlockROCSlab register(String name){
	if(isDouble) GameRegistry.registerBlock(this, ItemSlab.class, name, new Object[]{ROCBlocks.netherrack_brick_slab_double, ROCBlocks.netherrack_brick_slab, ROCBlocks.netherrack_brick_slab_double, true});
	else GameRegistry.registerBlock(this, ItemSlab.class, name, new Object[]{ROCBlocks.netherrack_brick_slab, ROCBlocks.netherrack_brick_slab, ROCBlocks.netherrack_brick_slab_double, false});

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

BlockSlab class:

public class BlockROCSlab extends BlockSlab{
private Block materialBlock;
private boolean isDouble;
public BlockROCSlab(boolean isDouble, Block b, float hard, float resist, String name) {
	super(isDouble, b.getMaterial());
	this.materialBlock = b;
	setBlockName(name);
	setHardness(hard);
	setResistance(resist);
	this.isDouble = isDouble;
}

@Override
public String func_150002_b(int p_150002_1_) {
	return this.getUnlocalizedName();
}

@Override
@SideOnly(Side.CLIENT)
    public IIcon getIcon(int p_149691_1_, int p_149691_2_)
    {
        return this.materialBlock.getIcon(p_149691_1_, 0);
    }

public BlockROCSlab register(String name){
	if(isDouble) GameRegistry.registerBlock(this, ItemBlockModSlab.class, name, new Object[]{ROCBlocks.netherrack_brick_slab_double, ROCBlocks.netherrack_brick_slab, ROCBlocks.netherrack_brick_slab_double, true});
	else GameRegistry.registerBlock(this, ItemBlockModSlab.class, name, new Object[]{ROCBlocks.netherrack_brick_slab, ROCBlocks.netherrack_brick_slab, ROCBlocks.netherrack_brick_slab_double, false});
	return this;
}
}

 

I will change the register function to have block parameters once I can get the slab working.

 

Blocks class (The relevant parts):

public static BlockROCSlab netherrack_brick_slab;
public static BlockROCSlab netherrack_brick_slab_double;
netherrack_brick_slab = new BlockROCSlab(false, netherrack_bricks, 0.4f, 1.0f, "slabHellrockBrick").register("netherrack_brick_slab");
netherrack_brick_slab_double = new BlockROCSlab(true, netherrack_bricks, 0.4f, 1.0f, "slabHellrockBrick").register("netherrack_brick_slab_double");

 

The ItemBlock:

public class ItemBlockModSlab extends ItemSlab{

public ItemBlockModSlab(BlockROCSlab p_i45355_1_, BlockROCSlab p_i45355_2_,
		BlockROCSlab p_i45355_3_, boolean p_i45355_4_) {
	super(p_i45355_1_, p_i45355_2_, p_i45355_3_, p_i45355_4_);
}
}

 

The Crash:

[07:59:26] [Client thread/ERROR] [FML]: Caught an exception during block registration
java.lang.NullPointerException
at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:206) [GameRegistry.class:?]
at com.eternaldoom.realmsofchaos.blocks.BlockROCSlab.register(BlockROCSlab.java:39) [blockROCSlab.class:?]
at com.eternaldoom.realmsofchaos.blocks.ROCBlocks.init(ROCBlocks.java:90) [ROCBlocks.class:?]
at com.eternaldoom.realmsofchaos.RealmsOfChaos.preInit(RealmsOfChaos.java:65) [RealmsOfChaos.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) [FMLModContainer.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) [LoadController.class:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) [LoadController.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) [guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) [guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) [guava-17.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513) [Loader.class:?]
at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:532) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:941) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
[07:59:26] [Client thread/INFO] [FML]: Applying holder lookups
[07:59:26] [Client thread/INFO] [FML]: Holder lookups applied
[07:59:26] [Client thread/ERROR] [FML]: Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue
[07:59:26] [Client thread/ERROR] [FML]: 
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized
FML{7.10.25.1199} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1199.jar) Unloaded->Constructed->Pre-initialized
Forge{10.13.0.1199} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1199.jar) Unloaded->Constructed->Pre-initialized
realmsofchaos{Alpha 1.0 pre 1} [Realms of Chaos] (bin) Unloaded->Constructed->Errored
[07:59:26] [Client thread/ERROR] [FML]: The following problems were captured during this phase
[07:59:26] [Client thread/ERROR] [FML]: Caught exception from realmsofchaos
cpw.mods.fml.common.LoaderException: java.lang.NullPointerException
at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:222) ~[forgeSrc-1.7.10-10.13.0.1199.jar:?]
at com.eternaldoom.realmsofchaos.blocks.BlockROCSlab.register(BlockROCSlab.java:39) ~[bin/:?]
at com.eternaldoom.realmsofchaos.blocks.ROCBlocks.init(ROCBlocks.java:90) ~[bin/:?]
at com.eternaldoom.realmsofchaos.RealmsOfChaos.preInit(RealmsOfChaos.java:65) ~[bin/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513) ~[forgeSrc-1.7.10-10.13.0.1199.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208) ~[forgeSrc-1.7.10-10.13.0.1199.jar:?]
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187) ~[forgeSrc-1.7.10-10.13.0.1199.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?]
at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?]
at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?]
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118) [LoadController.class:?]
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513) [Loader.class:?]
at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239) [FMLClientHandler.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:532) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:941) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
Caused by: java.lang.NullPointerException
at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:206) ~[forgeSrc-1.7.10-10.13.0.1199.jar:?]
... 40 more
---- Minecraft Crash Report ----
// You should try our sister game, Minceraft!

Time: 9/2/14 7:59 AM
Description: There was a severe problem during mod loading that has caused the game to fail

cpw.mods.fml.common.LoaderException: java.lang.NullPointerException
at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:222)
at com.eternaldoom.realmsofchaos.blocks.BlockROCSlab.register(BlockROCSlab.java:39)
at com.eternaldoom.realmsofchaos.blocks.ROCBlocks.init(ROCBlocks.java:90)
at com.eternaldoom.realmsofchaos.RealmsOfChaos.preInit(RealmsOfChaos.java:65)
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 cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:513)
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 cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187)
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 cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
at cpw.mods.fml.common.Loader.preinitializeMods(Loader.java:513)
at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:239)
at net.minecraft.client.Minecraft.startGame(Minecraft.java:532)
at net.minecraft.client.Minecraft.run(Minecraft.java:941)
at net.minecraft.client.main.Main.main(Main.java:164)
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:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
Caused by: java.lang.NullPointerException
at cpw.mods.fml.common.registry.GameRegistry.registerBlock(GameRegistry.java:206)
... 40 more


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

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Mac OS X (x86_64) version 10.10
Java Version: 1.8.0, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 864109552 bytes (824 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.25.1199 Minecraft Forge 10.13.0.1199 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized
FML{7.10.25.1199} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1199.jar) Unloaded->Constructed->Pre-initialized
Forge{10.13.0.1199} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1199.jar) Unloaded->Constructed->Pre-initialized
realmsofchaos{Alpha 1.0 pre 1} [Realms of Chaos] (bin) Unloaded->Constructed->Errored
#@!@# Game crashed! Crash report saved to: #@!@# /Users/Z/Desktop/ForgeModding2/eclipse/./crash-reports/crash-2014-09-02_07.59.26-client.txt

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

I fixed that, now I'm getting this error:

cpw.mods.fml.common.LoaderException: java.lang.NoSuchMethodException: com.eternaldoom.realmsofchaos.itemblock.ItemBlockModSlab.<init>(net.minecraft.block.Block, com.eternaldoom.realmsofchaos.blocks.BlockROCSlab, com.eternaldoom.realmsofchaos.blocks.BlockROCSlab, com.eternaldoom.realmsofchaos.blocks.BlockROCSlab, java.lang.Boolean)

 

I tried adding a Block to the constructor of the ItemBlock, but it still gave the same error.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

This is your problem. You have created a stalemate situation here.

netherrack_brick_slab = new BlockROCSlab(false, netherrack_bricks, 0.4f, 1.0f, "slabHellrockBrick").register("netherrack_brick_slab");
netherrack_brick_slab_double = new BlockROCSlab(true, netherrack_bricks, 0.4f, 1.0f, "slabHellrockBrick").register("netherrack_brick_slab_double");

The first block cannot be registered because if uses the second block which is not yet created. The order cannot be reversed, because the second block want the first block to be created. Both of these problems are due to adding .register(name) at the end. The register functions need both blocks already created you they use the value 'null'.

Link to comment
Share on other sites

I already fixed the .register() error. The problem with the constructor arguments is that forge seems to think that there is a Block argument at the beginning, but it does not exist. I have no idea what argument to use in registerBlock as the Block argument, since they all have to be the exact classes.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

I can't find what's wrong with the constructor. It is now:

public ItemBlockModSlab(Block p_i45355_1_, BlockROCSlab p_i45355_2_, BlockROCSlab p_i45355_3_, boolean p_i45355_4_)

and the registerBlock args are:

ROCBlocks.netherrack_brick_slab, ROCBlocks.netherrack_brick_slab_double, true

for the double slab.

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

fixed it. the b in boolean had to be capitalized.

Yes, because boolean is a primitive type and Boolean is a class type wrapper. The ItemBlock is always assumed to only accept classes objects. int can also be wrapped with Integer; Boolean etc. are also possible.

Sorry, I didn't notice the problem sooner.

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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