Jump to content

[1.8] extend Stair Block code


Zenim

Recommended Posts

Is there any kind souls out there that could show me how to extend the Stair Block class.

 

I have tried to follow minecraft modding stairs tutorial [1.8] Stairs by localtoast9001 but it will not work for me.

I have even looked at his complete source to try and work it out but due to the complexity of his mod I getting lost.

It's pretty awesome of him to put is hole mod source up there as its help me in other parts of my mod.

 

I don't need to now how to do the Json file and block state just how to get the class to extend and add the Material, HarvestToolEnum etc.

 

 

Edit

This is where i am up to

 

Code public class CustomStairs extends BlockStairs

 

I am not sure about "private static Block block;" but eclipse wanted to add it as " super(block.getStateFromMeta(0));" Block was alway in error.

 

 

 

package com.zenim.zenmod;

 

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.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;

 

public class CustomStairs extends BlockStairs {

 

 

private static Block block;

private Item dropsOnHarvest;

private int dropamountmax = 1;

private int maxharvestEXP = 0;

   

    public CustomStairs(Material material, String name, float hardness, float resistance, CreativeTabs creativetab, HarvestToolEnum harvesttool, HarvestLevelEnum harvestlevel)

    {

        super(block.getStateFromMeta(0));   

 

            this.setUnlocalizedName(name);

    this.setHardness(hardness);

    this.setResistance(resistance);

    this.setStepSound(soundTypePiston);

    this.setCreativeTab(creativetab);

   

   

   

    GameRegistry.registerBlock(this, name);

   

    this.dropsOnHarvest = Item.getItemFromBlock(this);

   

    }

    private void setBlock() {

// TODO Auto-generated method stub

 

}

public void RegisterRenderer(String modelName)

{

System.out.println("REGISTERING BLOCK RENDERER: " + modelName);

 

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(this), 0, new ModelResourceLocation(Main.MODID+":"+modelName, "inventory"));

}

 

public 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;

    }

}

 

 

 

 

 

 

Code 'public class CommonProxy'

 

 

 

package com.zenim.zenmod;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.block.state.IBlockState;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

 

public class CommonProxy

{

 

public void preInit(FMLPreInitializationEvent e)

{

 

 

}

public void init(FMLInitializationEvent e)

{

Main.mossystonebrick = new CustomStairs(Material.rock, "mossystonebrick", 3.0F, 5.0F, CreativeTabs.tabBlock, CustomStairs.HarvestToolEnum.PICKAXE, CustomStairs.HarvestLevelEnum.STONE);

}

public void postInit(FMLPostInitializationEvent e)

{

 

}

 

}

 

 

 

 

Crash Report

 

 

 

---- Minecraft Crash Report ----

// This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]

 

Time: 25/06/15 12:03 AM

Description: Initializing game

 

java.lang.NullPointerException: Initializing game

at com.zenim.zenmod.CustomStairs.<init>(CustomStairs.java:29)

at com.zenim.zenmod.CommonProxy.init(CommonProxy.java:27)

at com.zenim.zenmod.ClientProxy.init(ClientProxy.java:18)

at com.zenim.zenmod.Main.init(Main.java:47)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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.initializeMods(Loader.java:710)

at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:315)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:528)

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(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.zenim.zenmod.CustomStairs.<init>(CustomStairs.java:29)

at com.zenim.zenmod.CommonProxy.init(CommonProxy.java:27)

at com.zenim.zenmod.ClientProxy.init(ClientProxy.java:18)

at com.zenim.zenmod.Main.init(Main.java:47)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:537)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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.initializeMods(Loader.java:710)

at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:315)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:528)

 

-- Initialization --

Details:

Stacktrace:

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(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

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)

 

-- System Details --

Details:

Minecraft Version: 1.8

Operating System: Windows 8.1 (amd64) version 6.3

Java Version: 1.8.0_45, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 724750384 bytes (691 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 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.1446 4 mods loaded, 4 mods active

mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized

FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.8-11.14.3.1446.jar) Unloaded->Constructed->Pre-initialized->Initialized

Forge{11.14.3.1446} [Minecraft Forge] (forgeSrc-1.8-11.14.3.1446.jar) Unloaded->Constructed->Pre-initialized->Initialized

zenmod{1.0} [zenmod] (bin) Unloaded->Constructed->Pre-initialized->Errored

Loaded coremods (and transformers):

GL info: ' Vendor: 'Intel' Version: '4.2.0 - Build 10.18.10.3496' Renderer: 'Intel® HD Graphics 4600'

Launched Version: 1.8

LWJGL: 2.9.1

OpenGL: Intel® HD Graphics 4600 GL version 4.2.0 - Build 10.18.10.3496, Intel

GL Caps: Using GL 1.3 multitexturing.

Using GL 1.3 texture combiners.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Shaders are available because OpenGL 2.1 is supported.

VBOs are available because OpenGL 1.5 is supported.

 

Using VBOs: No

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: English (US)

Profiler Position: N/A (disabled)

 

 

 

 

 

I Would appreciate any help.

Thanks

Zen

Link to comment
Share on other sites

  • 2 weeks later...

I worked it out in the end, so the code for my class is,

 

 

 

package com.zenim.zenmod.stairsandroofing;

 

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.zenim.zenmod.Main;

import com.zenim.zenmod.stairsandroofing.CustomRoofing.HarvestLevelEnum;

import com.zenim.zenmod.stairsandroofing.CustomRoofing.HarvestToolEnum;

 

 

public class CustomStairs extends BlockStairs {

 

 

   

private Item dropsOnHarvest;

private int dropamountmax = 1;

private int maxharvestEXP = 0;

 

   

 

    public CustomStairs(Material material, String name, float hardness, float resistance, CreativeTabs creativetab, HarvestToolEnum harvesttool, HarvestLevelEnum harvestlevel)

    {

        super(Blocks.oak_stairs.getStateFromMeta(0));

             

        this.setUnlocalizedName(name);

this.setHardness(hardness);

this.setResistance(resistance);

this.setStepSound(soundTypePiston);

this.setCreativeTab(Main.zentab);

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(Main.MODID+":"+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 have been following Kevin M on YouTube awesome tutorials  https://www.youtube.com/channel/UCCLUr3vEPjmjn818HMyJEwg

 

Zen

 

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.