Exemplo n.º 1
0
 @Override
 public void onBlockPlacedBy(
     World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
   super.onBlockPlacedBy(world, x, y, z, player, stack);
   int heading = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
   TileEnchanter te = (TileEnchanter) world.getTileEntity(x, y, z);
   switch (heading) {
     case 0:
       te.setFacing((short) 2);
       break;
     case 1:
       te.setFacing((short) 5);
       break;
     case 2:
       te.setFacing((short) 3);
       break;
     case 3:
       te.setFacing((short) 4);
       break;
     default:
       break;
   }
   if (world.isRemote) {
     return;
   }
   world.markBlockForUpdate(x, y, z);
 }
Exemplo n.º 2
0
  @Override
  public boolean removedByPlayer(
      World world, EntityPlayer player, int x, int y, int z, boolean harvested) {
    if (!world.isRemote) {
      TileEntity te = world.getTileEntity(x, y, z);
      if (te instanceof TileEnchanter) {
        TileEnchanter enchanter = (TileEnchanter) te;
        if (!player.capabilities.isCreativeMode) {
          ItemStack itemStack = new ItemStack(this);
          float f = 0.7F;
          double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
          double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
          double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
          EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
          entityitem.delayBeforeCanPickup = 10;
          world.spawnEntityInWorld(entityitem);

          if (enchanter.getStackInSlot(0) != null) {
            Util.dropItems(world, enchanter.getStackInSlot(0), x, y, z, true);
          }
          if (enchanter.getStackInSlot(1) != null) {
            Util.dropItems(world, enchanter.getStackInSlot(1), x, y, z, true);
          }
        }
      }
    }
    return super.removedByPlayer(world, player, x, y, z, harvested);
  }