Jump to content

Recommended Posts

Posted

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

  • 2 weeks later...
Posted

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

 

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

    • logs too big for one pastebin https://pastebin.com/ZjUGHu3u  https://pastebin.com/RqCUZf3X  https://pastebin.com/6ZPS99nD
    • You probably used jd-gui to open it, didn't you? Nothing wrong with that, I also made that mistake, except that Notch was a smart guy and he obfuscated the code. That's why you only see files called "a", "b", "c" and then a file that combines them all. As I said, use RetroMCP to deobfuscate the code so that you will 100% understand it and be able to navigate it.
    • Decompiling minecraft indev, infdev, alpha, beta or whichever legacy version is really easy. I'm not a plug, I just also got interested in modding legacy versions (Infdev to be specific). Use https://github.com/MCPHackers/RetroMCP-Java Once you install their client and the Zulu Architecture that they say they recommend (or use your own Java). I encountered some problems, so I run it with: "java -jar RetroMCP-Java-CLI.jar". You should run it in a seperate folder (not in downloads), otherwise the files and folders will go all over the place. How to use RetroMCP: Type setup (every time you want change version), copy-paste the version number from their list (they support indev), write "decompile" and done! The code will now be deobfuscated and filenames will be normal, instead of "a", "b" and "c"! Hope I helped you, but I don't expect you to reply, as this discussion is 9 years old! What a piece of history!  
    • 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.
  • Topics

×
×
  • Create New...

Important Information

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