mod_Stairs
- package net.minecraft.src;
- public class mod_Stairs extends BaseMod
- {
- public static final Block nameHere= new BlockNameHereStairs(170, 0).setBlockName("stairsNameHere").setHardness(3F).setResistance(4F);
-
- public void load()
- {
- nameHere.blockIndexInTexture = ModLoader.addOverride("/terrain.png", "/imageblock.png");
- ModLoader.registerBlock(nameHere);
- ModLoader.addName(nameHere, "In-Game Name Here");
- ModLoader.addRecipe(new ItemStack(nameHere, 1), new Object [] {"# ", "## ", "###", Character.valueOf('#'), Block.dirt});
- }
- public String getVersion()
- {
- return "1.4.2";
- }
- }
复制代码
BlockNamehereStairs
- package net.minecraft.src;
- import java.util.List;
- import java.util.Random;
- public class BlockNameHereStairs extends Block
- {
- private static final int[][] field_72159_a = new int[][] {{2, 6}, {3, 7}, {2, 3}, {6, 7}, {0, 4}, {1, 5}, {0, 1}, {4, 5}};
- private boolean field_72156_cr = false;
- private int field_72160_cs = 0;
- protected BlockNameHereStairs(int i, int j)
- {
- super(i, j, Material.rock);
- this.setLightOpacity(255);
- this.setCreativeTab(CreativeTabs.tabBlock);
- }
- /**
- * 根据block的当前状态来更新block的边界参数:world,x,y,z
- */
- public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
- {
- if (this.field_72156_cr)
- {
- this.setBlockBounds(0.5F * (float)(this.field_72160_cs % 2), 0.5F * (float)(this.field_72160_cs / 2 % 2), 0.5F * (float)(this.field_72160_cs / 4 % 2), 0.5F + 0.5F * (float)(this.field_72160_cs % 2), 0.5F + 0.5F * (float)(this.field_72160_cs / 2 % 2), 0.5F + 0.5F * (float)(this.field_72160_cs / 4 % 2));
- }
- else
- {
- this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
- }
- }
- /**
- * 这是否是不透明方块,是否为完全填满一格空间的方块?这觉得对这个方块的渲染方式以及玩家是否可以将火把,红石粉等一些方块放置在它的上面
- */
- public boolean isOpaqueCube()
- {
- return false;
- }
- /**
- * 如果这个方块不是像一般的方块那样被渲染,它就会返回false(例如:牌子,按钮,阶梯等)
- */
- public boolean renderAsNormalBlock()
- {
- return false;
- }
- /**
- * 描绘(render)的方法
- */
- public int getRenderType()
- {
- return 10;
- }
- /**
- * 如果特殊方块石在给定的长方形范围(given AABB)内,则将CollidingBlock添加到列里
- */
- public void addCollidingBlockToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
- {
- int var8 = par1World.getBlockMetadata(par2, par3, par4);
- int var9 = var8 & 3;
- float var10 = 0.0F;
- float var11 = 0.5F;
- float var12 = 0.5F;
- float var13 = 1.0F;
- if ((var8 & 4) != 0)
- {
- var10 = 0.5F;
- var11 = 1.0F;
- var12 = 0.0F;
- var13 = 0.5F;
- }
- this.setBlockBounds(0.0F, var10, 0.0F, 1.0F, var11, 1.0F);
- super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
- if (var9 == 0)
- {
- this.setBlockBounds(0.5F, var12, 0.0F, 1.0F, var13, 1.0F);
- super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
- }
- else if (var9 == 1)
- {
- this.setBlockBounds(0.0F, var12, 0.0F, 0.5F, var13, 1.0F);
- super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
- }
- else if (var9 == 2)
- {
- this.setBlockBounds(0.0F, var12, 0.5F, 1.0F, var13, 1.0F);
- super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
- }
- else if (var9 == 3)
- {
- this.setBlockBounds(0.0F, var12, 0.0F, 1.0F, var13, 0.5F);
- super.addCollidingBlockToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
- }
- this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
- }
- /**
- * 当方块被放置出来时被调用
- */
- public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
- {
- int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- int var7 = par1World.getBlockMetadata(par2, par3, par4) & 4;
- if (var6 == 0)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 2 | var7);
- }
- if (var6 == 1)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 1 | var7);
- }
- if (var6 == 2)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 3 | var7);
- }
- if (var6 == 3)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 0 | var7);
- }
- }
- /**
- * 在onBlockPlacedBy 被调用前被调用
- */
- public void updateBlockMetadata(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8)
- {
- if (par5 == 0 || par5 != 1 && (double)par7 > 0.5D)
- {
- int var9 = par1World.getBlockMetadata(par2, par3, par4);
- par1World.setBlockMetadataWithNotify(par2, par3, par4, var9 | 4);
- }
- }
- /**
- * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world,
- * x, y, z, startVec, endVec
- */
- public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3)
- {
- MovingObjectPosition[] var7 = new MovingObjectPosition[8];
- int var8 = par1World.getBlockMetadata(par2, par3, par4);
- int var9 = var8 & 3;
- boolean var10 = (var8 & 4) == 4;
- int[] var11 = field_72159_a[var9 + (var10 ? 4 : 0)];
- this.field_72156_cr = true;
- int var14;
- int var15;
- int var16;
- for (int var12 = 0; var12 < 8; ++var12)
- {
- this.field_72160_cs = var12;
- int[] var13 = var11;
- var14 = var11.length;
- for (var15 = 0; var15 < var14; ++var15)
- {
- var16 = var13[var15];
- if (var16 == var12)
- {
- ;
- }
- }
- var7[var12] = super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3);
- }
- int[] var21 = var11;
- int var24 = var11.length;
- for (var14 = 0; var14 < var24; ++var14)
- {
- var15 = var21[var14];
- var7[var15] = null;
- }
- MovingObjectPosition var23 = null;
- double var22 = 0.0D;
- MovingObjectPosition[] var25 = var7;
- var16 = var7.length;
- for (int var17 = 0; var17 < var16; ++var17)
- {
- MovingObjectPosition var18 = var25[var17];
- if (var18 != null)
- {
- double var19 = var18.hitVec.squareDistanceTo(par6Vec3);
- if (var19 > var22)
- {
- var23 = var18;
- var22 = var19;
- }
- }
- }
- return var23;
- }
- }
复制代码
代码解析
mod_Stairs
与一般的方块类没什么区别
BlockNamehereStairs
addCollidingBlockToList 将方块的collision box添加到列中。通过“else if”这个命令行来修正方块的朝向。
在 onBlockPlacedBy中的if命令行被用来使方块的朝向为正对着玩家.
|