Exemplo n.º 1
0
  @Override
  public EnumActionResult onItemUse(
      ItemStack itemstack,
      EntityPlayer entityplayer,
      World world,
      BlockPos pos,
      EnumHand hand,
      EnumFacing side,
      float posX,
      float posY,
      float posZ) {
    TileEntity tileEntity = world.getTileEntity(pos);

    if (tileEntity instanceof TileEntityChargepad) {
      TileEntityChargepad chargepad = (TileEntityChargepad) tileEntity;

      if (!chargepad.isActive) {
        if (!world.isRemote) {
          EntityRobit robit =
              new EntityRobit(world, pos.getX() + 0.5, pos.getY() + 0.1, pos.getZ() + 0.5);

          robit.setHome(Coord4D.get(chargepad));
          robit.setEnergy(getEnergy(itemstack));
          robit.setOwner(entityplayer.getName());
          robit.setInventory(getInventory(itemstack));
          robit.setCustomNameTag(getName(itemstack));

          world.spawnEntityInWorld(robit);
        }

        entityplayer.setHeldItem(hand, null);

        return EnumActionResult.SUCCESS;
      }
    }

    return EnumActionResult.PASS;
  }