コード例 #1
0
  // ブロックのドロップ時に中身を落とす
  @Override
  public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
    TileIncenseBase tile = (TileIncenseBase) world.getTileEntity(x, y, z);
    if (tile != null) {
      ItemStack drop = tile.getItemstack();
      ItemStack ash = tile.getAsh();
      if (drop != null) {
        float f = world.rand.nextFloat() * 0.8F + 0.1F;
        float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
        float f2 = world.rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityitem =
            new EntityItem(
                world,
                (double) ((float) x + f),
                (double) ((float) y + f1),
                (double) ((float) z + f2),
                drop.copy());

        if (drop.hasTagCompound()) {
          entityitem.getEntityItem().setTagCompound((NBTTagCompound) drop.getTagCompound().copy());
        }

        float f3 = 0.05F;
        entityitem.motionX = (double) ((float) world.rand.nextGaussian() * f3);
        entityitem.motionY = (double) ((float) world.rand.nextGaussian() * f3 + 0.2F);
        entityitem.motionZ = (double) ((float) world.rand.nextGaussian() * f3);
        world.spawnEntityInWorld(entityitem);
      }
      if (ash != null) {
        float f = world.rand.nextFloat() * 0.8F + 0.1F;
        float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
        float f2 = world.rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityitem2 =
            new EntityItem(
                world,
                (double) ((float) x + f),
                (double) ((float) y + f1),
                (double) ((float) z + f2),
                ash.copy());

        if (ash.hasTagCompound()) {
          entityitem2.getEntityItem().setTagCompound((NBTTagCompound) ash.getTagCompound().copy());
        }

        float f3 = 0.05F;
        entityitem2.motionX = (double) ((float) world.rand.nextGaussian() * f3);
        entityitem2.motionY = (double) ((float) world.rand.nextGaussian() * f3 + 0.2F);
        entityitem2.motionZ = (double) ((float) world.rand.nextGaussian() * f3);
        world.spawnEntityInWorld(entityitem2);
      }
    }

    super.breakBlock(world, x, y, z, block, meta);
  }