Minecraft Blogs / Tutorial

modding tutorial #7: advanced blocks

  • 4,359 views, 3 today
  • 4
  • 2
  • 12
waterskier's Avatar waterskier
Level 54 : Grandmaster Pony
158
hey everyone! This will be my last pmc tutorial. If you want more I am going to remake the series on youtube, then start making more, so my next blog will just be giving you a link to my youtube page.

REQUIRES AN ALREADY MADE BLOCK, IF YOU DON't KNOW HOW GO HERE:

this tutorial will cover many ways to make your block more advanced:
jump when touching block
block hurting you
multi texture
stairs
half slab
making block transparent (like glass)
making a custom flower
making it slippery

jump when touching block:
for this we need to put this code-
jump

public void onEntityWalking(World world, int x, int y, int z, Entity entity)
{
entity.motionY += 2.0;
}
in the class where your block is, under the
public int idDropped(int i, Random random)
{
return mod_Namehere.Namehere.blockID;
}


slippery:
for this we need to edit your block class again
we need to change
slippery

public BlockNamehere(int i, int j)
{
super(i, j, Material.ground);
}
to
public BlockNamehere(int i, int j)
{
super(i, j, Material.ground);
slipperiness = 1.5F;
}



transparency:
Click to reveal

for this all you need to do is add-
public boolean isOpaqueCube()
{
return false;
}
under-
public BlockName(int i, int j)
{
super(i, j, Material.wood);
}
in your blocks class

half slab/stairs:
this one is a little more complicated, so if you want to know how it works post a comment
stair

all you need to do is put
public void getCollidingBoundingBoxes(World world, int i, int j, int k, AxisAlignedBB axisalignedbb, ArrayList arraylist)
{
int l = world.getBlockMetadata(i, j, k);
if (l == 0)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 0.5F, 1.0F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
}
else if (l == 1)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
}
else if (l == 2)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 0.5F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
setBlockBounds(0.0F, 0.0F, 0.5F, 1.0F, 1.0F, 1.0F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
}
else if (l == 3)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
setBlockBounds(0.0F, 0.0F, 0.5F, 1.0F, 0.5F, 1.0F);
super.getCollidingBoundingBoxes(world, i, j, k, axisalignedbb, arraylist);
}
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving)
{
int l = MathHelper.floor_double((double)((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (l == 0)
{
world.setBlockMetadataWithNotify(i, j, k, 2);
}
if (l == 1)
{
world.setBlockMetadataWithNotify(i, j, k, 1);
}
if (l == 2)
{
world.setBlockMetadataWithNotify(i, j, k, 3);
}
if (l == 3)
{
world.setBlockMetadataWithNotify(i, j, k, 0);
}
}


public void setBlockBoundsBasedOnState(IBlockAccess iblockaccess, int i, int j, int k)
{
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
public boolean isOpaqueCube()
{
return false;
}

public boolean renderAsNormalBlock()
{
return false;
}

public int getRenderType()
{
return 10;
}
under

public BlockYourBlock(int i, int j)
{
super(i, j, Material.wood);
}


slab

change
protected BlockNamehereSlab(int i, int j)
{
super(i, j, Material.wood);

}
to

protected BlockNamehereSlab(int i, int j)
{
super(i, j, Material.wood);
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
setLightOpacity(255);
}
then under that add

public boolean isOpaqueCube()
{
return false;
}

public int idDropped(int i, Random random, int j)
{
return mod_Slab.Namehere.blockID;
}

public int quantityDropped(Random random)
{
return 1;
}

public boolean renderAsNormalBlock()
{
return false;
}

public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
if (this != Block.stairSingle)
{
super.shouldSideBeRendered(iblockaccess, i, j, k, l);
}
if (l == 1)
{
return true;
}
if (!super.shouldSideBeRendered(iblockaccess, i, j, k, l))
{
return false;
}
if (l == 0)
{
return true;
}
else
{
return iblockaccess.getBlockId(i, j, k) != blockID;
}
}
Tags

Create an account or sign in to comment.

1
06/20/2012 12:10 pm
Level 45 : Master Lava Rider
BurningSkullz99
BurningSkullz99's Avatar
Thanks But im not just a good coder but if you could send me a link to zkmodcrafter working download that would make me as happy as a Narwhal!!!!And gain a sub
1
06/11/2012 1:25 pm
Level 1 : New Explorer
Metriximor
Metriximor's Avatar
Good!
1
06/02/2012 5:14 am
Level 12 : Journeyman Bunny
iCraftedYou
iCraftedYou's Avatar
how do you apply the mod to the game?
1
06/02/2012 5:21 am
Level 54 : Grandmaster Pony
waterskier
waterskier's Avatar
when you are done, press save in eclipse. After that you can exit. After that go into mcp, the hit recompile, wait, hit reobfuscate, wait, go to the reobf folder, then minecraft then you should have your class file(s) there.
1
06/02/2012 7:04 am
Level 12 : Journeyman Bunny
iCraftedYou
iCraftedYou's Avatar
lol sorry, it did actually work :D
1
06/02/2012 7:03 am
Level 12 : Journeyman Bunny
iCraftedYou
iCraftedYou's Avatar
i get this error: Can not find server sources, try decompiling! But i decompiled already
1
06/01/2012 11:18 am
Level 67 : High Grandmaster Modder
Surseance
Surseance's Avatar
How about teaching them to make a null block (i.e. like a flower).
1
08/07/2012 5:58 pm
Level 48 : Master Taco
kiefaber123
kiefaber123's Avatar
a null blockis something you walk though (i.e. portal) not a flower.
1
08/08/2012 7:19 pm
Level 67 : High Grandmaster Modder
Surseance
Surseance's Avatar
Actually, a flower is a null block. A portal is also a null block. The line of code that removes the bounding box can be found in the flower code. Look it up.
1
08/08/2012 8:04 pm
Level 48 : Master Taco
kiefaber123
kiefaber123's Avatar
Actually, I'm so stupod, I forgot you can walk through a flower! Haha,. sorry :(
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome