Jump to content

  • Curse Sites
Become a Premium Member! Help
Latest News Article

Override original block ?


  • Please log in to reply
6 replies to this topic

#1

XTRiZ
    XTRiZ

    Tree Puncher

  • Members
  • 12 posts

Posted 09 August 2011 - 03:37 PM

Hi,

i'm absolutely new to this modding thingie. But i do know a bit about programming..

Is it possible to override the normal dirt block in minecraft using mod_loader ?

if so, can you give me a hint ?

for example change texture and behavior to it ?

.x

Register or log in to remove.

#2

Calandiat
  • Location: Switzerland

Posted 09 August 2011 - 03:50 PM

View PostXTRiZ, on 09 August 2011 - 03:37 PM, said:

Hi,

i'm absolutely new to this modding thingie. But i do know a bit about programming..

Is it possible to override the normal dirt block in minecraft using mod_loader ?

if so, can you give me a hint ?

for example change texture and behavior to it ?

.x
Yes it is.
make a new mod and add this to the constructor to change the texture:
Block.dirt.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/yourTexture.png");
Your texture must be a png and it must be in minecraft.jar
This will only work for blocks that use the same texture for all sides.

To change the behavior you have to edit BlockDirt.java

#3

XTRiZ
    XTRiZ

    Tree Puncher

  • Members
  • 12 posts

Posted 09 August 2011 - 04:05 PM

View PostCalandiat, on 09 August 2011 - 03:50 PM, said:

Yes it is.
make a new mod and add this to the constructor to change the texture:
Block.dirt.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/yourTexture.png");
Your texture must be a png and it must be in minecraft.jar
This will only work for blocks that use the same texture for all sides.

To change the behavior you have to edit BlockDirt.java

So it's not possible to override the entire dirtblock then ?

How about just replacing the block like this.
 Block.dirt = new MyDirtBlock(......);

Then i'm replacing the instance with my own. Just me spinning around the subject.. i'll better test it instead.. Thanks anyway.

.x

#4

XTRiZ
    XTRiZ

    Tree Puncher

  • Members
  • 12 posts

Posted 09 August 2011 - 04:18 PM

View PostXTRiZ, on 09 August 2011 - 04:05 PM, said:

So it's not possible to override the entire dirtblock then ?

How about just replacing the block like this.
 Block.dirt = new MyDirtBlock(......);

Then i'm replacing the instance with my own. Just me spinning around the subject.. i'll better test it instead.. Thanks anyway.

.x

It's marked final.....
I'll drop that way..

.x

#5

Proloe
    Proloe

    Glowstone Miner

  • Members
  • 3239 posts
  • Location: UK
  • Minecraft: Proloe

Posted 09 August 2011 - 04:49 PM

No, you can do it.

I did it for my Steamcraft mod, though it's a little more complex than just saying:

Block dirt = new BlockNewDirt();

Here is how to do it, though I'm not sure all of it is necessary. Best stay on the safe side:

First, you have to remove the block from the list of blocks, which is set at the bottom of Block.java:

Block.blocksList[Block.dirt.blockID] = null;

This effectively removes the dirt block from the game.

Next, you need to define a new block:

Block dirt = new BlockNewDirt(Block.dirt.blockID, ModLoader.addOverride("/terrain.png", "newdirt.png")).setHardness(0.5F).setStepSound(Block.soundGravelFootstep).setBlockName("dirt");

This creates a new block within your mod_x file. It is not, as of yet, used.

Because Minecraft treats blocks as a form of item in some respects (such as inventory usage), you have to remove it from the list of items, too:

Item.itemsList[Block.dirt.blockID] = null;

Now dirt is well and truly ignored, and now you've more or less done it. All you have to do now is put your block back where the dirt block was:

Item.itemsList[Block.dirt.blockID] = new ItemBlock(Block.dirt.blockID - 256);

Because you gave your block dirts original ID, you essentially overwrite it in this stage, slotting your block in where the original dirt block was. You can do anything you like with it here, including changing the display name. The best part is that any references to dirt in the rest of the code will now apply to your new block, and this includes world generation!

If you have any more questions, don't hesitate to ask.

Posted Image


#6

XTRiZ
    XTRiZ

    Tree Puncher

  • Members
  • 12 posts

Posted 09 August 2011 - 05:14 PM

View PostProloe, on 09 August 2011 - 04:49 PM, said:

No, you can do it.

I did it for my Steamcraft mod, though it's a little more complex than just saying:

Block dirt = new BlockNewDirt();

Here is how to do it, though I'm not sure all of it is necessary. Best stay on the safe side:

First, you have to remove the block from the list of blocks, which is set at the bottom of Block.java:

Block.blocksList[Block.dirt.blockID] = null;

This effectively removes the dirt block from the game.

Next, you need to define a new block:

Block dirt = new BlockNewDirt(Block.dirt.blockID, ModLoader.addOverride("/terrain.png", "newdirt.png")).setHardness(0.5F).setStepSound(Block.soundGravelFootstep).setBlockName("dirt");

This creates a new block within your mod_x file. It is not, as of yet, used.

Because Minecraft treats blocks as a form of item in some respects (such as inventory usage), you have to remove it from the list of items, too:

Item.itemsList[Block.dirt.blockID] = null;

Now dirt is well and truly ignored, and now you've more or less done it. All you have to do now is put your block back where the dirt block was:

Item.itemsList[Block.dirt.blockID] = new ItemBlock(Block.dirt.blockID - 256);

Because you gave your block dirts original ID, you essentially overwrite it in this stage, slotting your block in where the original dirt block was. You can do anything you like with it here, including changing the display name. The best part is that any references to dirt in the rest of the code will now apply to your new block, and this includes world generation!

If you have any more questions, don't hesitate to ask.


You're never using the following code anywhere.
Block dirt = new BlockNewDirt(Block.dirt.blockID, ModLoader.addOverride("/terrain.png", "newdirt.png")).setHardness(0.5F).setStepSound(Block.soundGravelFootstep).setBlockName("dirt");

Should it be like that ? Shouldn't i put it in the blocklist ?

.x

#7

Proloe
    Proloe

    Glowstone Miner

  • Members
  • 3239 posts
  • Location: UK
  • Minecraft: Proloe

Posted 09 August 2011 - 05:17 PM

That piece of code simply reassigns the ID value for the dirt, so that you can mess around with light values and such to your hearts content. As far as my code goes, I don't think I ever reassigned the blocklist values, I believe the only point at which Minecraft uses it is when putting it into the itemlist, so it's all good.

Posted Image