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-
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
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:
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
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);
}
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;
}
}
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 |
tools/tracking
944667
6
modding-tutorial-7-advanced-blocks
Create an account or sign in to comment.